From 738bb4777cf08625adf22f50227377003598f7ad Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 21 Sep 2017 11:16:25 -0400 Subject: [PATCH 1/6] stdenv: Update autotools scripts on all Aarch64, not just Linux This is needed when cross-compiling for iOS (Aarch64 + Darwin). I also changed the syntax of the Linux stdenv for visual consistency, though that has no effect on semantics as the os is already guaranteed to be Linux. --- pkgs/stdenv/adapters.nix | 2 +- pkgs/stdenv/linux/default.nix | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index ac382927b1b9..07d1c245b49c 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -105,7 +105,7 @@ rec { # without proper `file` command, libtool sometimes fails # to recognize 64-bit DLLs ++ stdenv.lib.optional (hostPlatform.config == "x86_64-w64-mingw32") pkgs.file - ++ stdenv.lib.optional (hostPlatform.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook + ++ stdenv.lib.optional hostPlatform.isAarch64 pkgs.updateAutotoolsGnuConfigScriptsHook ; # Cross-linking dynamic libraries, every buildInput should diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index fab1985b9765..e79ec48e9f42 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -219,7 +219,7 @@ in }; extraNativeBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++ # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64. - lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; + lib.optional localSystem.isAarch64 prevStage.updateAutotoolsGnuConfigScriptsHook; }) @@ -251,7 +251,7 @@ in }; extraNativeBuildInputs = [ prevStage.patchelf prevStage.xz ] ++ # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64. - lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; + lib.optional localSystem.isAarch64 prevStage.updateAutotoolsGnuConfigScriptsHook; }) # Construct the final stdenv. It uses the Glibc and GCC, and adds @@ -281,7 +281,7 @@ in extraNativeBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++ # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64. - lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; + lib.optional localSystem.isAarch64 prevStage.updateAutotoolsGnuConfigScriptsHook; cc = prevStage.gcc; @@ -312,7 +312,7 @@ in glibc.out glibc.dev glibc.bin/*propagated from .dev*/ linuxHeaders gcc gcc.cc gcc.cc.lib gcc.expand-response-params ] - ++ lib.optionals (system == "aarch64-linux") + ++ lib.optionals localSystem.isAarch64 [ prevStage.updateAutotoolsGnuConfigScriptsHook prevStage.gnu-config ]; overrides = self: super: { From 05ef1034c7ebbe106ebd4615b06dcf421658c56c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 21 Sep 2017 14:52:07 -0400 Subject: [PATCH 2/6] stdenv cross adaptor: Add optional `overrides` parameter By default, all previous overrides are discarded as before, as they would only apply to the old host platform. But sometimes it is useful to add some new ones, and this optional parameter allows that. --- pkgs/stdenv/adapters.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 07d1c245b49c..b79ada60b3fd 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -59,17 +59,17 @@ rec { makeStdenvCross = { stdenv , cc , buildPlatform, hostPlatform, targetPlatform + , # Prior overrides are surely not valid as packages built + # with this run on a different platform, so disable by + # default. + overrides ? _: _: {} } @ overrideArgs: let stdenv = overrideArgs.stdenv.override { inherit buildPlatform hostPlatform targetPlatform - cc; + cc overrides; allowedRequisites = null; - - # Overrides are surely not valid as packages built with this run on a - # different platform. - overrides = _: _: {}; }; in stdenv // { mkDerivation = From 3af3d6efc23400613ef9301dfa67220b9e8ff647 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 21 Sep 2017 11:40:46 -0400 Subject: [PATCH 3/6] stdenv cross adapater: Remove old `extraBuildInputs` They, unlike their native counterparts, run on the wrong platform and are therefore invalid. --- pkgs/stdenv/adapters.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index b79ada60b3fd..25ee9adfd9d9 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -70,6 +70,7 @@ rec { cc overrides; allowedRequisites = null; + extraBuildInputs = [ ]; # Old ones run on wrong platform }; in stdenv // { mkDerivation = From 54282b9610e80b1ed93136319e24cb79c5bbcc33 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 20 Sep 2017 15:02:21 -0400 Subject: [PATCH 4/6] gcc: Change default of `crossStageStatic` param to false This gets us one step closer to removing `gccCrossStageFinal`. Care is taken to avoid a mass rebuild; will clean up with one later. --- pkgs/development/compilers/gcc/4.5/default.nix | 6 ++++-- pkgs/development/compilers/gcc/4.8/default.nix | 6 ++++-- pkgs/development/compilers/gcc/4.9/default.nix | 6 ++++-- pkgs/development/compilers/gcc/5/default.nix | 6 ++++-- pkgs/development/compilers/gcc/6/default.nix | 6 ++++-- pkgs/development/compilers/gcc/7/default.nix | 6 ++++-- pkgs/development/compilers/gcc/snapshot/default.nix | 6 ++++-- pkgs/top-level/all-packages.nix | 4 +--- 8 files changed, 29 insertions(+), 17 deletions(-) diff --git a/pkgs/development/compilers/gcc/4.5/default.nix b/pkgs/development/compilers/gcc/4.5/default.nix index bec2aab017ea..5bad03d30252 100644 --- a/pkgs/development/compilers/gcc/4.5/default.nix +++ b/pkgs/development/compilers/gcc/4.5/default.nix @@ -20,7 +20,7 @@ , enableMultilib ? false , name ? "gcc" , libcCross ? null -, crossStageStatic ? true +, crossStageStatic ? false , gnat ? null , libpthread ? null, libpthreadCross ? null # required for GNU/Hurd , stripped ? true @@ -213,7 +213,9 @@ stdenv.mkDerivation ({ '' else null; - inherit noSysDirs profiledCompiler staticCompiler langJava crossStageStatic + # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild, + crossStageStatic = targetPlatform == hostPlatform || crossStageStatic; + inherit noSysDirs profiledCompiler staticCompiler langJava libcCross crossMingw; nativeBuildInputs = [ texinfo which gettext ] diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 5b9d368c457b..72e37f18a178 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -26,7 +26,7 @@ , enablePlugin ? true # whether to support user-supplied plug-ins , name ? "gcc" , libcCross ? null -, crossStageStatic ? true +, crossStageStatic ? false , gnat ? null , libpthread ? null, libpthreadCross ? null # required for GNU/Hurd , stripped ? true @@ -284,7 +284,9 @@ stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild, + crossStageStatic = targetPlatform == hostPlatform || crossStageStatic; + inherit noSysDirs staticCompiler langJava libcCross crossMingw; nativeBuildInputs = [ texinfo which gettext ] diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 8990302eea2e..d7684a61a2ac 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -26,7 +26,7 @@ , enablePlugin ? true # whether to support user-supplied plug-ins , name ? "gcc" , libcCross ? null -, crossStageStatic ? true +, crossStageStatic ? false , gnat ? null , libpthread ? null, libpthreadCross ? null # required for GNU/Hurd , stripped ? true @@ -280,7 +280,9 @@ stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild, + crossStageStatic = targetPlatform == hostPlatform || crossStageStatic; + inherit noSysDirs staticCompiler langJava libcCross crossMingw; nativeBuildInputs = [ texinfo which gettext ] diff --git a/pkgs/development/compilers/gcc/5/default.nix b/pkgs/development/compilers/gcc/5/default.nix index f593e00ccfd4..c3e14d9328e4 100644 --- a/pkgs/development/compilers/gcc/5/default.nix +++ b/pkgs/development/compilers/gcc/5/default.nix @@ -26,7 +26,7 @@ , enablePlugin ? true # whether to support user-supplied plug-ins , name ? "gcc" , libcCross ? null -, crossStageStatic ? true +, crossStageStatic ? false , gnat ? null , libpthread ? null, libpthreadCross ? null # required for GNU/Hurd , stripped ? true @@ -299,7 +299,9 @@ stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild, + crossStageStatic = targetPlatform == hostPlatform || crossStageStatic; + inherit noSysDirs staticCompiler langJava libcCross crossMingw; nativeBuildInputs = [ texinfo which gettext ] diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 25940420e9a9..2c8a9696e693 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -26,7 +26,7 @@ , enablePlugin ? true # whether to support user-supplied plug-ins , name ? "gcc" , libcCross ? null -, crossStageStatic ? true +, crossStageStatic ? false , gnat ? null , libpthread ? null, libpthreadCross ? null # required for GNU/Hurd , stripped ? true @@ -292,7 +292,9 @@ stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild, + crossStageStatic = targetPlatform == hostPlatform || crossStageStatic; + inherit noSysDirs staticCompiler langJava libcCross crossMingw; nativeBuildInputs = [ texinfo which gettext ] diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 6dcd36eb3ea2..064f2ab00d47 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -26,7 +26,7 @@ , enablePlugin ? true # whether to support user-supplied plug-ins , name ? "gcc" , libcCross ? null -, crossStageStatic ? true +, crossStageStatic ? false , gnat ? null , libpthread ? null, libpthreadCross ? null # required for GNU/Hurd , stripped ? true @@ -294,7 +294,9 @@ stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild, + crossStageStatic = targetPlatform == hostPlatform || crossStageStatic; + inherit noSysDirs staticCompiler langJava libcCross crossMingw; nativeBuildInputs = [ texinfo which gettext ] diff --git a/pkgs/development/compilers/gcc/snapshot/default.nix b/pkgs/development/compilers/gcc/snapshot/default.nix index 46fcc53b3c46..696417a49566 100644 --- a/pkgs/development/compilers/gcc/snapshot/default.nix +++ b/pkgs/development/compilers/gcc/snapshot/default.nix @@ -26,7 +26,7 @@ , enablePlugin ? true # whether to support user-supplied plug-ins , name ? "gcc" , libcCross ? null -, crossStageStatic ? true +, crossStageStatic ? false , gnat ? null , libpthread ? null, libpthreadCross ? null # required for GNU/Hurd , stripped ? true @@ -281,7 +281,9 @@ stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # TODO(@Ericson2314): Make passthru instead. Weird to avoid mass rebuild, + crossStageStatic = targetPlatform == hostPlatform || crossStageStatic; + inherit noSysDirs staticCompiler langJava libcCross crossMingw; nativeBuildInputs = [ texinfo which gettext ] diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 60a3bc8394df..655d464e66c6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5451,9 +5451,7 @@ with pkgs; gccCrossStageFinal = assert targetPlatform != buildPlatform; wrapCCWith { name = "gcc-cross-wrapper"; - cc = gcc.cc.override { - crossStageStatic = false; - }; + cc = gcc.cc; libc = libcCross; }; From 88a0e55ce01867e3f8ba177bf128ed1f63376d92 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 20 Sep 2017 15:20:00 -0400 Subject: [PATCH 5/6] wrapCC: Alias now does the right thing for cross Unfortunately this makes previously-barely-working overrides have infinite recursion, so I had to reinstantiate gcc for gccCrossStageFinal instead. --- pkgs/top-level/all-packages.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 655d464e66c6..73d65d4ad085 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5377,6 +5377,7 @@ with pkgs; gambit = callPackage ../development/compilers/gambit { }; gerbil = callPackage ../development/compilers/gerbil { }; + gccFun = callPackage ../development/compilers/gcc/6; gcc = gcc6; gcc-unwrapped = gcc.cc; @@ -5432,12 +5433,18 @@ with pkgs; else null; in wrapCCWith { name = "gcc-cross-wrapper"; - cc = gcc.cc.override { + cc = gccFun { + # copy-pasted + inherit noSysDirs; + # PGO seems to speed up compilation by gcc by ~10%, see #445 discussion + profiledCompiler = with stdenv; (!isDarwin && (isi686 || isx86_64)); + isl = if !stdenv.isDarwin then isl_0_14 else null; + + # just for stage static crossStageStatic = true; langCC = false; libcCross = libcCross1; enableShared = false; - # Why is this needed? }; libc = libcCross1; }; @@ -6220,7 +6227,7 @@ with pkgs; wrapCC = cc: wrapCCWith { inherit cc; - inherit (stdenv.cc) libc; + libc = if targetPlatform != hostPlatform then libcCross else stdenv.cc.libc; }; # legacy version, used for gnat bootstrapping wrapGCC-old = baseGCC: callPackage ../build-support/gcc-wrapper-old { From b9bf90ca6c7d980c9ff34d67fb3950c47b6be6b8 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 20 Sep 2017 15:31:07 -0400 Subject: [PATCH 6/6] all-packages: Remove gccCrossStageFinal; any gcc will not work --- pkgs/os-specific/gnu/default.nix | 4 ++-- pkgs/stdenv/cross/default.nix | 2 +- pkgs/top-level/all-packages.nix | 9 +++------ pkgs/top-level/release-cross.nix | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pkgs/os-specific/gnu/default.nix b/pkgs/os-specific/gnu/default.nix index fb3796394e81..478040132b82 100644 --- a/pkgs/os-specific/gnu/default.nix +++ b/pkgs/os-specific/gnu/default.nix @@ -2,7 +2,7 @@ args@{ fetchgit, stdenv, autoconf, automake, automake111x, libtool , texinfo, glibcCross, hurdPartedCross, libuuid, samba -, gccCrossStageStatic, gccCrossStageFinal +, gccCrossStageStatic, gcc , forceSystem, newScope, platform, config , targetPlatform, buildPlatform , overrides ? {} @@ -28,7 +28,7 @@ let automake = automake111x; headersOnly = false; cross = assert targetPlatform != buildPlatform; targetPlatform; - gccCross = gccCrossStageFinal; + gccCross = gcc; }; hurdCrossIntermediate = forcedNativePackages.callPackage ./hurd { diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index c83714d01f2c..8197510eeecc 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -35,7 +35,7 @@ in bootStages ++ [ targetPlatform = crossSystem; cc = if crossSystem.useiOSCross or false then buildPackages.darwin.ios-cross - else buildPackages.gccCrossStageFinal; + else buildPackages.gcc; }; }) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 73d65d4ad085..860567283b86 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5426,6 +5426,8 @@ with pkgs; cc = buildPackages.gccCrossStageStatic; }; + # The GCC used to build libc for the target platform. Normal gccs will be + # built with, and use, that cross-compiled libc. gccCrossStageStatic = assert targetPlatform != buildPlatform; let libcCross1 = if targetPlatform.libc == "msvcrt" then __targetPackages.windows.mingw_w64_headers @@ -5456,12 +5458,6 @@ with pkgs; libc = windows.mingw_headers2; }; - gccCrossStageFinal = assert targetPlatform != buildPlatform; wrapCCWith { - name = "gcc-cross-wrapper"; - cc = gcc.cc; - libc = libcCross; - }; - gcc45 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/4.5 { inherit noSysDirs; texinfo = texinfo4; @@ -6226,6 +6222,7 @@ with pkgs; ccWrapperFun = callPackage ../build-support/cc-wrapper; wrapCC = cc: wrapCCWith { + name = lib.optionalString (targetPlatform != hostPlatform) "gcc-cross-wrapper"; inherit cc; libc = if targetPlatform != hostPlatform then libcCross else stdenv.cc.libc; }; diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix index 94c1e6c7ad2e..62f7134616bf 100644 --- a/pkgs/top-level/release-cross.nix +++ b/pkgs/top-level/release-cross.nix @@ -19,7 +19,7 @@ let }; gnuCommon = lib.recursiveUpdate common { - buildPackages.gccCrossStageFinal = nativePlatforms; + buildPackages.gcc = nativePlatforms; coreutils = nativePlatforms; };