Skip to content
6 changes: 5 additions & 1 deletion pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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; };
Expand Down
7 changes: 7 additions & 0 deletions pkgs/build-support/cc-wrapper/ld-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/compilers/llvm/3.6/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/compilers/llvm/3.7/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/compilers/llvm/3.7/llvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand All @@ -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
'';
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/compilers/llvm/3.8/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/compilers/llvm/3.9/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
6 changes: 5 additions & 1 deletion pkgs/os-specific/darwin/cctools/port.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
'';
});

Expand Down
1 change: 1 addition & 0 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down