gcc: do not install sys-include headers for cross-compilers.

Before the change include headers for cross-compilers like `pkgsStatic`
looked like this:

    $ nix build -L --impure --expr 'with import ./. {}; pkgsStatic.stdenv.mkDerivation { name = "probe"; buildCommand = "echo | $CXX -x c++ -E -v - |& fgrep -B10 search; exit 1"; }' |& unnix

    #include "..." search starts here:
    #include <...> search starts here:
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/x86_64-unknown-linux-musl
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/backward
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/sys-include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include
     /<<NIX>>/musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include-fixed
    End of search list.

Note that `.../sys-include` inhibits the effect of `musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include`.

After the change the paths look as expected:

    $ nix build -L --impure --expr 'with import ./. {}; pkgsStatic.stdenv.mkDerivation { name = "probe"; buildCommand = "echo | $CXX -x c++ -E -v - |& fgrep -B10 search; exit 1"; }' |& unnix

    #include "..." search starts here:
    #include <...> search starts here:
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/x86_64-unknown-linux-musl
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/backward
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include
     /<<NIX>>/musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include-fixed
    End of search list.
This commit is contained in:
Sergei Trofimovich 2023-03-06 07:46:25 +00:00
parent cb351f064e
commit 7df4387ebd

View File

@ -250,6 +250,17 @@ postInstall() {
done
fi
# Cross-compiler specific:
# --with-headers=$dir option triggers gcc to make a private copy
# of $dir headers and use it later as `-isysroot`. This prevents
# cc-wrapper from overriding libc headers with `-idirafter`.
# It should be safe to drop it and rely solely on the cc-wrapper.
local sysinc_dir=$out/${targetConfig+$targetConfig/}sys-include
if [ -d "$sysinc_dir" ]; then
chmod -R u+w "$out/${targetConfig+$targetConfig/}sys-include"
rm -rfv "$out/${targetConfig+$targetConfig/}sys-include"
fi
# Get rid of some "fixed" header files
rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux}