Skip to content

Commit

Permalink
gcc: set up sysroot for the Darwin SDK
Browse files Browse the repository at this point in the history
The GCC bootstrap builds each stage with an unwrapped GCC, which needs
to correctly handle looking for libraries and headers in sysroot.
Setting the native header folder to `/usr/include` will actually cause
GCC to search `<sysroot>/usr/include`, which is the SDKROOT in nixpkgs.
  • Loading branch information
reckenrode committed Oct 10, 2024
1 parent a77d0eb commit e500744
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
, threadsCross
, version

, binutils, gmp, mpfr, libmpc, isl
, apple-sdk, binutils, gmp, mpfr, libmpc, isl

, enableLTO
, enableMultilib
Expand Down Expand Up @@ -112,7 +112,11 @@ let
]
++ lib.optionals (!withoutTargetLibc) [
(if libcCross == null
then "--with-native-system-header-dir=${lib.getDev stdenv.cc.libc}/include"
then (
# GCC will search for the headers relative to SDKROOT on Darwin, so it will find them in the store.
if targetPlatform.isDarwin then "--with-native-system-header-dir=/usr/include"
else "--with-native-system-header-dir=${lib.getDev stdenv.cc.libc}/include"
)
else "--with-native-system-header-dir=${lib.getDev libcCross}${libcCross.incdir or "/include"}")
# gcc builds for cross-compilers (build != host) or cross-built
# gcc (host != target) always apply the offset prefix to disentangle
Expand All @@ -132,7 +136,8 @@ let
#
# We pick "/" path to effectively avoid sysroot offset and make it work
# as a native case.
"--with-build-sysroot=/"
# Darwin requires using the SDK as the sysroot for `SDKROOT` to work correctly.
"--with-build-sysroot=${if targetPlatform.isDarwin then apple-sdk.sdkroot else "/"}"
# Same with the stdlibc++ headers embedded in the gcc output
"--with-gxx-include-dir=${placeholder "out"}/include/c++/${version}/"
]
Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/compilers/gcc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
, nukeReferences
, callPackage
, majorMinorVersion
, apple-sdk
, cctools
, darwin
}:
Expand Down Expand Up @@ -105,6 +106,7 @@ let
;
# inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc${majorVersion}.cc.override)" | jq '.[]' --raw-output'
inherit
apple-sdk
binutils
buildPackages
cargo
Expand Down

0 comments on commit e500744

Please sign in to comment.