Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc: fix build with new SDK pattern #346949

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions pkgs/development/compilers/gcc/common/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
let
forceLibgccToBuildCrtStuff =
import ./libgcc-buildstuff.nix { inherit lib stdenv; };

# todo(@reckenrode) Remove in staging. This is ugly, but it avoid unwanted rebuilds on Darwin and Linux.
enableDarwinFixesForStagingNext =
version:
stdenv.buildPlatform.isDarwin
&& stdenv.buildPlatform.isx86_64
&& lib.versionOlder version "10";
in

originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // {
Expand All @@ -27,20 +20,11 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // {

if test "$staticCompiler" = "1"; then
EXTRA_LDFLAGS="-static"
${
if enableDarwinFixesForStagingNext finalAttrs.version then
''
elif test "''${NIX_DONT_SET_RPATH-}" != "1"; then
EXTRA_LDFLAGS="-Wl,-rpath,''${!outputLib}/lib"
else
EXTRA_LDFLAGS=""
''
else
''
else
EXTRA_LDFLAGS="-Wl,-rpath,''${!outputLib}/lib"
''
}fi
elif test "''${NIX_DONT_SET_RPATH-}" != "1"; then
EXTRA_LDFLAGS="-Wl,-rpath,''${!outputLib}/lib"
else
EXTRA_LDFLAGS=""
fi

# GCC interprets empty paths as ".", which we don't want.
if test -z "''${CPATH-}"; then unset CPATH; fi
Expand Down Expand Up @@ -74,24 +58,14 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // {
extraLDFlags=("-L/usr/lib64" "-L/usr/lib")
libc_libdir="/usr/lib"
fi
${
if enableDarwinFixesForStagingNext finalAttrs.version then
''
extraLDFlags=("-L$libc_libdir")
nixDontSetRpathVar=NIX_DONT_SET_RPATH''${post}
if test "''${!nixDontSetRpathVar-}" != "1"; then
extraLDFlags+=("-rpath" "$libc_libdir")
fi
extraLDFlags+=("''${extraLDFlags[@]}")
''
else
''
extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir"
"''${extraLDFlags[@]}")
''
# The strange indentation with the next line is to ensure the string renders the same when the condition is false,
# which is necessary to prevent unwanted rebuilds in staging-next.
} for i in "''${extraLDFlags[@]}"; do
declare -a prefixExtraLDFlags=()
prefixExtraLDFlags=("-L$libc_libdir")
nixDontSetRpathVar=NIX_DONT_SET_RPATH''${post}
if test "''${!nixDontSetRpathVar-}" != "1"; then
prefixExtraLDFlags+=("-rpath" "$libc_libdir")
fi
extraLDFlags=("''${prefixExtraLDFlags[@]}" "''${extraLDFlags[@]}")
for i in "''${extraLDFlags[@]}"; do
declare -g EXTRA_LDFLAGS''${post}+=" -Wl,$i"
done
done
Expand Down
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
Loading