llvmPackages_11: darwin cross compilation and bootstrapping

+33 -14
+11 -6
pkgs/development/compilers/llvm/11/compiler-rt/default.nix
··· 3 3 let 4 4 5 5 useLLVM = stdenv.hostPlatform.useLLVM or false; 6 + isDarwin = stdenv.hostPlatform.isDarwin; 6 7 bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; 7 8 haveLibc = stdenv.cc.libc != null; 8 9 inherit (stdenv.hostPlatform) isMusl; ··· 15 16 src = fetch "compiler-rt" "0x1j8ngf1zj63wlnns9vlibafq48qcm72p4jpaxkmkb4qw0grwfy"; 16 17 17 18 nativeBuildInputs = [ cmake python3 llvm.dev ]; 18 - buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; 19 19 20 20 NIX_CFLAGS_COMPILE = [ 21 21 "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" ··· 25 25 "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" 26 26 "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" 27 27 "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" 28 - ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ 28 + ] ++ lib.optionals (useLLVM || isDarwin || bareMetal || isMusl) [ 29 29 "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" 30 30 "-DCOMPILER_RT_BUILD_XRAY=OFF" 31 31 "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" 32 32 "-DCOMPILER_RT_BUILD_PROFILE=OFF" 33 - ] ++ lib.optionals ((useLLVM || bareMetal) && !haveLibc) [ 33 + ] ++ lib.optionals ((useLLVM || isDarwin || bareMetal) && !haveLibc) [ 34 34 "-DCMAKE_C_COMPILER_WORKS=ON" 35 35 "-DCMAKE_CXX_COMPILER_WORKS=ON" 36 36 "-DCOMPILER_RT_BAREMETAL_BUILD=ON" 37 37 "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" 38 - ] ++ lib.optionals (useLLVM && !haveLibc) [ 38 + ] ++ lib.optionals ((useLLVM || isDarwin) && !haveLibc) [ 39 39 "-DCMAKE_C_FLAGS=-nodefaultlibs" 40 - ] ++ lib.optionals (useLLVM) [ 40 + ] ++ lib.optionals (useLLVM || isDarwin) [ 41 41 "-DCOMPILER_RT_BUILD_BUILTINS=ON" 42 42 #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program 43 43 "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ··· 61 61 ]# ++ lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch 62 62 ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; 63 63 64 + 65 + preConfigure = lib.optionalString isDarwin '' 66 + cmakeFlagsArray+=("-DCMAKE_LIPO=$(command -v ${stdenv.cc.targetPrefix}lipo)") 67 + ''; 68 + 64 69 # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks 65 70 # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra 66 71 # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd ··· 71 76 --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' 72 77 '' + lib.optionalString stdenv.isDarwin '' 73 78 substituteInPlace cmake/builtin-config-ix.cmake \ 74 - --replace 'set(ARM64 arm64 arm64e)' 'set(ARM64)' 79 + --replace 'foreach(arch ''${ARM64})' 'foreach(arch)' 75 80 substituteInPlace cmake/config-ix.cmake \ 76 81 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 77 82 '' + lib.optionalString (useLLVM) ''
+6 -6
pkgs/development/compilers/llvm/11/default.nix
··· 213 213 214 214 compiler-rt-libc = callPackage ./compiler-rt { 215 215 inherit llvm_meta; 216 - stdenv = if stdenv.hostPlatform.useLLVM or false 216 + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin 217 217 then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc 218 218 else stdenv; 219 219 }; 220 220 221 221 compiler-rt-no-libc = callPackage ./compiler-rt { 222 222 inherit llvm_meta; 223 - stdenv = if stdenv.hostPlatform.useLLVM or false 223 + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin 224 224 then overrideCC stdenv buildLlvmTools.clangNoCompilerRt 225 225 else stdenv; 226 226 }; 227 227 228 228 # N.B. condition is safe because without useLLVM both are the same. 229 - compiler-rt = if stdenv.hostPlatform.isAndroid 229 + compiler-rt = if stdenv.hostPlatform.isAndroid || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) 230 230 then libraries.compiler-rt-libc 231 231 else libraries.compiler-rt-no-libc; 232 232 ··· 236 236 237 237 libcxx = callPackage ./libcxx { 238 238 inherit llvm_meta; 239 - stdenv = if stdenv.hostPlatform.useLLVM or false 239 + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin 240 240 then overrideCC stdenv buildLlvmTools.clangNoLibcxx 241 241 else stdenv; 242 242 }; 243 243 244 244 libcxxabi = callPackage ./libcxxabi { 245 245 inherit llvm_meta; 246 - stdenv = if stdenv.hostPlatform.useLLVM or false 246 + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin 247 247 then overrideCC stdenv buildLlvmTools.clangNoLibcxx 248 248 else stdenv; 249 249 }; 250 250 251 251 libunwind = callPackage ./libunwind { 252 252 inherit llvm_meta; 253 - stdenv = if stdenv.hostPlatform.useLLVM or false 253 + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin 254 254 then overrideCC stdenv buildLlvmTools.clangNoLibcxx 255 255 else stdenv; 256 256 };
+14 -1
pkgs/development/compilers/llvm/11/libcxx/default.nix
··· 46 46 "-DLIBCXX_ENABLE_THREADS=OFF" 47 47 "-DLIBCXX_ENABLE_FILESYSTEM=OFF" 48 48 "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" 49 - ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; 49 + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" 50 + 51 + # TODO: this is a bit of a hack to cross compile to Apple Silicon. libcxx 52 + # starting with 11 enables CMAKE_BUILD_WITH_INSTALL_NAME_DIR which requires 53 + # platform setup for rpaths. In cmake, this is enabled when macos is newer 54 + # than 10.5. However CMAKE_SYSTEM_VERSION is set to empty (TODO: why?) 55 + # which prevents the conditional configuration, and configure fails. The 56 + # value here corresponds to `uname -r`. If stdenv.hostPlatform.release is 57 + # not null, then this property will be set via mkDerivation (TODO: how can 58 + # we set this?). 59 + ++ lib.optional ( 60 + stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64 && 61 + stdenv.hostPlatform != stdenv.buildPlatform 62 + ) "-DCMAKE_SYSTEM_VERSION=20.1.0"; 50 63 51 64 passthru = { 52 65 isLLVM = true;
+1 -1
pkgs/development/compilers/llvm/11/libcxxabi/default.nix
··· 48 48 # the magic combination of necessary CMake variables 49 49 # if you fancy a try, take a look at 50 50 # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling 51 - install_name_tool -id $out/$file $file 51 + ${stdenv.cc.targetPrefix}install_name_tool -id $out/$file $file 52 52 done 53 53 make install 54 54 install -d 755 $out/include
+1
pkgs/top-level/all-packages.nix
··· 14848 14848 inherit (stdenv.targetPlatform) libc; 14849 14849 in if libc == "msvcrt" then targetPackages.windows.mingw_w64_headers or windows.mingw_w64_headers 14850 14850 else if libc == "nblibc" then targetPackages.netbsdCross.headers or netbsdCross.headers 14851 + else if libc == "libSystem" && stdenv.targetPlatform.isAarch64 then targetPackages.darwin.LibsystemCross or darwin.LibsystemCross 14851 14852 else null; 14852 14853 14853 14854 # We can choose: