diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 8a746ea016ef0..2f0ab7cfadd56 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -10,6 +10,7 @@ , zlib ? null, extraPackages ? [], extraBuildCommands ? "" , dyld ? null # TODO: should this be a setup-hook on dyld? , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null +, llvm ? null }: with stdenv.lib; @@ -22,6 +23,8 @@ assert !nativeLibc -> libc != null; # For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper. assert cc.langVhdl or false -> zlib != null; +assert llvm != null -> isClang; + let ccVersion = (builtins.parseDrvName cc.name).version; @@ -30,6 +33,7 @@ let libc_bin = if nativeLibc then null else getBin libc; libc_dev = if nativeLibc then null else getDev libc; libc_lib = if nativeLibc then null else getLib libc; + llvm_lib = if llvm != null then getLib llvm else ""; cc_solib = getLib cc; binutils_bin = if nativeTools then "" else getBin binutils; # The wrapper scripts use 'cat' and 'grep', so we may need coreutils. @@ -43,7 +47,7 @@ stdenv.mkDerivation { preferLocalBuild = true; - inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin; + inherit cc shell libc_bin libc_dev libc_lib llvm_lib binutils_bin coreutils_bin; gnugrep_bin = if nativeTools then "" else gnugrep; passthru = { inherit libc nativeTools nativeLibc nativePrefix isGNU isClang; }; diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 44d9a047936a5..39cc725a0b6a3 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -167,6 +167,9 @@ if [ "$NIX_SET_BUILD_ID" = 1 ]; then fi fi +if [ -n "@llvm_lib@" ]; then + export DYLD_LIBRARY_PATH="@llvm_lib@/lib:$DYLD_LIBRARY_PATH" +fi # Optionally print debug info. if [ -n "$NIX_DEBUG" ]; then @@ -178,6 +181,10 @@ if [ -n "$NIX_DEBUG" ]; then for i in ${extra[@]}; do echo " $i" >&2 done + if [ -n "@llvm_lib@" ]; then + echo "DYLD_LIBRARY_PATH variable for @prog@:" >&2 + echo " $DYLD_LIBRARY_PATH" >&2 + fi fi if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then diff --git a/pkgs/development/compilers/llvm/3.6/clang/default.nix b/pkgs/development/compilers/llvm/3.6/clang/default.nix index c1d0cf8062c81..bc953091adc0c 100644 --- a/pkgs/development/compilers/llvm/3.6/clang/default.nix +++ b/pkgs/development/compilers/llvm/3.6/clang/default.nix @@ -42,6 +42,7 @@ let passthru = { lib = self; # compatibility with gcc, so that `stdenv.cc.cc.lib` works on both isClang = true; + inherit llvm; } // stdenv.lib.optionalAttrs stdenv.isLinux { inherit gcc; }; diff --git a/pkgs/development/compilers/llvm/3.7/clang/default.nix b/pkgs/development/compilers/llvm/3.7/clang/default.nix index 6c1a89cf60a90..4f94ecfbc9b80 100644 --- a/pkgs/development/compilers/llvm/3.7/clang/default.nix +++ b/pkgs/development/compilers/llvm/3.7/clang/default.nix @@ -42,6 +42,7 @@ let passthru = { lib = self; # compatibility with gcc, so that `stdenv.cc.cc.lib` works on both isClang = true; + inherit llvm; } // stdenv.lib.optionalAttrs stdenv.isLinux { inherit gcc; }; diff --git a/pkgs/development/compilers/llvm/3.7/llvm.nix b/pkgs/development/compilers/llvm/3.7/llvm.nix index cc65c69927c5f..b06b149e97c17 100644 --- a/pkgs/development/compilers/llvm/3.7/llvm.nix +++ b/pkgs/development/compilers/llvm/3.7/llvm.nix @@ -28,6 +28,7 @@ in stdenv.mkDerivation rec { sourceRoot=$PWD/llvm unpackFile ${compiler-rt_src} mv compiler-rt-* $sourceRoot/projects/compiler-rt + sed -i 's/-compatibility_version .* -current_version/-compatibility_version 1 -current_version/g' $sourceRoot/tools/llvm-shlib/CMakeLists.txt ''; buildInputs = [ perl groff cmake libxml2 python libffi ] @@ -37,6 +38,7 @@ in stdenv.mkDerivation rec { # hacky fix: created binaries need to be run before installation preBuild = '' + sed -i 's/-compatibility_version .* -current_version/-compatibility_version 1 -current_version/g' $PWD/tools/lto/CMakeFiles/LTO.dir/link.txt mkdir -p $out/ ln -sv $PWD/lib $out ''; diff --git a/pkgs/development/compilers/llvm/3.8/clang/default.nix b/pkgs/development/compilers/llvm/3.8/clang/default.nix index 9282a64c8a56e..d0acbcaed0db4 100644 --- a/pkgs/development/compilers/llvm/3.8/clang/default.nix +++ b/pkgs/development/compilers/llvm/3.8/clang/default.nix @@ -42,6 +42,7 @@ let passthru = { lib = self; # compatibility with gcc, so that `stdenv.cc.cc.lib` works on both isClang = true; + inherit llvm; } // stdenv.lib.optionalAttrs stdenv.isLinux { inherit gcc; }; diff --git a/pkgs/development/compilers/llvm/3.9/clang/default.nix b/pkgs/development/compilers/llvm/3.9/clang/default.nix index e75da0e9717e6..8c452d50d8f7c 100644 --- a/pkgs/development/compilers/llvm/3.9/clang/default.nix +++ b/pkgs/development/compilers/llvm/3.9/clang/default.nix @@ -43,6 +43,7 @@ let passthru = { lib = self; # compatibility with gcc, so that `stdenv.cc.cc.lib` works on both isClang = true; + inherit llvm; } // stdenv.lib.optionalAttrs stdenv.isLinux { inherit gcc; }; diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix index bc6492f243fa6..959947fcc2208 100644 --- a/pkgs/os-specific/darwin/cctools/port.nix +++ b/pkgs/os-specific/darwin/cctools/port.nix @@ -18,7 +18,7 @@ let buildInputs = [ autoconf automake libtool_2 openssl libuuid ] ++ # Only need llvm and clang if the stdenv isn't already clang-based (TODO: just make a stdenv.cc.isClang) stdenv.lib.optionals (!stdenv.isDarwin) [ llvm clang ] ++ - stdenv.lib.optionals stdenv.isDarwin [ libcxxabi libobjc ]; + stdenv.lib.optionals stdenv.isDarwin [ llvm libcxxabi libobjc ]; patches = [ ./ld-rpath-nonfinal.patch ./ld-ignore-rpath-link.patch @@ -83,6 +83,10 @@ in { #!${stdenv.shell} EOF chmod +x $out/bin/dsymutil + exe="$out/bin/ld" + '' + stdenv.lib.optionalString (stdenv.isDarwin) '' + install_name_tool -add_rpath ${llvm}/lib $exe + install_name_tool -change '@rpath/libLTO.3.7.dylib' '@rpath/libLTO.dylib' $exe ''; }); diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 09d9ed23b3f84..35b72ae1a5ffa 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -285,6 +285,7 @@ in rec { inherit (pkgs.darwin) dyld; cc = pkgs.llvmPackages.clang-unwrapped; libc = pkgs.darwin.Libsystem; + llvm = pkgs.llvmPackages.clang-unwrapped.llvm; }; extraBuildInputs = with pkgs; [ darwin.CF libcxx ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 55e3844d8cdc5..6e0ac2b737295 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5191,6 +5191,7 @@ in isGNU = baseCC.isGNU or false; isClang = baseCC.isClang or false; inherit libc extraBuildCommands; + llvm = baseCC.llvm or null; }; wrapCC = wrapCCWith (callPackage ../build-support/cc-wrapper) stdenv.cc.libc "";