diff options
author | Bernardo Meurer <bernardo@meurer.org> | 2023-04-03 08:19:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 08:19:03 -0700 |
commit | f1f6ca8bcd8d85a22a6f3e3d02c4e0bf9cb2c9cc (patch) | |
tree | 791eb576b729778367f1611ee7071419ea6aeb02 /pkgs/build-support/cc-wrapper | |
parent | 89ab0e405c1ca4bcc480f8ab1f0d740376e3ee09 (diff) | |
parent | 6c209e862e18d6a9d103a80d5fa2443f4e47163e (diff) |
Merge pull request #209870 from amjoseph-nixpkgs/pr/stdenv/external-gcc-bootstrap
Diffstat (limited to 'pkgs/build-support/cc-wrapper')
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 388e546461667..597e8105fa1dd 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -17,9 +17,40 @@ , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null , buildPackages ? {} , libcxx ? null + +# Whether or not to add `-B` and `-L` to `nix-support/cc-{c,ld}flags` +, useCcForLibs ? + + # Always add these flags for Clang, because in order to compile (most + # software) it needs libraries that are shipped and compiled with gcc. + if isClang then true + + # Never add these flags for a build!=host cross-compiler or a host!=target + # ("cross-built-native") compiler; currently nixpkgs has a special build + # path for these (`crossStageStatic`). Hopefully at some point that build + # path will be merged with this one and this conditional will be removed. + else if (with stdenvNoCC; buildPlatform != hostPlatform || hostPlatform != targetPlatform) then false + + # Never add these flags when wrapping the bootstrapFiles' compiler; it has a + # /usr/-like layout with everything smashed into a single outpath, so it has + # no trouble finding its own libraries. + else if (cc.passthru.isFromBootstrapFiles or false) then false + + # Add these flags when wrapping `xgcc` (the first compiler that nixpkgs builds) + else if (cc.passthru.isXgcc or false) then true + + # Add these flags when wrapping `stdenv.cc` + else if (cc.stdenv.cc.cc.passthru.isXgcc or false) then true + + # Do not add these flags in any other situation. This is `false` mainly to + # prevent these flags from being added when wrapping *old* versions of gcc + # (e.g. `gcc6Stdenv`), since they will cause the old gcc to get `-B` and + # `-L` flags pointing at the new gcc's libstdc++ headers. Example failure: + # https://hydra.nixos.org/build/213125495 + else false + +# the derivation at which the `-B` and `-L` flags added by `useCcForLibs` will point , gccForLibs ? if useCcForLibs then cc else null -# same as `gccForLibs`, but generalized beyond clang -, useCcForLibs ? isClang }: with lib; @@ -321,7 +352,7 @@ stdenv.mkDerivation { && targetPlatform.isLinux && !(stdenv.targetPlatform.useAndroidPrebuilt or false) && !(stdenv.targetPlatform.useLLVM or false) - && gccForLibs != null) '' + && gccForLibs != null) ('' echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags # Pull in 'cc.out' target to get 'libstdc++fs.a'. It should be in @@ -329,6 +360,11 @@ stdenv.mkDerivation { # TODO(trofi): remove once gcc is fixed to move libraries to .lib output. echo "-L${gccForLibs}/${optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}"}/lib" >> $out/nix-support/cc-ldflags '' + # this ensures that when clang passes -lgcc_s to lld (as it does + # when building e.g. firefox), lld is able to find libgcc_s.so + + lib.optionalString (gccForLibs?libgcc) '' + echo "-L${gccForLibs.libgcc}/lib" >> $out/nix-support/cc-ldflags + '') ## ## General libc support |