diff options
author | Adam Joseph <adam@westernsemico.com> | 2023-06-27 18:43:42 -0700 |
---|---|---|
committer | Adam Joseph <adam@westernsemico.com> | 2023-07-01 13:12:41 -0700 |
commit | 63305d00d32e8c743e36155a7d8cd544dc676d5b (patch) | |
tree | dce3f1a79070be6900f803f9ac215fb6436c7c7f | |
parent | 443dfc4b05360794aa0304459177557107274559 (diff) |
gcc: withoutTargetLibc: build libgcc_s.so
We want a `libgcc_s.so` to be built by the first stage cross-compiler (withoutTargetLibc), since that is the compiler which will compile the target libc. This commit accomplishes that, by making three changes: 1. Replacing the `targetPlatform.libc == "msvcrt" &&` conditional with `enableShared`, so that the code which cross-build `libgcc_s.so` is used for all cross compilers capable of emitting shared libraries. 2. Removing the `targetPlatform == hostPlatform` guard from the code which produces the `libgcc` output. 3. Looking for build products in in "lib/${targetPlatform.config}/" rather than "lib/", so we will find them when cross compiling.
-rw-r--r-- | pkgs/development/compilers/gcc/10/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/11/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/12/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/13/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/4.8/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/4.9/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/6/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/7/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/8/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/9/default.nix | 2 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/common/configure-flags.nix | 1 | ||||
-rw-r--r-- | pkgs/development/compilers/gcc/common/libgcc.nix | 23 |
12 files changed, 27 insertions, 17 deletions
diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index 9f49cc2b91f5c..c61093c67c03a 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -295,5 +295,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index c64fd0853f9af..f61e51e2cabe3 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -307,6 +307,6 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) (callPackage ../common/checksum.nix { inherit langC langCC; }) ] diff --git a/pkgs/development/compilers/gcc/12/default.nix b/pkgs/development/compilers/gcc/12/default.nix index bb48446c84770..9665c2a9fe85b 100644 --- a/pkgs/development/compilers/gcc/12/default.nix +++ b/pkgs/development/compilers/gcc/12/default.nix @@ -353,7 +353,7 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) (callPackage ../common/checksum.nix { inherit langC langCC; }) ] diff --git a/pkgs/development/compilers/gcc/13/default.nix b/pkgs/development/compilers/gcc/13/default.nix index 19bb07669e5c6..1b73c251ce6f8 100644 --- a/pkgs/development/compilers/gcc/13/default.nix +++ b/pkgs/development/compilers/gcc/13/default.nix @@ -347,7 +347,7 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) (callPackage ../common/checksum.nix { inherit langC langCC; }) ] diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 6a40bd753a3b8..fa856eff96e5f 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -323,5 +323,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 41df57ffd4c1d..bab79f968db38 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -350,5 +350,5 @@ lib.pipe (stdenv.mkDerivation ({ '';} )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 1c1f4ae6cb314..f443babb4b706 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -368,5 +368,5 @@ lib.pipe (stdenv.mkDerivation ({ '';} )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index de6ccbb2efd8d..5b6ea7ead50a5 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -302,5 +302,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index da4b179100809..f903e264b0af6 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -277,5 +277,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 2d4e8a7524a8e..289212a136356 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -292,5 +292,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } ) ) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index f395f9e0960ef..a60a3380ea259 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -66,6 +66,7 @@ let "--disable-threads" "--disable-libgomp" "--disable-libquadmath" + (lib.enableFeature enableShared "shared") "--disable-libatomic" # requires libc "--disable-decimal-float" # requires libc "--disable-libmpx" # requires libc diff --git a/pkgs/development/compilers/gcc/common/libgcc.nix b/pkgs/development/compilers/gcc/common/libgcc.nix index 19def2cbc4e6b..528d9d7d13ac7 100644 --- a/pkgs/development/compilers/gcc/common/libgcc.nix +++ b/pkgs/development/compilers/gcc/common/libgcc.nix @@ -4,6 +4,7 @@ , langC , langCC , langJit +, enableShared , targetPlatform , hostPlatform , withoutTargetLibc @@ -18,7 +19,7 @@ drv: lib.pipe drv (pkg: pkg.overrideAttrs (previousAttrs: lib.optionalAttrs ( targetPlatform != hostPlatform && - targetPlatform.libc == "msvcrt" && + enableShared && withoutTargetLibc ) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; @@ -33,11 +34,15 @@ drv: lib.pipe drv lib.optional (lib.versionAtLeast version "11.0") (let + targetPlatformSlash = + if hostPlatform.config == targetPlatform.config + then "" + else "${targetPlatform.config}/"; + enableLibGccOutput = - (with stdenv; targetPlatform == hostPlatform) && !langJit && !stdenv.hostPlatform.isDarwin && - !stdenv.hostPlatform.isStatic + enableShared ; in @@ -52,6 +57,10 @@ in lib.optionalString (!langC) '' rm -f $out/lib/libgcc_s.so* '' + + lib.optionalString (hostPlatform.config != targetPlatform.config) '' + mkdir -p $lib/lib/ + ln -s ${targetPlatformSlash}lib $lib/lib + '' # TODO(amjoseph): remove the `libgcc_s.so` symlinks below and replace them # with a `-L${gccForLibs.libgcc}/lib` in cc-wrapper's @@ -64,10 +73,10 @@ in + lib.optionalString enableLibGccOutput ('' # move libgcc from lib to its own output (libgcc) mkdir -p $libgcc/lib - mv $lib/lib/libgcc_s.so $libgcc/lib/ - mv $lib/lib/libgcc_s.so.1 $libgcc/lib/ - ln -s $libgcc/lib/libgcc_s.so $lib/lib/ - ln -s $libgcc/lib/libgcc_s.so.1 $lib/lib/ + mv $lib/${targetPlatformSlash}lib/libgcc_s.so $libgcc/lib/ + mv $lib/${targetPlatformSlash}lib/libgcc_s.so.1 $libgcc/lib/ + ln -s $libgcc/lib/libgcc_s.so $lib/${targetPlatformSlash}lib/ + ln -s $libgcc/lib/libgcc_s.so.1 $lib/${targetPlatformSlash}lib/ '' # # Nixpkgs ordinarily turns dynamic linking into pseudo-static linking: |