gcc: link $lib/lib -> $lib/$targetConfig correctly and consistently

When native-compiling, gcc will install libraries into:

/nix/store/...-$targetConfig-gcc-$version-lib/lib

When cross-compiling, gcc will install libraries into:

/nix/store/...-$targetConfig-gcc-$version-lib/$targetConfig

When cross-compiling, we intended to create a link from $lib/lib to
$lib/$targetConfig, so that downstream users can always safely
assume that "${lib.getLib stdenv.cc.cc}/lib" is where the gcc
libraries are, regardless of whether `stdenv.cc.cc` is a cross
compiler or a native compiler.

Unfortunately, there were two problems with how we were trying to
create these links:

1. The link would be created only when `enableLibGccOutput==true`

2. The link was being created from the incorrect source
`$lib/lib/lib` instead of `$lib/lib`.

Both of these mistakes are my fault. This commit corrects them by
creating the link using `ln -Ts` (which is more predictable) and by
creating the link from `gcc/common/builder.nix` rather than from
`gcc/common/libgcc.nix`.

authored by Adam Joseph and committed by Connor Baker b81284ec 655a011e

+11 -5
+8
pkgs/development/compilers/gcc/common/builder.nix
··· 1 { lib 2 , stdenv 3 , enableMultilib 4 }: 5 6 let ··· 195 preInstall = '' 196 mkdir -p "$out/''${targetConfig}/lib" 197 mkdir -p "''${!outputLib}/''${targetConfig}/lib" 198 '' + 199 # Make `lib64` symlinks to `lib`. 200 lib.optionalString (!enableMultilib && stdenv.hostPlatform.is64bit && !stdenv.hostPlatform.isMips64n32) ''
··· 1 { lib 2 , stdenv 3 , enableMultilib 4 + , targetConfig 5 }: 6 7 let ··· 196 preInstall = '' 197 mkdir -p "$out/''${targetConfig}/lib" 198 mkdir -p "''${!outputLib}/''${targetConfig}/lib" 199 + '' + 200 + # if cross-compiling, link from $lib/lib to $lib/${targetConfig}. 201 + # since native-compiles have $lib/lib as a directory (not a 202 + # symlink), this ensures that in every case we can assume that 203 + # $lib/lib contains the .so files 204 + lib.optionalString (with stdenv; targetPlatform.config != hostPlatform.config) '' 205 + ln -Ts "''${!outputLib}/''${targetConfig}/lib" $lib/lib 206 '' + 207 # Make `lib64` symlinks to `lib`. 208 lib.optionalString (!enableMultilib && stdenv.hostPlatform.is64bit && !stdenv.hostPlatform.isMips64n32) ''
-4
pkgs/development/compilers/gcc/common/libgcc.nix
··· 83 lib.optionalString (!langC) '' 84 rm -f $out/lib/libgcc_s.so* 85 '' 86 - + lib.optionalString (hostPlatform != targetPlatform) '' 87 - mkdir -p $lib/lib/ 88 - ln -s ${targetPlatformSlash}lib $lib/lib 89 - '' 90 91 # TODO(amjoseph): remove the `libgcc_s.so` symlinks below and replace them 92 # with a `-L${gccForLibs.libgcc}/lib` in cc-wrapper's
··· 83 lib.optionalString (!langC) '' 84 rm -f $out/lib/libgcc_s.so* 85 '' 86 87 # TODO(amjoseph): remove the `libgcc_s.so` symlinks below and replace them 88 # with a `-L${gccForLibs.libgcc}/lib` in cc-wrapper's
+3 -1
pkgs/development/compilers/gcc/default.nix
··· 103 disableBootstrap = atLeast11 && !stdenv.hostPlatform.isDarwin && (atLeast12 -> !profiledCompiler); 104 105 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 106 107 patches = callFile ./patches {}; 108 ··· 124 buildPlatform 125 hostPlatform 126 targetPlatform 127 patches 128 crossMingw 129 stageNameAddon ··· 329 ++ optional (is7 && targetPlatform.isAarch64) "--enable-fix-cortex-a53-843419" 330 ++ optional (is7 && targetPlatform.isNetBSD) "--disable-libcilkrts"; 331 332 - targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 333 334 buildFlags = 335 # we do not yet have Nix-driven profiling
··· 103 disableBootstrap = atLeast11 && !stdenv.hostPlatform.isDarwin && (atLeast12 -> !profiledCompiler); 104 105 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 106 + targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 107 108 patches = callFile ./patches {}; 109 ··· 125 buildPlatform 126 hostPlatform 127 targetPlatform 128 + targetConfig 129 patches 130 crossMingw 131 stageNameAddon ··· 331 ++ optional (is7 && targetPlatform.isAarch64) "--enable-fix-cortex-a53-843419" 332 ++ optional (is7 && targetPlatform.isNetBSD) "--disable-libcilkrts"; 333 334 + inherit targetConfig; 335 336 buildFlags = 337 # we do not yet have Nix-driven profiling