diff options
Diffstat (limited to 'pkgs/build-support')
-rwxr-xr-x | pkgs/build-support/buildenv/builder.pl | 7 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/cc-wrapper.sh | 6 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 101 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/ld-wrapper.sh | 44 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/setup-hook.sh | 27 | ||||
-rw-r--r-- | pkgs/build-support/fetchurl/builder.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper-old/builder.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/trivial-builders.nix | 2 |
8 files changed, 94 insertions, 97 deletions
diff --git a/pkgs/build-support/buildenv/builder.pl b/pkgs/build-support/buildenv/builder.pl index 678f5a3fe9e6..7cc37d156735 100755 --- a/pkgs/build-support/buildenv/builder.pl +++ b/pkgs/build-support/buildenv/builder.pl @@ -141,12 +141,11 @@ sub addPkg { my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages"; if (-e $propagatedFN) { open PROP, "<$propagatedFN" or die; - my $propagated = <PROP>; - close PROP; - my @propagated = split ' ', $propagated; - foreach my $p (@propagated) { + while (my $p = <PROP>) { + chomp $p; $postponed{$p} = 1 unless defined $done{$p}; } + close PROP; } } diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 3ccdc34db5b2..99eb63f40edf 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -55,7 +55,7 @@ while [ $n -lt ${#params[*]} ]; do nonFlagArgs=1 elif [ "$p" = -m32 ]; then if [ -e @out@/nix-support/dynamic-linker-m32 ]; then - NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)" + NIX_LDFLAGS+=" -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)" fi fi n=$((n + 1)) @@ -111,9 +111,9 @@ fi if [[ "$isCpp" = 1 ]]; then if [[ "$cppInclude" = 1 ]]; then - NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}" + NIX_CFLAGS_COMPILE+=" ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}" fi - NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK $NIX_CXXSTDLIB_LINK" + NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK" fi LD=@ldPath@/ld diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 676fbd006881..09d1d4cd681a 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -71,22 +71,6 @@ let -e 's^addCVars^addCVars${_infixSalt}^g' \ -e 's^\[ -z "\$crossConfig" \]^\[\[ "${builtins.toString (targetPlatform != hostPlatform)}" || -z "$crossConfig" \]\]^g' - '' + stdenv.lib.optionalString (textFile == ./setup-hook.sh) '' - cat << 'EOF' >> $out - for CMD in ar as nm objcopy ranlib strip strings size ld windres - do - # which is not part of stdenv, but compgen will do for now - if - PATH=$_PATH type -p ${prefix}$CMD > /dev/null - then - export ''$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=${prefix}''${CMD}; - fi - done - EOF - - sed -i $out -e 's_envHooks_crossEnvHooks_g' - '' + '' - # NIX_ things which we don't both use and define, we revert them #asymmetric=$( # for pre in "" "\\$" @@ -105,22 +89,20 @@ let done ''); - # The dynamic linker has different names on different platforms. + # The dynamic linker has different names on different platforms. This is a + # shell glob that ought to match it. dynamicLinker = - if !nativeLibc then - (if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else - if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else - # ARM with a wildcard, which can be "" or "-armhf". - if targetPlatform.isArm32 then "ld-linux*.so.3" else - if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else - if targetPlatform.system == "powerpc-linux" then "ld.so.1" else - if targetPlatform.system == "mips64el-linux" then "ld.so.1" else - if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else - if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else - builtins.trace - "Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead." - null) - else ""; + /**/ if libc == null then null + else if targetPlatform.system == "i686-linux" then "${libc_lib}/lib/ld-linux.so.2" + else if targetPlatform.system == "x86_64-linux" then "${libc_lib}/lib/ld-linux-x86-64.so.2" + # ARM with a wildcard, which can be "" or "-armhf". + else if targetPlatform.isArm32 then "${libc_lib}/lib/ld-linux*.so.3" + else if targetPlatform.system == "aarch64-linux" then "${libc_lib}/lib/ld-linux-aarch64.so.1" + else if targetPlatform.system == "powerpc-linux" then "${libc_lib}/lib/ld.so.1" + else if targetPlatform.system == "mips64el-linux" then "${libc_lib}/lib/ld.so.1" + else if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" + else if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" + else null; expand-response-params = if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null" then buildPackages.stdenv.mkDerivation { @@ -145,6 +127,7 @@ stdenv.mkDerivation { inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin; gnugrep_bin = if nativeTools then "" else gnugrep; + binPrefix = prefix; passthru = { inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile @@ -175,39 +158,39 @@ stdenv.mkDerivation { } '' - # TODO(@Ericson2314): Unify logic next hash break - + optionalString (libc != null) (if (targetPlatform.isDarwin) then '' - echo $dynamicLinker > $out/nix-support/dynamic-linker + + optionalString (libc != null) ('' + if [[ -z ''${dynamicLinker+x} ]]; then + echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2 + dynamicLinker="${libc_lib}/lib/ld*.so.?" + fi - echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook - '' else if dynamicLinker != null then '' - dynamicLinker="${libc_lib}/lib/$dynamicLinker" - echo $dynamicLinker > $out/nix-support/dynamic-linker + # Expand globs to fill array of options + dynamicLinker=($dynamicLinker) - if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then - echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 - fi + case ''${#dynamicLinker[@]} in + 0) echo "No dynamic linker found for platform '${targetPlatform.config}'." >&2;; + 1) echo "Using dynamic linker: '$dynamicLinker'" >&2;; + *) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;; + esac - # 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 '' - dynamicLinker=`eval 'echo $libc/lib/ld*.so.?'` if [ -n "$dynamicLinker" ]; then echo $dynamicLinker > $out/nix-support/dynamic-linker + '' + (if targetPlatform.isDarwin then '' + printf "export LD_DYLD_PATH+=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook + '' else '' if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 fi - ldflagsBefore="-dynamic-linker $dlinker" + ldflagsBefore=(-dynamic-linker "$dynamicLinker") + '') + '' 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 "$ldflagsBefore" > $out/nix-support/libc-ldflags-before + printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before '') + optionalString (libc != null) '' @@ -275,9 +258,9 @@ stdenv.mkDerivation { # Propagate the wrapped cc so that if you install the wrapper, # you get tools like gcov, the manpages, etc. as well (including # for binutils and Glibc). - echo ${cc} ${cc.man or ""} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages + printWords ${cc} ${cc.man or ""} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages - echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs + printWords ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs '' + optionalString (targetPlatform.isSunOS && nativePrefix != "") '' @@ -305,20 +288,24 @@ stdenv.mkDerivation { wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd fi - export real_cc=${prefix}cc - export real_cxx=${prefix}c++ + # We export environment variables pointing to the wrapped nonstandard + # cmds, lest some lousy configure script use those to guess compiler + # version. + export named_cc=${prefix}cc + export named_cxx=${prefix}c++ + export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}" if [ -e $ccPath/${prefix}gcc ]; then wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc ln -s ${prefix}gcc $out/bin/${prefix}cc - export real_cc=${prefix}gcc - export real_cxx=${prefix}g++ + export named_cc=${prefix}gcc + export named_cxx=${prefix}g++ elif [ -e $ccPath/clang ]; then wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang ln -s ${prefix}clang $out/bin/${prefix}cc - export real_cc=clang - export real_cxx=clang++ + export named_cc=${prefix}clang + export named_cxx=${prefix}clang++ fi if [ -e $ccPath/${prefix}g++ ]; then diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 056cfa920535..240082b5dfdc 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -64,7 +64,9 @@ extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN) # Add all used dynamic libraries to the rpath. if [ "$NIX_DONT_SET_RPATH" != 1 ]; then - libPath="" + declare -A libDirsSeen + declare -a libDirs + addToLibPath() { local path="$1" if [ "${path:0:1}" != / ]; then return 0; fi @@ -76,29 +78,27 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then fi ;; esac - case $libPath in - *\ $path\ *) return 0 ;; - esac - libPath="$libPath $path " + if [[ -z ${libDirsSeen[$path]} ]]; then + libDirs+=("$path") + libDirsSeen[$path]=1 + fi } + declare -A rpathsSeen + declare -a rpaths + addToRPath() { # If the path is not in the store, don't add it to the rpath. # This typically happens for libraries in /tmp that are later # copied to $out/lib. If not, we're screwed. if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi - case $rpath in - *\ $1\ *) return 0 ;; - esac - rpath="$rpath $1 " - } - - libs="" - addToLibs() { - libs="$libs $1" + if [[ -z ${rpathsSeen[$1]} ]]; then + rpaths+=("$1") + rpathsSeen[$1]=1 + fi } - rpath="" + declare -a libs # First, find all -L... switches. allParams=("${params[@]}" ${extra[@]}) @@ -112,10 +112,10 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then addToLibPath ${p2} n=$((n + 1)) elif [ "$p" = -l ]; then - addToLibs ${p2} + libs+=(${p2}) n=$((n + 1)) elif [ "${p:0:2}" = -l ]; then - addToLibs ${p:2} + libs+=(${p:2}) elif [ "$p" = -dynamic-linker ]; then # Ignore the dynamic linker argument, or it # will get into the next 'elif'. We don't want @@ -135,9 +135,8 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then # so, add the directory to the rpath. # It's important to add the rpath in the order of -L..., so # the link time chosen objects will be those of runtime linking. - - for i in $libPath; do - for j in $libs; do + for i in ${libDirs[@]}; do + for j in ${libs[@]}; do if [ -f "$i/lib$j.so" ]; then addToRPath $i break @@ -145,10 +144,9 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then done done - # Finally, add `-rpath' switches. - for i in $rpath; do - extra+=(-rpath $i) + for i in ${rpaths[@]}; do + extra+=(-rpath "$i") done fi diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index f4f7ab181d3e..104b82425f29 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -1,5 +1,3 @@ -export NIX_CC=@out@ - addCVars () { if [ -d $1/include ]; then export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" @@ -39,9 +37,26 @@ if [ -n "@coreutils_bin@" ]; then fi if [ -z "$crossConfig" ]; then - export CC=@real_cc@ - export CXX=@real_cxx@ + ENV_PREFIX="" else - export BUILD_CC=@real_cc@ - export BUILD_CXX=@real_cxx@ + ENV_PREFIX="BUILD_" fi + +export NIX_${ENV_PREFIX}CC=@out@ + +export ${ENV_PREFIX}CC=@named_cc@ +export ${ENV_PREFIX}CXX=@named_cxx@ + +for CMD in \ + cpp \ + ar as nm objcopy ranlib strip strings size ld windres +do + if + PATH=$_PATH type -p "@binPrefix@$CMD" > /dev/null + then + export "${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}"; + fi +done + +# No local scope available for sourced files +unset ENV_PREFIX diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index c4fd18e46caf..7c2bdf260b4e 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -39,7 +39,6 @@ tryDownload() { curlexit=$?; fi done - stopNest } @@ -51,7 +50,6 @@ finish() { fi runHook postFetch - stopNest exit 0 } diff --git a/pkgs/build-support/gcc-wrapper-old/builder.sh b/pkgs/build-support/gcc-wrapper-old/builder.sh index a8e8a370ec0d..22e32814927e 100644 --- a/pkgs/build-support/gcc-wrapper-old/builder.sh +++ b/pkgs/build-support/gcc-wrapper-old/builder.sh @@ -211,5 +211,5 @@ cp -p $utils $out/nix-support/utils.sh # tools like gcov, the manpages, etc. as well (including for binutils # and Glibc). if test -z "$nativeTools"; then - echo $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages + printWords $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages fi diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 4debd9636396..16bd4e8e4054 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -84,7 +84,7 @@ rec { mkdir -p $out/nix-support cp ${script} $out/nix-support/setup-hook '' + lib.optionalString (deps != []) '' - echo ${toString deps} > $out/nix-support/propagated-native-build-inputs + printWords ${toString deps} > $out/nix-support/propagated-native-build-inputs '' + lib.optionalString (substitutions != {}) '' substituteAll ${script} $out/nix-support/setup-hook ''); |