···11+{ stdenv, version, fetch, cmake, python, llvm, libcxxabi }:
22+with stdenv.lib;
33+stdenv.mkDerivation rec {
44+ name = "compiler-rt-${version}";
55+ inherit version;
66+ src = fetch "compiler-rt" "0r4hg8hi60kdjl4arp3s51dbwbwz11s8qvccdkx9v52vc27p2241";
77+88+ nativeBuildInputs = [ cmake python llvm ];
99+ buildInputs = stdenv.lib.optional stdenv.hostPlatform.isDarwin libcxxabi;
1010+1111+ configureFlags = [
1212+ "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
1313+ ];
1414+1515+ outputs = [ "out" "dev" ];
1616+1717+ patches = [
1818+ ./compiler-rt-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
1919+ ] ++ optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch;
2020+2121+ # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
2222+ # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
2323+ # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
2424+ # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
2525+ # a flag and turn the flag off during the stdenv build.
2626+ postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
2727+ substituteInPlace cmake/config-ix.cmake \
2828+ --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
2929+ '';
3030+3131+ # Hack around weird upsream RPATH bug
3232+ postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
3333+ ln -s "$out/lib"/*/* "$out/lib"
3434+ '';
3535+3636+ enableParallelBuilding = true;
3737+}
···11+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
22+index 94d426b..37f7794 100644
33+--- a/tools/llvm-config/llvm-config.cpp
44++++ b/tools/llvm-config/llvm-config.cpp
55+@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
66+ ActiveIncludeOption = "-I" + ActiveIncludeDir;
77+ }
88+99++ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
1010++ if (!IsInDevelopmentTree) {
1111++ bool WantShared = true;
1212++ for (int i = 1; i < argc; ++i) {
1313++ StringRef Arg = argv[i];
1414++ if (Arg == "--link-shared")
1515++ WantShared = true;
1616++ else if (Arg == "--link-static")
1717++ WantShared = false; // the last one wins
1818++ }
1919++
2020++ if (WantShared)
2121++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
2222++ }
2323++
2424+ /// We only use `shared library` mode in cases where the static library form
2525+ /// of the components provided are not available; note however that this is
2626+ /// skipped if we're run from within the build dir. However, once installed,