gcc: fix build with new SDK pattern (#346949)
This commit is contained in:
@@ -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 // {
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
, threadsCross
|
||||
, version
|
||||
|
||||
, binutils, gmp, mpfr, libmpc, isl
|
||||
, apple-sdk, binutils, gmp, mpfr, libmpc, isl
|
||||
|
||||
, enableLTO
|
||||
, enableMultilib
|
||||
@@ -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
|
||||
@@ -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}/"
|
||||
]
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
, nukeReferences
|
||||
, callPackage
|
||||
, majorMinorVersion
|
||||
, apple-sdk
|
||||
, cctools
|
||||
, darwin
|
||||
}:
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user