Merge pull request #247066 from reckenrode/compiler-rt-static

llvmPackages_16.compiler-rt: fix static build on Darwin
This commit is contained in:
Theodore Ni 2023-08-21 19:36:50 -07:00 committed by GitHub
commit 174e4f41b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -9,6 +9,7 @@ let
useLLVM = stdenv.hostPlatform.useLLVM or false;
bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none";
haveLibc = stdenv.cc.libc != null;
isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic;
inherit (stdenv.hostPlatform) isMusl isGnu;
baseName = "compiler-rt";
@ -41,7 +42,7 @@ stdenv.mkDerivation {
"-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}"
] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [
"-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include"
] ++ lib.optionals (useLLVM || bareMetal || isMusl) [
] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [
"-DCOMPILER_RT_BUILD_SANITIZERS=OFF"
"-DCOMPILER_RT_BUILD_XRAY=OFF"
"-DCOMPILER_RT_BUILD_LIBFUZZER=OFF"
@ -49,9 +50,10 @@ stdenv.mkDerivation {
"-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary
] ++ lib.optionals (useLLVM || bareMetal) [
"-DCOMPILER_RT_BUILD_PROFILE=OFF"
] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [
"-DCMAKE_CXX_COMPILER_WORKS=ON"
] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [
"-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) [
@ -63,6 +65,7 @@ stdenv.mkDerivation {
] ++ lib.optionals (bareMetal) [
"-DCOMPILER_RT_OS_DIR=baremetal"
] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
"-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo"
"-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON"
"-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}"
"-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}"

View file

@ -316,7 +316,7 @@ in 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 && stdenv.hostPlatform.isStatic)
then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc
else stdenv;
};
@ -329,7 +329,7 @@ in let
};
# 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
then libraries.compiler-rt-libc
else libraries.compiler-rt-no-libc;