From 761aa9bf9f0ff6e9600e0178ecfe6740428f71b9 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 3 Aug 2023 22:44:09 -0400 Subject: [PATCH] llvmPackages_16.compiler-rt: fix static build on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes two issues on Darwin to allow pkgsStatic to work with LLVM 16 * It fixes an infinite recursion where Darwin was using a regular stdenv to build compiler-rt instead of one without compiler-rt; and * It disables sanitizers that won’t build statically and makes sure the build can find the cross-lipo. --- pkgs/development/compilers/llvm/16/compiler-rt/default.nix | 7 +++++-- pkgs/development/compilers/llvm/16/default.nix | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/llvm/16/compiler-rt/default.nix b/pkgs/development/compilers/llvm/16/compiler-rt/default.nix index e2b8d470f890..aa248c0e60eb 100644 --- a/pkgs/development/compilers/llvm/16/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/16/compiler-rt/default.nix @@ -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}" diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix index 1e200b17b0b2..0c0ff44e155f 100644 --- a/pkgs/development/compilers/llvm/16/default.nix +++ b/pkgs/development/compilers/llvm/16/default.nix @@ -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;