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.
This commit is contained in:
parent
bb349421c1
commit
d2965a7d85
|
@ -0,0 +1,26 @@
|
||||||
|
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
|
||||||
|
index 94d426b..37f7794 100644
|
||||||
|
--- a/tools/llvm-config/llvm-config.cpp
|
||||||
|
+++ b/tools/llvm-config/llvm-config.cpp
|
||||||
|
@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
|
||||||
|
ActiveIncludeOption = "-I" + ActiveIncludeDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
|
||||||
|
+ if (!IsInDevelopmentTree) {
|
||||||
|
+ bool WantShared = true;
|
||||||
|
+ for (int i = 1; i < argc; ++i) {
|
||||||
|
+ StringRef Arg = argv[i];
|
||||||
|
+ if (Arg == "--link-shared")
|
||||||
|
+ WantShared = true;
|
||||||
|
+ else if (Arg == "--link-static")
|
||||||
|
+ WantShared = false; // the last one wins
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (WantShared)
|
||||||
|
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
/// We only use `shared library` mode in cases where the static library form
|
||||||
|
/// of the components provided are not available; note however that this is
|
||||||
|
/// skipped if we're run from within the build dir. However, once installed,
|
|
@ -30,16 +30,24 @@ in stdenv.mkDerivation rec {
|
||||||
mv compiler-rt-* $sourceRoot/projects/compiler-rt
|
mv compiler-rt-* $sourceRoot/projects/compiler-rt
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
outputs = [ "out" ] ++ stdenv.lib.optional enableSharedLibraries "lib";
|
||||||
|
|
||||||
buildInputs = [ perl groff cmake libxml2 python libffi ]
|
buildInputs = [ perl groff cmake libxml2 python libffi ]
|
||||||
++ stdenv.lib.optional stdenv.isDarwin libcxxabi;
|
++ stdenv.lib.optional stdenv.isDarwin libcxxabi;
|
||||||
|
|
||||||
propagatedBuildInputs = [ ncurses zlib ];
|
propagatedBuildInputs = [ ncurses zlib ];
|
||||||
|
|
||||||
|
postPatch = ""
|
||||||
# hacky fix: New LLVM releases require a newer OS X SDK than
|
# hacky fix: New LLVM releases require a newer OS X SDK than
|
||||||
# 10.9. This is a temporary measure until nixpkgs darwin support is
|
# 10.9. This is a temporary measure until nixpkgs darwin support is
|
||||||
# updated.
|
# updated.
|
||||||
patchPhase = stdenv.lib.optionalString stdenv.isDarwin ''
|
+ stdenv.lib.optionalString stdenv.isDarwin ''
|
||||||
sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
|
sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
|
||||||
|
''
|
||||||
|
# Patch llvm-config to return correct library path based on --link-{shared,static}.
|
||||||
|
+ stdenv.lib.optionalString (enableSharedLibraries) ''
|
||||||
|
substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
|
||||||
|
patch -p1 < ./llvm-outputs.patch
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# hacky fix: created binaries need to be run before installation
|
# hacky fix: created binaries need to be run before installation
|
||||||
|
@ -59,7 +67,7 @@ in stdenv.mkDerivation rec {
|
||||||
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
||||||
] ++ stdenv.lib.optional (!isDarwin)
|
] ++ stdenv.lib.optional (!isDarwin)
|
||||||
"-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
|
"-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
|
||||||
++ stdenv.lib.optionals ( isDarwin) [
|
++ stdenv.lib.optionals (isDarwin) [
|
||||||
"-DLLVM_ENABLE_LIBCXX=ON"
|
"-DLLVM_ENABLE_LIBCXX=ON"
|
||||||
"-DCAN_TARGET_i386=false"
|
"-DCAN_TARGET_i386=false"
|
||||||
];
|
];
|
||||||
|
@ -70,7 +78,14 @@ in stdenv.mkDerivation rec {
|
||||||
paxmark m bin/{lli,llvm-rtdyld}
|
paxmark m bin/{lli,llvm-rtdyld}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postInstall = stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
|
postInstall = ""
|
||||||
|
+ stdenv.lib.optionalString (enableSharedLibraries) ''
|
||||||
|
moveToOutput "lib/libLLVM-*" "$lib"
|
||||||
|
moveToOutput "lib/libLLVM.so" "$lib"
|
||||||
|
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-release.cmake" \
|
||||||
|
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
|
||||||
|
''
|
||||||
|
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
|
||||||
install_name_tool -id $out/lib/libLLVM.dylib $out/lib/libLLVM.dylib
|
install_name_tool -id $out/lib/libLLVM.dylib $out/lib/libLLVM.dylib
|
||||||
ln -s $out/lib/libLLVM.dylib $out/lib/libLLVM-${version}.dylib
|
ln -s $out/lib/libLLVM.dylib $out/lib/libLLVM-${version}.dylib
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Reference in New Issue