llvm-3.9: move shared libLLVM to a separate output

Fixes #18840: too large closure of mesa_drivers.

Tested atop 16.09:
- clang compiles a hello-world app;
- mesa seems to link OK;
- ispc builds.

Size comparison:
- 80 MB of full llvm-3.7 on 16.03;
- 200 MB of full llvm-3.9 on 16.09 before this patch;
- 50 MB of libLLVM after this commit.

+44 -3
+26
pkgs/development/compilers/llvm/3.9/llvm-outputs.patch
··· 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,
+18 -3
pkgs/development/compilers/llvm/3.9/llvm.nix
··· 30 30 mv compiler-rt-* $sourceRoot/projects/compiler-rt 31 31 ''; 32 32 33 + outputs = [ "out" ] ++ stdenv.lib.optional enableSharedLibraries "lib"; 34 + 33 35 buildInputs = [ perl groff cmake libxml2 python libffi ] 34 36 ++ stdenv.lib.optional stdenv.isDarwin libcxxabi; 35 37 36 38 propagatedBuildInputs = [ ncurses zlib ]; 37 39 40 + postPatch = "" 38 41 # hacky fix: New LLVM releases require a newer OS X SDK than 39 42 # 10.9. This is a temporary measure until nixpkgs darwin support is 40 43 # updated. 41 - patchPhase = stdenv.lib.optionalString stdenv.isDarwin '' 44 + + stdenv.lib.optionalString stdenv.isDarwin '' 42 45 sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc 46 + '' 47 + # Patch llvm-config to return correct library path based on --link-{shared,static}. 48 + + stdenv.lib.optionalString (enableSharedLibraries) '' 49 + substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib 50 + patch -p1 < ./llvm-outputs.patch 43 51 ''; 44 52 45 53 # hacky fix: created binaries need to be run before installation ··· 59 67 "-DLLVM_LINK_LLVM_DYLIB=ON" 60 68 ] ++ stdenv.lib.optional (!isDarwin) 61 69 "-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include" 62 - ++ stdenv.lib.optionals ( isDarwin) [ 70 + ++ stdenv.lib.optionals (isDarwin) [ 63 71 "-DLLVM_ENABLE_LIBCXX=ON" 64 72 "-DCAN_TARGET_i386=false" 65 73 ]; ··· 70 78 paxmark m bin/{lli,llvm-rtdyld} 71 79 ''; 72 80 73 - postInstall = stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) '' 81 + postInstall = "" 82 + + stdenv.lib.optionalString (enableSharedLibraries) '' 83 + moveToOutput "lib/libLLVM-*" "$lib" 84 + moveToOutput "lib/libLLVM.so" "$lib" 85 + substituteInPlace "$out/lib/cmake/llvm/LLVMExports-release.cmake" \ 86 + --replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-" 87 + '' 88 + + stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) '' 74 89 install_name_tool -id $out/lib/libLLVM.dylib $out/lib/libLLVM.dylib 75 90 ln -s $out/lib/libLLVM.dylib $out/lib/libLLVM-${version}.dylib 76 91 '';