Skip to content

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

Merged
trofi merged 1 commit intoNixOS:stagingfrom
trofi:gcc-cross-no-sys-includes
Mar 11, 2023
Merged

gcc: do not install sys-include headers for cross-compilers.#219811
trofi merged 1 commit intoNixOS:stagingfrom
trofi:gcc-cross-no-sys-includes

Conversation

@trofi
Copy link
Contributor

@trofi trofi commented Mar 6, 2023

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.
Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

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.
@trofi trofi requested a review from matthewbauer as a code owner March 6, 2023 09:27
@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Mar 6, 2023
@ofborg ofborg bot added 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Mar 6, 2023
@trofi
Copy link
Contributor Author

trofi commented Mar 11, 2023

Lightly tested a few targets from x86_64-linux host:

  • pkgsCross.mingw64
  • pkgsCross.riscv64
  • pkgsCross.mmix
  • pkgsMusl
  • pkgsi686Linux
  • pkgsStatic

All seem to work.

@trofi trofi merged commit d65d457 into NixOS:staging Mar 11, 2023
@trofi trofi deleted the gcc-cross-no-sys-includes branch March 11, 2023 20:49
@alyssais
Copy link
Member

This change has broken pkgsStatic.netbsd.compat on staging-next, which is needed for fts, for example by glib.

@trofi
Copy link
Contributor Author

trofi commented Mar 17, 2023

Can reproduce locally as:

$ nix build -f. -L pkgsStatic.netbsd.compat
...
       > checking how to run the C preprocessor... x86_64-unknown-linux-musl-cpp
       > configure: error: in `/build/cvs-export/tools/compat':
       > configure: error: C preprocessor "x86_64-unknown-linux-musl-cpp" fails sanity check
       > See `config.log' for more details

I suspect we are using unwrapped version of cpp here and are missing standard -idirafter flags. It was previously masked by the default path. Looking to confirm.

@trofi
Copy link
Contributor Author

trofi commented Mar 17, 2023

Confirmed it's unwrapped:

bash-5.2$ dev>which x86_64-unknown-linux-musl-gcc
/nix/store/dskdlhryjxq1bdk8qsmjncc4z7ak79yn-x86_64-unknown-linux-musl-stage-final-gcc-wrapper-13.0.0/bin/x86_64-unknown-linux-musl-gcc

bash-5.2$ dev>which x86_64-unknown-linux-musl-cpp
/nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/bin/x86_64-unknown-linux-musl-cpp

And preoprocessor is validated against system headers without any extra include paths:

configure:3142: x86_64-unknown-linux-musl-cpp  conftest.c
In file included from /nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include/syslimits.h:7,
                 from /nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include/limits.h:34,
                 from conftest.c:10:
/nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include/limits.h:205:75: error: no include path in which to search for limits.h
  205 | #include_next <limits.h>                /* recurse down to the real one */
      |                                                                           ^
configure:3142: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libnbcompat"
| #define PACKAGE_TARNAME "libnbcompat"
| #define PACKAGE_VERSION "noversion"
| #define PACKAGE_STRING "libnbcompat noversion"
| #define PACKAGE_BUGREPORT "lib-bug-people@NetBSD.org"
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| #ifdef __STDC__
| # include <limits.h>
| #else
| # include <assert.h>
| #endif
|                    Syntax error
configure:3172: error: in `/home/slyfox/dev/git/nixpkgs/cvs-export/tools/compat':
configure:3174: error: C preprocessor "x86_64-unknown-linux-musl-cpp" fails sanity check
See `config.log' for more details

As a workaround you can try to pass CPP="$CC -E". Ideally we will need to wrap cpp as well.

If it's a wider spread breakage we'll need to roll the sys-include removal back and try again when more fixes are applied.

@trofi
Copy link
Contributor Author

trofi commented Mar 17, 2023

Proposed the cpp wrapping fix as #221677

@trofi
Copy link
Contributor Author

trofi commented Jul 26, 2023

Another regression manifested itself: #245455

Proposed the revert in #245550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: cross-compilation Building packages on a different platform than they will be used on 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants