···1+{ stdenv, version, fetch, cmake, python, llvm, libcxxabi }:
2+with stdenv.lib;
3+stdenv.mkDerivation rec {
4+ name = "compiler-rt-${version}";
5+ inherit version;
6+ src = fetch "compiler-rt" "0r4hg8hi60kdjl4arp3s51dbwbwz11s8qvccdkx9v52vc27p2241";
7+8+ nativeBuildInputs = [ cmake python llvm ];
9+ buildInputs = stdenv.lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
10+11+ configureFlags = [
12+ "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
13+ ];
14+15+ outputs = [ "out" "dev" ];
16+17+ patches = [
18+ ./compiler-rt-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
19+ ] ++ optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch;
20+21+ # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
22+ # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
23+ # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
24+ # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
25+ # a flag and turn the flag off during the stdenv build.
26+ postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
27+ substituteInPlace cmake/config-ix.cmake \
28+ --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
29+ '';
30+31+ # Hack around weird upsream RPATH bug
32+ postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
33+ ln -s "$out/lib"/*/* "$out/lib"
34+ '';
35+36+ enableParallelBuilding = true;
37+}
···1+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
2+index 94d426b..37f7794 100644
3+--- a/tools/llvm-config/llvm-config.cpp
4++++ b/tools/llvm-config/llvm-config.cpp
5+@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
6+ ActiveIncludeOption = "-I" + ActiveIncludeDir;
7+ }
8+9++ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
10++ if (!IsInDevelopmentTree) {
11++ bool WantShared = true;
12++ for (int i = 1; i < argc; ++i) {
13++ StringRef Arg = argv[i];
14++ if (Arg == "--link-shared")
15++ WantShared = true;
16++ else if (Arg == "--link-static")
17++ WantShared = false; // the last one wins
18++ }
19++
20++ if (WantShared)
21++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
22++ }
23++
24+ /// We only use `shared library` mode in cases where the static library form
25+ /// of the components provided are not available; note however that this is
26+ /// skipped if we're run from within the build dir. However, once installed,