compiler-rt: build builtins on darwin

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.)

Changed files
+61 -32
pkgs
development
compilers
llvm
11
compiler-rt
12
compiler-rt
13
compiler-rt
14
compiler-rt
common
git
compiler-rt
+6 -6
pkgs/development/compilers/llvm/11/compiler-rt/default.nix
···
-
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi }:
+
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, xcbuild, libllvm, libcxxabi }:
let
···
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"
···
# 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)")
···
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) ''
+6 -5
pkgs/development/compilers/llvm/12/compiler-rt/default.nix
···
-
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi }:
+
{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, xcbuild, libllvm, libcxxabi }:
let
···
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 = [
···
# 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
···
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) ''
+8 -7
pkgs/development/compilers/llvm/13/compiler-rt/default.nix
···
-
{ lib, stdenv, llvm_meta, version, src, cmake, python3, libllvm, libcxxabi }:
+
{ lib, stdenv, llvm_meta, version, src, cmake, python3, xcbuild, libllvm, libcxxabi }:
let
···
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 = [
···
# 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
···
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) ''
+8 -7
pkgs/development/compilers/llvm/14/compiler-rt/default.nix
···
{ lib, stdenv, llvm_meta, version
, monorepoSrc, runCommand
-
, cmake, python3, libllvm, libcxxabi
+
, cmake, python3, xcbuild, libllvm, libcxxabi
}:
let
···
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 = [
···
# 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
···
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) ''
+25
pkgs/development/compilers/llvm/common/compiler-rt/darwin-plistbuddy-workaround.patch
···
+
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)
+8 -7
pkgs/development/compilers/llvm/git/compiler-rt/default.nix
···
{ lib, stdenv, llvm_meta, version
, monorepoSrc, runCommand
-
, cmake, python3, libllvm, libcxxabi
+
, cmake, python3, xcbuild, libllvm, libcxxabi
}:
let
···
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 = [
···
# 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
···
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) ''