Skip to content

Commit

Permalink
compiler-rt: build builtins on darwin
Browse files Browse the repository at this point in the history
The missing xcrun meant builtins were missing from darwin. This
apparently wasn't an issue until now, but is in projects using
`@available` checks. (The ARM64 hack was apparently the previous
solution to fixing broken SDK detection.)
  • Loading branch information
stephank committed Aug 24, 2022
1 parent 8c469b0 commit fb91bfc
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 32 deletions.
12 changes: 6 additions & 6 deletions pkgs/development/compilers/llvm/11/compiler-rt/default.nix
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
Expand Down Expand Up @@ -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)")
Expand All @@ -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) ''
Expand Down
11 changes: 6 additions & 5 deletions pkgs/development/compilers/llvm/12/compiler-rt/default.nix
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 = [
Expand Down Expand Up @@ -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
Expand All @@ -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) ''
Expand Down
15 changes: 8 additions & 7 deletions pkgs/development/compilers/llvm/13/compiler-rt/default.nix
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 = [
Expand Down Expand Up @@ -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
Expand All @@ -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) ''
Expand Down
15 changes: 8 additions & 7 deletions pkgs/development/compilers/llvm/14/compiler-rt/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, stdenv, llvm_meta, version
, monorepoSrc, runCommand
, cmake, python3, libllvm, libcxxabi
, cmake, python3, xcbuild, libllvm, libcxxabi
}:

let
Expand All @@ -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 = [
Expand Down Expand Up @@ -72,9 +73,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
Expand All @@ -85,8 +88,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) ''
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 8 additions & 7 deletions pkgs/development/compilers/llvm/git/compiler-rt/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, stdenv, llvm_meta, version
, monorepoSrc, runCommand
, cmake, python3, libllvm, libcxxabi
, cmake, python3, xcbuild, libllvm, libcxxabi
}:

let
Expand All @@ -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 = [
Expand Down Expand Up @@ -72,9 +73,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
Expand All @@ -85,8 +88,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) ''
Expand Down

0 comments on commit fb91bfc

Please sign in to comment.