lol

llvm and clang 6: factor out compiler-rt, fix libstdcxxStdenv sanitizer headers

Build compiler-rt separate from llvm and clang, and just add as an extra
library in the wrapper.

authored by ralith.com and committed by

John Ericson 16da44b5 e5175fbf

+53 -27
+2 -7
pkgs/development/compilers/llvm/6/clang/default.nix
··· 30 30 "-DSPHINX_OUTPUT_MAN=ON" 31 31 "-DSPHINX_OUTPUT_HTML=OFF" 32 32 "-DSPHINX_WARNINGS_AS_ERRORS=OFF" 33 - ] 34 - # Maybe with compiler-rt this won't be needed? 35 - ++ stdenv.lib.optional stdenv.isLinux "-DGCC_INSTALL_PREFIX=${gcc}" 36 - ++ stdenv.lib.optional (stdenv.cc.libc != null) "-DC_INCLUDE_DIRS=${stdenv.cc.libc}/include"; 33 + ]; 37 34 38 35 patches = [ ./purity.patch ]; 39 36 ··· 51 48 outputs = [ "out" "lib" "python" ]; 52 49 53 50 # Clang expects to find LLVMgold in its own prefix 54 - # Clang expects to find sanitizer libraries in its own prefix 55 51 postInstall = '' 56 52 if [ -e ${llvm}/lib/LLVMgold.so ]; then 57 53 ln -sv ${llvm}/lib/LLVMgold.so $out/lib 58 54 fi 59 55 60 - ln -sv ${llvm}/lib/clang/${release_version}/lib $out/lib/clang/${release_version}/ 61 56 ln -sv $out/bin/clang $out/bin/cpp 62 57 63 58 # Move libclang to 'lib' output ··· 79 74 passthru = { 80 75 isClang = true; 81 76 inherit llvm; 82 - } // stdenv.lib.optionalAttrs stdenv.isLinux { 77 + } // stdenv.lib.optionalAttrs stdenv.targetPlatform.isLinux { 83 78 inherit gcc; 84 79 }; 85 80
+31
pkgs/development/compilers/llvm/6/compiler-rt.nix
··· 1 + { stdenv, version, fetch, cmake, python, llvm }: 2 + with stdenv.lib; 3 + stdenv.mkDerivation rec { 4 + name = "compiler-rt-${version}"; 5 + inherit version; 6 + src = fetch "compiler-rt" "16m7rvh3w6vq10iwkjrr1nn293djld3xm62l5zasisaprx117k6h"; 7 + 8 + nativeBuildInputs = [ cmake python llvm ]; 9 + 10 + configureFlags = [ 11 + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" 12 + ]; 13 + 14 + outputs = [ "dev" "out" ]; 15 + 16 + patches = [ 17 + ./compiler-rt-codesign.patch # Revert compiler-rt commit that makes codesign mandatory 18 + ] ++ optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch; 19 + 20 + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks 21 + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra 22 + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd 23 + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by 24 + # a flag and turn the flag off during the stdenv build. 25 + postPatch = stdenv.lib.optionalString stdenv.isDarwin '' 26 + substituteInPlace cmake/config-ix.cmake \ 27 + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 28 + ''; 29 + 30 + enableParallelBuilding = true; 31 + }
+20 -4
pkgs/development/compilers/llvm/6/default.nix
··· 14 14 inherit sha256; 15 15 }; 16 16 17 - compiler-rt_src = fetch "compiler-rt" "16m7rvh3w6vq10iwkjrr1nn293djld3xm62l5zasisaprx117k6h"; 18 17 clang-tools-extra_src = fetch "clang-tools-extra" "1ll9v6r29xfdiywbn9iss49ad39ah3fk91wiv0sr6k6k9i544fq5"; 19 18 20 19 # Add man output without introducing extra dependencies. ··· 27 26 in { 28 27 29 28 llvm = overrideManOutput (callPackage ./llvm.nix { 30 - inherit compiler-rt_src; 31 29 inherit (targetLlvmLibraries) libcxxabi; 32 30 }); 33 31 clang-unwrapped = overrideManOutput (callPackage ./clang { ··· 43 41 libstdcxxClang = wrapCCWith { 44 42 cc = tools.clang-unwrapped; 45 43 extraPackages = [ libstdcxxHook ]; 44 + extraBuildCommands = stdenv.lib.optionalString stdenv.targetPlatform.isLinux '' 45 + echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags 46 + ''; 46 47 }; 47 48 48 - libcxxClang = wrapCCWith { 49 + libcxxClang = wrapCCWith rec { 49 50 cc = tools.clang-unwrapped; 50 - extraPackages = [ targetLlvmLibraries.libcxx targetLlvmLibraries.libcxxabi ]; 51 + extraPackages = [ 52 + targetLlvmLibraries.libcxx 53 + targetLlvmLibraries.libcxxabi 54 + targetLlvmLibraries.compiler-rt 55 + ]; 56 + extraBuildCommands = '' 57 + rsrc="$out/resource-root" 58 + mkdir "$rsrc" 59 + ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc" 60 + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" 61 + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags 62 + '' + stdenv.lib.optionalString stdenv.targetPlatform.isLinux '' 63 + echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags 64 + ''; 51 65 }; 52 66 53 67 lld = callPackage ./lld.nix {}; ··· 58 72 libraries = let 59 73 callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python2 isl release_version version fetch; }); 60 74 in { 75 + 76 + compiler-rt = callPackage ./compiler-rt.nix {}; 61 77 62 78 stdenv = overrideCC stdenv buildLlvmTools.clang; 63 79
-16
pkgs/development/compilers/llvm/6/llvm.nix
··· 11 11 , version 12 12 , release_version 13 13 , zlib 14 - , compiler-rt_src 15 14 , libcxxabi 16 15 , debugVersion ? false 17 16 , enableManpages ? false ··· 33 32 unpackFile ${src} 34 33 mv llvm-${version}* llvm 35 34 sourceRoot=$PWD/llvm 36 - unpackFile ${compiler-rt_src} 37 - mv compiler-rt-* $sourceRoot/projects/compiler-rt 38 35 ''; 39 36 40 37 outputs = [ "out" "python" ] ··· 48 45 49 46 propagatedBuildInputs = [ ncurses zlib ]; 50 47 51 - # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks 52 - # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra 53 - # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd 54 - # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by 55 - # a flag and turn the flag off during the stdenv build. 56 48 postPatch = stdenv.lib.optionalString stdenv.isDarwin '' 57 - substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \ 58 - --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 59 - 60 49 substituteInPlace cmake/modules/AddLLVM.cmake \ 61 50 --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \ 62 51 --replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' "" ··· 70 59 substituteInPlace unittests/Support/CMakeLists.txt \ 71 60 --replace "Path.cpp" "" 72 61 rm unittests/Support/Path.cpp 73 - 74 - # Revert compiler-rt commit that makes codesign mandatory 75 - patch -p1 -i ${./compiler-rt-codesign.patch} -d projects/compiler-rt 76 62 '' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl '' 77 63 patch -p1 -i ${../TLI-musl.patch} 78 64 substituteInPlace unittests/Support/CMakeLists.txt \ 79 65 --replace "add_subdirectory(DynamicLibrary)" "" 80 66 rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp 81 - patch -p1 -i ${./sanitizers-nongnu.patch} -d projects/compiler-rt 82 67 ''; 83 68 84 69 # hacky fix: created binaries need to be run before installation ··· 93 78 "-DLLVM_BUILD_TESTS=ON" 94 79 "-DLLVM_ENABLE_FFI=ON" 95 80 "-DLLVM_ENABLE_RTTI=ON" 96 - "-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code 97 81 ] 98 82 ++ stdenv.lib.optional enableSharedLibraries 99 83 "-DLLVM_LINK_LLVM_DYLIB=ON"