Trying to get the iOS build of a C++ library working. Unfortunately, the toolchain seems to be having an issue.
I was able to solve a couple of issues myself with an overlay, the core of which is something like this. I’m manually extracting the non-project-specific things, so this may not 100% exactly build (may be missing semicolons) but this should be almost exactly what’s happening.
{ system ? builtins.currentSystem, iphone ? false }:
let
nixpkgsFun = import (builtins.fetchTarball {
# A 20.09 commit
url = "https://github.com/NixOS/nixpkgs/archive/f53c431645da8e6760268092aa10f736b5cfb117.tar.gz";
sha256 = "1n1ikc16ak8rylmn6bxq4dgxy0kniq4z36sm4i0cdf2hy5frwmqi";
});
overlay = self: super: {
binutils-unwrapped = super.binutils-unwrapped.override {
autoreconfHook = super.autoreconfHook269;
};
gccForLibs = null;
darwin = super.darwin // {
inherit (super.callPackage ./xcode.nix {}) xcode xcode_12_3;
};
};
in
nixpkgsFun {
config.allowUnfree = true;
overlays = [ overlay ];
crossSystem = if iphone then {
config = "aarch64-apple-ios";
sdkVer = "14.3";
xcodeVer = "12.3";
xcodePlatform = "iPhoneOS";
useiOSPrebuilt = true;
platform = {};
} else null;
inherit system;
}
Where xcode.nix is basically a newer version of this PR:
https://github.com/NixOS/nixpkgs/pull/100687
However, I get an error from ld:
CMake Error at /nix/store/8gscqqq8fpj75kmcjyf7abkq7wh0i1rd-cmake-3.19.2/share/cmake-3.19/Modules/CMakeTestCXXCompiler.cmake:59 (message):
The C++ compiler
"/nix/store/g9w4pl5s9snkz0c7q1xdlvy6c3v0mcp9-aarch64-apple-ios-clang-wrapper-7.1.0/bin/aarch64-apple-ios-clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /tmp/nix-build-cxxopts-2.2.1-aarch64-apple-ios.drv-0/source/build/CMakeFiles/CMakeTmp
Run Build Command(s):/nix/store/ya77axvrzs5ifqi4jjp38nz9xf53z6ri-gnumake-4.3/bin/make cmTC_9ec3f/fast && /nix/store/ya77axvrzs5ifqi4jjp38nz9xf53z6ri-gnumake-4.3/bin/make -f CMakeFiles/cmTC_9ec3f.dir/build.make CMakeFiles/cmTC_9ec3f.dir/build
make[1]: Entering directory '/private/tmp/nix-build-cxxopts-2.2.1-aarch64-apple-ios.drv-0/source/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_9ec3f.dir/testCXXCompiler.cxx.obj
/nix/store/g9w4pl5s9snkz0c7q1xdlvy6c3v0mcp9-aarch64-apple-ios-clang-wrapper-7.1.0/bin/aarch64-apple-ios-clang++ -o CMakeFiles/cmTC_9ec3f.dir/testCXXCompiler.cxx.obj -c /tmp/nix-build-cxxopts-2.2.1-aarch64-apple-ios.drv-0/source/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_9ec3f
/nix/store/8gscqqq8fpj75kmcjyf7abkq7wh0i1rd-cmake-3.19.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9ec3f.dir/link.txt --verbose=1
/nix/store/g9w4pl5s9snkz0c7q1xdlvy6c3v0mcp9-aarch64-apple-ios-clang-wrapper-7.1.0/bin/aarch64-apple-ios-clang++ CMakeFiles/cmTC_9ec3f.dir/testCXXCompiler.cxx.obj -o cmTC_9ec3f
ld: warning: directory not found for option '-L/nix/store/fjpd7z9fsj903743z7m2jqx6g9hylcbj-clang-7.1.0-lib/aarch64-apple-ios/lib'
ld: warning: passed two min versions (9.0.0, 9.0) for platform iOS. Using 9.0.
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/nix/store/fsp2b0w02ay2242p41d0pqg3xsmwms59-libSystem-prebuilt/lib/libc++.tbd' for architecture arm64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_9ec3f.dir/build.make:106: cmTC_9ec3f] Error 1
make[1]: Leaving directory '/private/tmp/nix-build-cxxopts-2.2.1-aarch64-apple-ios.drv-0/source/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:140: cmTC_9ec3f/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:33 (project)
-- Configuring incomplete, errors occurred!
See also "/tmp/nix-build-cxxopts-2.2.1-aarch64-apple-ios.drv-0/source/build/CMakeFiles/CMakeOutput.log".
See also "/tmp/nix-build-cxxopts-2.2.1-aarch64-apple-ios.drv-0/source/build/CMakeFiles/CMakeError.log".
builder for '/nix/store/m0a8c336q5w0vnq51132hf83x0djbd57-cxxopts-2.2.1-aarch64-apple-ios.drv' failed with exit code 1
I googled the error, and most of the results came from an older version of ld with a newer version of XCode.
It looks like it may come from somewhat deep in stdenv(?)'s bootstrapping process. I tried overriding the llvm version (llvm = super.llvm_8;
) but this didn’t fix it, and when I dug into darwin’s stdenv bootstrap process in default.nix, I saw it was directly referencing LLVM 7 in such a way that I didn’t think I could try to update it.
Anyway, if anyone has any ideas, I’d appreciate it.