The CoreFoundation.tbd setup hook in darwin's CoreFoundation does not take build/host offsets into account, so it unconditionally applies CFLAGS/LDFLAGS which are invalid for non-darwin hosts. This can occur when a package pulls in CoreFoundation via a buildPackage's propagatedBuildInputs. Since CF is propagated by a number of packages, this occurs quite often.
This seems to have technically been an issue for as long as this setup hook has existed, but has only started causing problems now that we are explicitly linking the .tbd file. Previously it was an extraneous directory that could be ignored, but now the explicit .tbd file is seen as an invalid linker script by the target cross linker.
For example, see: nixpkgs:cross-trunk:rpi-musl.nix.x86_64-darwin (https://hydra.nixos.org/build/241448869/nixlog/1):
CMake Error at /nix/store/nsk9a663g0khs9li1hwwqlsxsvqd0x9d-cmake-3.27.7/share/cmake-3.27/Modules/CMakeTestCXXCompiler.cmake:60 (message):
The C++ compiler
"/nix/store/7hl3605laf3qi72bgzkxkvpg4ziqzlch-armv6l-unknown-linux-musleabihf-gcc-wrapper-12.3.0/bin/armv6l-unknown-linux-musleabihf-g++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: '/tmp/nix-build-aws-sdk-cpp-armv6l-unknown-linux-musleabihf-1.11.118.drv-0/source/build/CMakeFiles/CMakeScratch/TryCompile-cfogov'
Run Build Command(s): /nix/store/nsk9a663g0khs9li1hwwqlsxsvqd0x9d-cmake-3.27.7/bin/cmake -E env VERBOSE=1 /nix/store/x5dy4sqg1nxsl7nwibanfrbx95wdb228-gnumake-4.4.1/bin/make -f Makefile cmTC_fd3de/fast
/nix/store/x5dy4sqg1nxsl7nwibanfrbx95wdb228-gnumake-4.4.1/bin/make -f CMakeFiles/cmTC_fd3de.dir/build.make CMakeFiles/cmTC_fd3de.dir/build
make[1]: Entering directory '/private/tmp/nix-build-aws-sdk-cpp-armv6l-unknown-linux-musleabihf-1.11.118.drv-0/source/build/CMakeFiles/CMakeScratch/TryCompile-cfogov'
Building CXX object CMakeFiles/cmTC_fd3de.dir/testCXXCompiler.cxx.o
/nix/store/7hl3605laf3qi72bgzkxkvpg4ziqzlch-armv6l-unknown-linux-musleabihf-gcc-wrapper-12.3.0/bin/armv6l-unknown-linux-musleabihf-g++ -o CMakeFiles/cmTC_fd3de.dir/testCXXCompiler.cxx.o -c /tmp/nix-build-aws-sdk-cpp-armv6l-unknown-linux-musleabihf-1.11.118.drv-0/source/build/CMakeFiles/CMakeScratch/TryCompile-cfogov/testCXXCompiler.cxx
Linking CXX executable cmTC_fd3de
/nix/store/nsk9a663g0khs9li1hwwqlsxsvqd0x9d-cmake-3.27.7/bin/cmake -E cmake_link_script CMakeFiles/cmTC_fd3de.dir/link.txt --verbose=1
/nix/store/7hl3605laf3qi72bgzkxkvpg4ziqzlch-armv6l-unknown-linux-musleabihf-gcc-wrapper-12.3.0/bin/armv6l-unknown-linux-musleabihf-g++ CMakeFiles/cmTC_fd3de.dir/testCXXCompiler.cxx.o -o cmTC_fd3de
/nix/store/25607ap8xf8n6q29zbz9ikr6dl9mkrs6-armv6l-unknown-linux-musleabihf-binutils-2.40/bin/armv6l-unknown-linux-musleabihf-ld:/nix/store/xk64xciny5qx5g6wjbq7839zxqb53kjq-apple-framework-CoreFoundation/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd: file format not recognized; treating as linker script
/nix/store/25607ap8xf8n6q29zbz9ikr6dl9mkrs6-armv6l-unknown-linux-musleabihf-binutils-2.40/bin/armv6l-unknown-linux-musleabihf-ld:/nix/store/xk64xciny5qx5g6wjbq7839zxqb53kjq-apple-framework-CoreFoundation/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd:1: syntax error
collect2: error: ld returned 1 exit status
(This can be reproduced locally on x86_64-darwin via nix-build -A pkgsCross.muslpi.aws-sdk-cpp)
I suspect this may be fixed by using role_post correctly as in other libraries' setup hooks, e.g.:
|
getHostRole |
|
export NIX_LDFLAGS${role_post}+=" -liconv" |
However, making this change to CF's setup hook would be a a stdenv rebuild on darwin, and I don't have time at the moment to rebuild the world to test this out.
The CoreFoundation.tbd setup hook in darwin's CoreFoundation does not take build/host offsets into account, so it unconditionally applies CFLAGS/LDFLAGS which are invalid for non-darwin hosts. This can occur when a package pulls in CoreFoundation via a buildPackage's propagatedBuildInputs. Since CF is propagated by a number of packages, this occurs quite often.
This seems to have technically been an issue for as long as this setup hook has existed, but has only started causing problems now that we are explicitly linking the .tbd file. Previously it was an extraneous directory that could be ignored, but now the explicit .tbd file is seen as an invalid linker script by the target cross linker.
For example, see: nixpkgs:cross-trunk:rpi-musl.nix.x86_64-darwin (https://hydra.nixos.org/build/241448869/nixlog/1):
(This can be reproduced locally on x86_64-darwin via
nix-build -A pkgsCross.muslpi.aws-sdk-cpp)I suspect this may be fixed by using
role_postcorrectly as in other libraries' setup hooks, e.g.:nixpkgs/pkgs/development/libraries/libiconv/setup-hook.sh
Lines 6 to 7 in a6c7882
However, making this change to CF's setup hook would be a a stdenv rebuild on darwin, and I don't have time at the moment to rebuild the world to test this out.