Merge pull request #186575 from stephank/fix/compiler-rt-builtins

compiler-rt: build builtins on darwin
This commit is contained in:
7c6f434c
2022-10-05 18:48:36 +00:00
committed by GitHub
6 changed files with 61 additions and 32 deletions
@@ -1,4 +1,4 @@
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi }:
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, xcbuild, libllvm, libcxxabi }:
let
@@ -15,7 +15,8 @@ stdenv.mkDerivation {
inherit version;
src = fetch "compiler-rt" "0x1j8ngf1zj63wlnns9vlibafq48qcm72p4jpaxkmkb4qw0grwfy";
nativeBuildInputs = [ cmake python3 libllvm.dev ];
nativeBuildInputs = [ cmake python3 libllvm.dev ]
++ lib.optional stdenv.isDarwin xcbuild.xcrun;
NIX_CFLAGS_COMPILE = [
"-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0"
@@ -59,8 +60,9 @@ stdenv.mkDerivation {
# extra `/`.
./normalize-var.patch
../../common/compiler-rt/libsanitizer-no-cyclades-11.patch
] ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch;
../../common/compiler-rt/darwin-plistbuddy-workaround.patch
./armv7l.patch
];
preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
cmakeFlagsArray+=("-DCMAKE_LIPO=$(command -v ${stdenv.cc.targetPrefix}lipo)")
@@ -75,8 +77,6 @@ stdenv.mkDerivation {
substituteInPlace cmake/builtin-config-ix.cmake \
--replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)'
'' + lib.optionalString stdenv.isDarwin ''
substituteInPlace cmake/builtin-config-ix.cmake \
--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) ''
@@ -1,4 +1,4 @@
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi }:
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, xcbuild, libllvm, libcxxabi }:
let
@@ -14,7 +14,8 @@ stdenv.mkDerivation {
inherit version;
src = fetch "compiler-rt" "1950rg294izdwkaasi7yjrmadc9mzdd5paf0q63jjcq2m3rdbj5l";
nativeBuildInputs = [ cmake python3 libllvm.dev ];
nativeBuildInputs = [ cmake python3 libllvm.dev ]
++ lib.optional stdenv.isDarwin xcbuild.xcrun;
buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
NIX_CFLAGS_COMPILE = [
@@ -59,7 +60,9 @@ stdenv.mkDerivation {
# ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
# extra `/`.
./normalize-var.patch
] ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch;
../../common/compiler-rt/darwin-plistbuddy-workaround.patch
./armv7l.patch
];
# 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
@@ -70,8 +73,6 @@ stdenv.mkDerivation {
substituteInPlace cmake/builtin-config-ix.cmake \
--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)'
substituteInPlace cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
'' + lib.optionalString (useLLVM) ''
@@ -1,4 +1,4 @@
{ lib, stdenv, llvm_meta, version, src, cmake, python3, libllvm, libcxxabi }:
{ lib, stdenv, llvm_meta, version, src, cmake, python3, xcbuild, libllvm, libcxxabi }:
let
@@ -16,7 +16,8 @@ stdenv.mkDerivation {
inherit src;
sourceRoot = "source/compiler-rt";
nativeBuildInputs = [ cmake python3 libllvm.dev ];
nativeBuildInputs = [ cmake python3 libllvm.dev ]
++ lib.optional stdenv.isDarwin xcbuild.xcrun;
buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
NIX_CFLAGS_COMPILE = [
@@ -62,9 +63,11 @@ stdenv.mkDerivation {
# ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
# extra `/`.
./normalize-var.patch
] # Prevent a compilation error on darwin
++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch
++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch;
# Prevent a compilation error on darwin
./darwin-targetconditionals.patch
../../common/compiler-rt/darwin-plistbuddy-workaround.patch
./armv7l.patch
];
# 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
@@ -75,8 +78,6 @@ stdenv.mkDerivation {
substituteInPlace cmake/builtin-config-ix.cmake \
--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)'
substituteInPlace cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
'' + lib.optionalString (useLLVM) ''
@@ -1,6 +1,6 @@
{ lib, stdenv, llvm_meta, version
, monorepoSrc, runCommand
, cmake, python3, libllvm, libcxxabi
, cmake, python3, xcbuild, libllvm, libcxxabi
}:
let
@@ -26,7 +26,8 @@ stdenv.mkDerivation {
inherit src;
sourceRoot = "${src.name}/${baseName}";
nativeBuildInputs = [ cmake python3 libllvm.dev ];
nativeBuildInputs = [ cmake python3 libllvm.dev ]
++ lib.optional stdenv.isDarwin xcbuild.xcrun;
buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
NIX_CFLAGS_COMPILE = [
@@ -73,9 +74,11 @@ stdenv.mkDerivation {
# ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
# extra `/`.
./normalize-var.patch
] # Prevent a compilation error on darwin
++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch
++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch;
# Prevent a compilation error on darwin
./darwin-targetconditionals.patch
../../common/compiler-rt/darwin-plistbuddy-workaround.patch
./armv7l.patch
];
# 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
@@ -86,8 +89,6 @@ stdenv.mkDerivation {
substituteInPlace cmake/builtin-config-ix.cmake \
--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)'
substituteInPlace cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
'' + lib.optionalString (useLLVM) ''
@@ -0,0 +1,25 @@
CMake tries to read a list field from SDKSettings.plist, but the output of
xcbuild PlistBuddy is incompatible with Apple's. (Plus we don't want it in our
dependencies.)
Simply assume ARM64 is supported by the SDK. We already limit the actual archs
we build for by setting DARWIN_osx_BUILTIN_ARCHS explicitely.
--- a/cmake/builtin-config-ix.cmake
+++ b/cmake/builtin-config-ix.cmake
@@ -97,14 +97,7 @@ if(APPLE)
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
- set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
- # Add support for arm64 macOS if available in SDK.
- foreach(arch ${ARM64})
- sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
- if (MACOS_ARM_SUPPORT)
- list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
- endif()
- endforeach(arch)
+ set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64} ${ARM64})
if(COMPILER_RT_ENABLE_IOS)
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
@@ -1,6 +1,6 @@
{ lib, stdenv, llvm_meta, version
, monorepoSrc, runCommand
, cmake, python3, libllvm, libcxxabi
, cmake, python3, xcbuild, libllvm, libcxxabi
}:
let
@@ -26,7 +26,8 @@ stdenv.mkDerivation {
inherit src;
sourceRoot = "${src.name}/${baseName}";
nativeBuildInputs = [ cmake python3 libllvm.dev ];
nativeBuildInputs = [ cmake python3 libllvm.dev ]
++ lib.optional stdenv.isDarwin xcbuild.xcrun;
buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
NIX_CFLAGS_COMPILE = [
@@ -71,9 +72,11 @@ stdenv.mkDerivation {
# ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
# extra `/`.
./normalize-var.patch
] # Prevent a compilation error on darwin
++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch
++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch;
# Prevent a compilation error on darwin
./darwin-targetconditionals.patch
../../common/compiler-rt/darwin-plistbuddy-workaround.patch
./armv7l.patch
];
# 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
@@ -84,8 +87,6 @@ stdenv.mkDerivation {
substituteInPlace cmake/builtin-config-ix.cmake \
--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)'
substituteInPlace cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
'' + lib.optionalString (useLLVM) ''