Skip to content
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
11 changes: 8 additions & 3 deletions pkgs/development/compilers/gcc/all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ let
inherit majorMinorVersion;
reproducibleBuild = true;
profiledCompiler = false;
libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then args.libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross else { };
libcCross =
if !lib.systems.equals stdenv.targetPlatform stdenv.buildPlatform then args.libcCross else null;
threadsCross =
if !lib.systems.equals stdenv.targetPlatform stdenv.buildPlatform then threadsCross else { };
isl = if stdenv.hostPlatform.isDarwin then null else isl_0_20;
# do not allow version skew when cross-building gcc
#
Expand All @@ -49,7 +51,10 @@ let
# cross-case.
stdenv =
if
(stdenv.targetPlatform != stdenv.buildPlatform || stdenv.hostPlatform != stdenv.targetPlatform)
(
(!lib.systems.equals stdenv.targetPlatform stdenv.buildPlatform)
|| (!lib.systems.equals stdenv.hostPlatform stdenv.targetPlatform)
)
&& stdenv.cc.isGNU
then
pkgs."gcc${majorVersion}Stdenv"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/common/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

let
forceLibgccToBuildCrtStuff = import ./libgcc-buildstuff.nix { inherit lib stdenv; };
isCross = with stdenv; targetPlatform.config != hostPlatform.config;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These really should be lib.systems.equals, all of them, now that I think about it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just those three or everything in gcc? A quick git grep 'Platform *[!=]=' | wc -l inside pkgs/development/compilers/gcc gives me 40 hits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, all of them in nixpkgs, technically...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I don't want to let this single line change scope creep into doing a treewide update.
I've replaced things inside gcc, a simple rebuild of nix-build -A gcc was a no-op, but I'm not sure how to test this properly.

isCross = ! lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform;
in

# We don't support multilib and cross at the same time
Expand Down
5 changes: 4 additions & 1 deletion pkgs/development/compilers/gcc/common/checksum.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

let
enableChecksum =
(with stdenv; buildPlatform == hostPlatform && hostPlatform == targetPlatform)
(
with stdenv;
lib.systems.equals buildPlatform hostPlatform && lib.systems.equals hostPlatform targetPlatform
)
&& langC
&& langCC
&& !stdenv.hostPlatform.isDarwin;
Expand Down
16 changes: 8 additions & 8 deletions pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
, langObjCpp
, langJit
, langRust ? false
, disableBootstrap ? stdenv.targetPlatform != stdenv.hostPlatform
, disableBootstrap ? (! lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform)
}:

assert !enablePlugin -> disableGdbPlugin;
Expand All @@ -45,10 +45,10 @@ let
# See https://github.com/NixOS/nixpkgs/pull/209870#issuecomment-1500550903
disableBootstrap' = disableBootstrap && !langFortran && !langGo;

crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW;
crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
crossMingw = (! lib.systems.equals targetPlatform hostPlatform) && targetPlatform.isMinGW;
crossDarwin = (! lib.systems.equals targetPlatform hostPlatform) && targetPlatform.libc == "libSystem";

targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
targetPrefix = lib.optionalString (! lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform)
"${stdenv.targetPlatform.config}-";

crossConfigureFlags =
Expand Down Expand Up @@ -201,16 +201,16 @@ let

# Ada options, gcc can't build the runtime library for a cross compiler
++ lib.optional langAda
(if hostPlatform == targetPlatform
(if lib.systems.equals hostPlatform targetPlatform
then "--enable-libada"
else "--disable-libada")

++ import ../common/platform-flags.nix { inherit (stdenv) targetPlatform; inherit lib; }
++ lib.optionals (targetPlatform != hostPlatform) crossConfigureFlags
++ lib.optionals (! lib.systems.equals targetPlatform hostPlatform) crossConfigureFlags
++ lib.optional disableBootstrap' "--disable-bootstrap"

# Platform-specific flags
++ lib.optional (targetPlatform == hostPlatform && targetPlatform.isx86_32) "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
++ lib.optional (lib.systems.equals targetPlatform hostPlatform && targetPlatform.isx86_32) "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
++ lib.optional targetPlatform.isNetBSD "--disable-libssp" # Provided by libc.
++ lib.optionals hostPlatform.isSunOS [
"--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit"
Expand All @@ -220,7 +220,7 @@ let
++ lib.optional (targetPlatform.libc == "musl")
# musl at least, disable: https://git.buildroot.net/buildroot/commit/?id=873d4019f7fb00f6a80592224236b3ba7d657865
"--disable-libmpx"
++ lib.optionals (targetPlatform == hostPlatform && targetPlatform.libc == "musl") [
++ lib.optionals (lib.systems.equals targetPlatform hostPlatform && targetPlatform.libc == "musl") [
"--disable-libsanitizer"
"--disable-symvers"
"libat_cv_have_ifunc=no"
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/compilers/gcc/common/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ in
# same for all gcc's
depsBuildTarget =
(
if hostPlatform == buildPlatform then
if lib.systems.equals hostPlatform buildPlatform then
[
targetPackages.stdenv.cc.bintools # newly-built gcc will be used
]
else
assert targetPlatform == hostPlatform;
assert lib.systems.equals targetPlatform hostPlatform;
[
# build != host == target
stdenv.cc
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/compilers/gcc/common/extra-target-flags.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ in
let
mkFlags =
dep: langD:
lib.optionals (targetPlatform != hostPlatform && dep != null && !langD) (
lib.optionals ((!lib.systems.equals targetPlatform hostPlatform) && dep != null && !langD) (
[
"-O2 -idirafter ${lib.getDev dep}${dep.incdir or "/include"}"
]
Expand All @@ -35,7 +35,7 @@ in
let
mkFlags =
dep:
lib.optionals (targetPlatform != hostPlatform && dep != null) (
lib.optionals ((!lib.systems.equals targetPlatform hostPlatform) && dep != null) (
[
"-Wl,-L${lib.getLib dep}${dep.libdir or "/lib"}"
]
Expand Down
11 changes: 8 additions & 3 deletions pkgs/development/compilers/gcc/common/libgcc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ lib.pipe drv
pkg.overrideAttrs (
previousAttrs:
lib.optionalAttrs
(targetPlatform != hostPlatform && (enableShared || targetPlatform.isMinGW) && withoutTargetLibc)
(
(!lib.systems.equals targetPlatform hostPlatform)
&& (enableShared || targetPlatform.isMinGW)
&& withoutTargetLibc
)
{
makeFlags = [
"all-gcc"
Expand All @@ -46,7 +50,8 @@ lib.pipe drv

(
let
targetPlatformSlash = if hostPlatform == targetPlatform then "" else "${targetPlatform.config}/";
targetPlatformSlash =
if lib.systems.equals hostPlatform targetPlatform then "" else "${targetPlatform.config}/";

# If we are building a cross-compiler and the target libc provided
# to us at build time has a libgcc, use that instead of building a
Expand All @@ -55,7 +60,7 @@ lib.pipe drv
useLibgccFromTargetLibc = libcCross != null && libcCross ? passthru.libgcc;

enableLibGccOutput =
(!stdenv.targetPlatform.isWindows || (with stdenv; targetPlatform == hostPlatform))
(!stdenv.targetPlatform.isWindows || (lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform))
&& !langJit
&& !stdenv.hostPlatform.isDarwin
&& enableShared
Expand Down
23 changes: 16 additions & 7 deletions pkgs/development/compilers/gcc/common/pre-configure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) ''
# meet that need: it runs on the hostPlatform.
+
lib.optionalString
(langFortran && (with stdenv; buildPlatform != hostPlatform && hostPlatform == targetPlatform))
(
langFortran
&& (
with stdenv;
(!lib.systems.equals buildPlatform hostPlatform) && (lib.systems.equals hostPlatform targetPlatform)
)
)
''
export GFORTRAN_FOR_TARGET=${pkgsBuildTarget.gfortran}/bin/${stdenv.targetPlatform.config}-gfortran
''
Expand All @@ -52,25 +58,28 @@ lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) ''
# actually different we need to convince the configure script that it
# is in fact building a cross compiler although it doesn't believe it.
+
lib.optionalString (targetPlatform.config == hostPlatform.config && targetPlatform != hostPlatform)
lib.optionalString
(targetPlatform.config == hostPlatform.config && (!lib.systems.equals targetPlatform hostPlatform))
''
substituteInPlace configure --replace is_cross_compiler=no is_cross_compiler=yes
''

# Normally (for host != target case) --without-headers automatically
# enables 'inhibit_libc=true' in gcc's gcc/configure.ac. But case of
# gcc->clang or dynamic->static "cross"-compilation manages to evade it: there
# hostPlatform != targetPlatform, hostPlatform.config == targetPlatform.config.
# ! lib.systems.equals hostPlatform targetPlatform, hostPlatform.config == targetPlatform.config.
# We explicitly inhibit libc headers use in this case as well.
+
lib.optionalString
(
targetPlatform != hostPlatform && withoutTargetLibc && targetPlatform.config == hostPlatform.config
(!lib.systems.equals targetPlatform hostPlatform)
&& withoutTargetLibc
&& targetPlatform.config == hostPlatform.config
)
''
export inhibit_libc=true
''

+ lib.optionalString (targetPlatform != hostPlatform && withoutTargetLibc && enableShared) (
import ./libgcc-buildstuff.nix { inherit lib stdenv; }
)
+ lib.optionalString (
(!lib.systems.equals targetPlatform hostPlatform) && withoutTargetLibc && enableShared
) (import ./libgcc-buildstuff.nix { inherit lib stdenv; })
22 changes: 11 additions & 11 deletions pkgs/development/compilers/gcc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
, libucontext ? null
, gnat-bootstrap ? null
, enableMultilib ? false
, enablePlugin ? stdenv.hostPlatform == stdenv.buildPlatform # Whether to support user-supplied plug-ins
, enablePlugin ? (lib.systems.equals stdenv.hostPlatform stdenv.buildPlatform) # Whether to support user-supplied plug-ins
, name ? "gcc"
, libcCross ? null
, threadsCross ? null # for MinGW
Expand Down Expand Up @@ -77,14 +77,14 @@ let
disableBootstrap = atLeast11 && !stdenv.hostPlatform.isDarwin && (atLeast12 -> !profiledCompiler);

inherit (stdenv) buildPlatform hostPlatform targetPlatform;
targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
targetConfig = if (! lib.systems.equals targetPlatform hostPlatform) then targetPlatform.config else null;

patches = callFile ./patches {};

/* Cross-gcc settings (build == host != target) */
crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW;
crossMingw = (! lib.systems.equals targetPlatform hostPlatform) && targetPlatform.isMinGW;
stageNameAddon = optionalString withoutTargetLibc "-nolibc";
crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}${stageNameAddon}-";
crossNameAddon = optionalString (! lib.systems.equals targetPlatform hostPlatform) "${targetPlatform.config}${stageNameAddon}-";

callFile = callPackageWith {
# lets
Expand Down Expand Up @@ -244,7 +244,7 @@ pipe ((callFile ./common/builder.nix {}) ({
--replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname"
''
+ (
optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null)
optionalString ((! lib.systems.equals targetPlatform hostPlatform) || stdenv.cc.libc != null)
# On NixOS, use the right path to the dynamic linker instead of
# `/lib/ld*.so'.
(let
Expand Down Expand Up @@ -296,11 +296,11 @@ pipe ((callFile ./common/builder.nix {}) ({
if atLeast11
then let target =
optionalString (profiledCompiler) "profiled" +
optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap";
optionalString ((lib.systems.equals targetPlatform hostPlatform) && (lib.systems.equals hostPlatform buildPlatform) && !disableBootstrap) "bootstrap";
in optional (target != "") target
else
optional
(targetPlatform == hostPlatform && hostPlatform == buildPlatform)
((lib.systems.equals targetPlatform hostPlatform) && (lib.systems.equals hostPlatform buildPlatform))
(if profiledCompiler then "profiledbootstrap" else "bootstrap");

inherit (callFile ./common/strip-attributes.nix { })
Expand Down Expand Up @@ -328,11 +328,11 @@ pipe ((callFile ./common/builder.nix {}) ({
# compiler (after the specs for the cross-gcc are created). Having
# LIBRARY_PATH= makes gcc read the specs from ., and the build breaks.

CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([]
CPATH = optionals (lib.systems.equals targetPlatform hostPlatform) (makeSearchPathOutput "dev" "include" ([]
++ optional (zlib != null) zlib
));

LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath (
LIBRARY_PATH = optionals (lib.systems.equals targetPlatform hostPlatform) (makeLibraryPath (
optional (zlib != null) zlib
));

Expand All @@ -342,7 +342,7 @@ pipe ((callFile ./common/builder.nix {}) ({
EXTRA_FLAGS_FOR_TARGET
EXTRA_LDFLAGS_FOR_TARGET
;
} // optionalAttrs (!atLeast12 && stdenv.cc.isClang && targetPlatform != hostPlatform) {
} // optionalAttrs (!atLeast12 && stdenv.cc.isClang && (! lib.systems.equals targetPlatform hostPlatform)) {
NIX_CFLAGS_COMPILE = "-Wno-register";
});

Expand Down Expand Up @@ -376,7 +376,7 @@ pipe ((callFile ./common/builder.nix {}) ({
} // optionalAttrs (!atLeast11) {
badPlatforms = [ "aarch64-darwin" ];
} // optionalAttrs is10 {
badPlatforms = if targetPlatform != hostPlatform then [ "aarch64-darwin" ] else [ ];
badPlatforms = if (! lib.systems.equals targetPlatform hostPlatform) then [ "aarch64-darwin" ] else [ ];
};
} // optionalAttrs (!atLeast10 && stdenv.targetPlatform.isDarwin) {
# GCC <10 requires default cctools `strip` instead of `llvm-strip` used by Darwin bintools.
Expand Down
13 changes: 9 additions & 4 deletions pkgs/development/compilers/gcc/patches/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ let
canApplyIainsDarwinPatches =
stdenv.hostPlatform.isDarwin
&& stdenv.hostPlatform.isAarch64
&& buildPlatform == hostPlatform
&& hostPlatform == targetPlatform;
&& (lib.systems.equals buildPlatform hostPlatform)
&& (lib.systems.equals hostPlatform targetPlatform);

inherit (lib) optionals optional;
in
Expand All @@ -62,7 +62,7 @@ in

[ ]
++ optional (!atLeast12) ./fix-bug-80431.patch
++ optional (targetPlatform != hostPlatform) ./libstdc++-target.patch
++ optional (!lib.systems.equals targetPlatform hostPlatform) ./libstdc++-target.patch
++ optionals (noSysDirs) (
[ (if atLeast12 then ./gcc-12-no-sys-dirs.patch else ./no-sys-dirs.patch) ]
++ (
Expand Down Expand Up @@ -255,7 +255,12 @@ in

++ optional (langAda && (is9 || is10)) ./gnat-cflags.patch
++
optional (is10 && buildPlatform.system == "aarch64-darwin" && targetPlatform != buildPlatform)
optional
(
is10
&& buildPlatform.system == "aarch64-darwin"
&& (!lib.systems.equals targetPlatform buildPlatform)
)
(fetchpatch {
url = "https://raw.githubusercontent.com/richard-vd/musl-cross-make/5e9e87f06fc3220e102c29d3413fbbffa456fcd6/patches/gcc-${version}/0008-darwin-aarch64-self-host-driver.patch";
sha256 = "sha256-XtykrPd5h/tsnjY1wGjzSOJ+AyyNLsfnjuOZ5Ryq9vA=";
Expand Down