mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 15:33:13 +00:00
llvmPackages_11: darwin cross compilation and bootstrapping
This commit is contained in:
parent
c31591cf8b
commit
56fcbcd154
@ -3,6 +3,7 @@
|
||||
let
|
||||
|
||||
useLLVM = stdenv.hostPlatform.useLLVM or false;
|
||||
isDarwin = stdenv.hostPlatform.isDarwin;
|
||||
bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none";
|
||||
haveLibc = stdenv.cc.libc != null;
|
||||
inherit (stdenv.hostPlatform) isMusl;
|
||||
@ -15,7 +16,6 @@ stdenv.mkDerivation {
|
||||
src = fetch "compiler-rt" "0x1j8ngf1zj63wlnns9vlibafq48qcm72p4jpaxkmkb4qw0grwfy";
|
||||
|
||||
nativeBuildInputs = [ cmake python3 llvm.dev ];
|
||||
buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
|
||||
|
||||
NIX_CFLAGS_COMPILE = [
|
||||
"-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0"
|
||||
@ -25,19 +25,19 @@ stdenv.mkDerivation {
|
||||
"-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
|
||||
"-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}"
|
||||
"-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}"
|
||||
] ++ lib.optionals (useLLVM || bareMetal || isMusl) [
|
||||
] ++ lib.optionals (useLLVM || isDarwin || bareMetal || isMusl) [
|
||||
"-DCOMPILER_RT_BUILD_SANITIZERS=OFF"
|
||||
"-DCOMPILER_RT_BUILD_XRAY=OFF"
|
||||
"-DCOMPILER_RT_BUILD_LIBFUZZER=OFF"
|
||||
"-DCOMPILER_RT_BUILD_PROFILE=OFF"
|
||||
] ++ lib.optionals ((useLLVM || bareMetal) && !haveLibc) [
|
||||
] ++ lib.optionals ((useLLVM || isDarwin || bareMetal) && !haveLibc) [
|
||||
"-DCMAKE_C_COMPILER_WORKS=ON"
|
||||
"-DCMAKE_CXX_COMPILER_WORKS=ON"
|
||||
"-DCOMPILER_RT_BAREMETAL_BUILD=ON"
|
||||
"-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}"
|
||||
] ++ lib.optionals (useLLVM && !haveLibc) [
|
||||
] ++ lib.optionals ((useLLVM || isDarwin) && !haveLibc) [
|
||||
"-DCMAKE_C_FLAGS=-nodefaultlibs"
|
||||
] ++ lib.optionals (useLLVM) [
|
||||
] ++ lib.optionals (useLLVM || isDarwin) [
|
||||
"-DCOMPILER_RT_BUILD_BUILTINS=ON"
|
||||
#https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program
|
||||
"-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
|
||||
@ -61,6 +61,11 @@ stdenv.mkDerivation {
|
||||
]# ++ lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch
|
||||
++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch;
|
||||
|
||||
|
||||
preConfigure = lib.optionalString isDarwin ''
|
||||
cmakeFlagsArray+=("-DCMAKE_LIPO=$(command -v ${stdenv.cc.targetPrefix}lipo)")
|
||||
'';
|
||||
|
||||
# TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
|
||||
# to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
|
||||
# can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
|
||||
@ -71,7 +76,7 @@ stdenv.mkDerivation {
|
||||
--replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)'
|
||||
'' + lib.optionalString stdenv.isDarwin ''
|
||||
substituteInPlace cmake/builtin-config-ix.cmake \
|
||||
--replace 'set(ARM64 arm64 arm64e)' 'set(ARM64)'
|
||||
--replace 'foreach(arch ''${ARM64})' 'foreach(arch)'
|
||||
substituteInPlace cmake/config-ix.cmake \
|
||||
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
|
||||
'' + lib.optionalString (useLLVM) ''
|
||||
|
@ -213,20 +213,20 @@ let
|
||||
|
||||
compiler-rt-libc = callPackage ./compiler-rt {
|
||||
inherit llvm_meta;
|
||||
stdenv = if stdenv.hostPlatform.useLLVM or false
|
||||
stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin
|
||||
then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc
|
||||
else stdenv;
|
||||
};
|
||||
|
||||
compiler-rt-no-libc = callPackage ./compiler-rt {
|
||||
inherit llvm_meta;
|
||||
stdenv = if stdenv.hostPlatform.useLLVM or false
|
||||
stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin
|
||||
then overrideCC stdenv buildLlvmTools.clangNoCompilerRt
|
||||
else stdenv;
|
||||
};
|
||||
|
||||
# N.B. condition is safe because without useLLVM both are the same.
|
||||
compiler-rt = if stdenv.hostPlatform.isAndroid
|
||||
compiler-rt = if stdenv.hostPlatform.isAndroid || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)
|
||||
then libraries.compiler-rt-libc
|
||||
else libraries.compiler-rt-no-libc;
|
||||
|
||||
@ -236,21 +236,21 @@ let
|
||||
|
||||
libcxx = callPackage ./libcxx {
|
||||
inherit llvm_meta;
|
||||
stdenv = if stdenv.hostPlatform.useLLVM or false
|
||||
stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin
|
||||
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
|
||||
else stdenv;
|
||||
};
|
||||
|
||||
libcxxabi = callPackage ./libcxxabi {
|
||||
inherit llvm_meta;
|
||||
stdenv = if stdenv.hostPlatform.useLLVM or false
|
||||
stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin
|
||||
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
|
||||
else stdenv;
|
||||
};
|
||||
|
||||
libunwind = callPackage ./libunwind {
|
||||
inherit llvm_meta;
|
||||
stdenv = if stdenv.hostPlatform.useLLVM or false
|
||||
stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin
|
||||
then overrideCC stdenv buildLlvmTools.clangNoLibcxx
|
||||
else stdenv;
|
||||
};
|
||||
|
@ -46,7 +46,20 @@ stdenv.mkDerivation {
|
||||
"-DLIBCXX_ENABLE_THREADS=OFF"
|
||||
"-DLIBCXX_ENABLE_FILESYSTEM=OFF"
|
||||
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
|
||||
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
|
||||
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"
|
||||
|
||||
# TODO: this is a bit of a hack to cross compile to Apple Silicon. libcxx
|
||||
# starting with 11 enables CMAKE_BUILD_WITH_INSTALL_NAME_DIR which requires
|
||||
# platform setup for rpaths. In cmake, this is enabled when macos is newer
|
||||
# than 10.5. However CMAKE_SYSTEM_VERSION is set to empty (TODO: why?)
|
||||
# which prevents the conditional configuration, and configure fails. The
|
||||
# value here corresponds to `uname -r`. If stdenv.hostPlatform.release is
|
||||
# not null, then this property will be set via mkDerivation (TODO: how can
|
||||
# we set this?).
|
||||
++ lib.optional (
|
||||
stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64 &&
|
||||
stdenv.hostPlatform != stdenv.buildPlatform
|
||||
) "-DCMAKE_SYSTEM_VERSION=20.1.0";
|
||||
|
||||
passthru = {
|
||||
isLLVM = true;
|
||||
|
@ -48,7 +48,7 @@ stdenv.mkDerivation {
|
||||
# the magic combination of necessary CMake variables
|
||||
# if you fancy a try, take a look at
|
||||
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
|
||||
install_name_tool -id $out/$file $file
|
||||
${stdenv.cc.targetPrefix}install_name_tool -id $out/$file $file
|
||||
done
|
||||
make install
|
||||
install -d 755 $out/include
|
||||
|
@ -14848,6 +14848,7 @@ in
|
||||
inherit (stdenv.targetPlatform) libc;
|
||||
in if libc == "msvcrt" then targetPackages.windows.mingw_w64_headers or windows.mingw_w64_headers
|
||||
else if libc == "nblibc" then targetPackages.netbsdCross.headers or netbsdCross.headers
|
||||
else if libc == "libSystem" && stdenv.targetPlatform.isAarch64 then targetPackages.darwin.LibsystemCross or darwin.LibsystemCross
|
||||
else null;
|
||||
|
||||
# We can choose:
|
||||
|
Loading…
Reference in New Issue
Block a user