Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cc-wrapper changes to better support darwin and clang #6254

Merged
merged 1 commit into from
Feb 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkgs/build-support/cc-wrapper/cc-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
params=("${rest[@]}")
fi

if [[ "@prog@" = *++ ]]; then
if echo "$@" | grep -qvw -- -nostdlib; then
NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE $NIX_CXXSTDLIB_COMPILE"
NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK $NIX_CXXSTDLIB_LINK"
fi
fi

# Add the flags for the C compiler proper.
extraAfter=($NIX_CFLAGS_COMPILE)
extraBefore=()
Expand Down
25 changes: 18 additions & 7 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
, cc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell
, zlib ? null, extraPackages ? []
, dyld ? null # TODO: should this be a setup-hook on dyld?
, setupHook ? ./setup-hook.sh
}:

Expand Down Expand Up @@ -55,14 +56,25 @@ stdenv.mkDerivation {
}
''

+ optionalString (!nativeLibc) ''
+ optionalString (!nativeLibc) (if (!stdenv.isDarwin) then ''
dynamicLinker="$libc/lib/$dynamicLinker"
echo $dynamicLinker > $out/nix-support/dynamic-linker

if [ -e $libc/lib/32/ld-linux.so.2 ]; then
echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
fi

# The dynamic linker is passed in `ldflagsBefore' to allow
# explicit overrides of the dynamic linker by callers to gcc/ld
# (the *last* value counts, so ours should come first).
echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
'' else ''
echo $dynamicLinker > $out/nix-support/dynamic-linker

echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook
'')

+ optionalString (!nativeLibc) ''
# The "-B$libc/lib/" flag is a quick hack to force gcc to link
# against the crt1.o from our own glibc, rather than the one in
# /usr/lib. (This is only an issue when using an `impure'
Expand All @@ -78,11 +90,6 @@ stdenv.mkDerivation {

echo "-L$libc/lib" > $out/nix-support/libc-ldflags

# The dynamic linker is passed in `ldflagsBefore' to allow
# explicit overrides of the dynamic linker by callers to gcc/ld
# (the *last* value counts, so ours should come first).
echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before

echo $libc > $out/nix-support/orig-libc
''

Expand Down Expand Up @@ -213,7 +220,10 @@ stdenv.mkDerivation {
''

+ ''
substituteAll ${setupHook} $out/nix-support/setup-hook
substituteAll ${setupHook} $out/nix-support/setup-hook.tmp
cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook
rm $out/nix-support/setup-hook.tmp

substituteAll ${./add-flags} $out/nix-support/add-flags.sh
cp -p ${./utils.sh} $out/nix-support/utils.sh
'';
Expand All @@ -227,6 +237,7 @@ stdenv.mkDerivation {
if stdenv.isArm then "ld-linux*.so.3" else
if stdenv.system == "powerpc-linux" then "ld.so.1" else
if stdenv.system == "mips64el-linux" then "ld.so.1" else
if stdenv.system == "x86_64-darwin" then "${dyld}/lib/dyld" else
abort "Don't know the name of the dynamic linker for this platform.")
else "";

Expand Down
4 changes: 4 additions & 0 deletions pkgs/build-support/cc-wrapper/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ addCVars () {
if [ -d $1/lib ]; then
export NIX_LDFLAGS+=" -L$1/lib"
fi

if test -d $1/Library/Frameworks; then
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -F$1/Library/Frameworks"
fi
}

envHooks+=(addCVars)
Expand Down