From 7e096024d7cf0ea1ca2a0d0d79d33d3f3e4e9965 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Apr 2017 23:55:03 -0400 Subject: [PATCH 1/2] glibc: Fix for cross --- pkgs/development/libraries/glibc/common.nix | 17 +++++++++-------- pkgs/development/libraries/glibc/default.nix | 12 +++++++----- .../linux/make-bootstrap-tools-cross.nix | 2 +- pkgs/top-level/all-packages.nix | 19 ++++++++++++++----- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/pkgs/development/libraries/glibc/common.nix b/pkgs/development/libraries/glibc/common.nix index ec9f94d00d8..74fb0050109 100644 --- a/pkgs/development/libraries/glibc/common.nix +++ b/pkgs/development/libraries/glibc/common.nix @@ -4,17 +4,20 @@ cross: { name, fetchurl, lib, stdenv, installLocales ? false -, gccCross ? null, linuxHeaders ? null +, linuxHeaders ? null , profilingLibraries ? false, meta , withGd ? false, gd ? null, libpng ? null -, preConfigure ? "", ... }@args: +, preConfigure ? "" +, buildPackages ? {} +, ... +} @ args: let version = "2.25"; sha256 = "067bd9bb3390e79aa45911537d13c3721f1d9d3769931a30c2681bfee66f23a0"; in -assert cross != null -> gccCross != null; +assert cross != null -> buildPackages.stdenv ? cc; stdenv.mkDerivation ({ inherit linuxHeaders installLocales; @@ -113,8 +116,8 @@ stdenv.mkDerivation ({ outputs = [ "out" "bin" "dev" "static" ]; - buildInputs = lib.optionals (cross != null) [ gccCross ] - ++ lib.optionals withGd [ gd libpng ]; + nativeBuildInputs = lib.optional (cross != null) buildPackages.stdenv.cc; + buildInputs = lib.optionals withGd [ gd libpng ]; # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to # prevent a retained dependency on the bootstrap tools in the stdenv-linux @@ -122,9 +125,7 @@ stdenv.mkDerivation ({ BASH_SHELL = "/bin/sh"; } -# Remove the `gccCross' attribute so that the *native* glibc store path -# doesn't depend on whether `gccCross' is null or not. -// (removeAttrs args [ "lib" "gccCross" "fetchurl" "withGd" "gd" "libpng" ]) // +// (removeAttrs args [ "lib" "buildPackages" "fetchurl" "withGd" "gd" "libpng" ]) // { name = name + "-${version}" + diff --git a/pkgs/development/libraries/glibc/default.nix b/pkgs/development/libraries/glibc/default.nix index 4f9eb2d0714..7295e4d62f4 100644 --- a/pkgs/development/libraries/glibc/default.nix +++ b/pkgs/development/libraries/glibc/default.nix @@ -1,21 +1,23 @@ -{ lib, stdenv, fetchurl, linuxHeaders +{ lib, stdenv, fetchurl , installLocales ? true , profilingLibraries ? false -, gccCross ? null , withGd ? false, gd ? null, libpng ? null +, buildPlatform, hostPlatform +, buildPackages }: assert stdenv.cc.isGNU; let build = import ./common.nix; - cross = if gccCross != null then gccCross.target else null; + cross = if buildPlatform != hostPlatform then hostPlatform else null; + inherit (buildPackages) linuxHeaders; in build cross ({ name = "glibc" + lib.optionalString withGd "-gd"; - inherit lib stdenv fetchurl linuxHeaders installLocales - profilingLibraries gccCross withGd gd libpng; + inherit lib stdenv buildPackages fetchurl linuxHeaders installLocales + profilingLibraries withGd gd libpng; NIX_NO_SELF_RPATH = true; diff --git a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix index 77471e6dfdb..50fd563e7c2 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix @@ -92,7 +92,7 @@ let pkgs = pkgsFun ({inherit system;} // selectedCrossSystem); - glibc = pkgs.buildPackages.libcCross; + glibc = pkgs.libcCross; bash = pkgs.bash; findutils = pkgs.findutils; diffutils = pkgs.diffutils; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d2a171a732d..32c4f0f95c6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7700,7 +7700,6 @@ with pkgs; glibc = callPackage ../development/libraries/glibc { installLocales = config.glibc.locales or false; - gccCross = null; }; glibc_memusage = callPackage ../development/libraries/glibc { @@ -7708,13 +7707,23 @@ with pkgs; withGd = true; }; - glibcCross = forcedNativePackages.glibc.override { - gccCross = gccCrossStageStatic; - inherit (forcedNativePackages) linuxHeaders; + # Being redundant to avoid cycles on boot. TODO: find a better way + glibcCross = callPackage ../development/libraries/glibc { + installLocales = config.glibc.locales or false; + # Can't just overrideCC, because then the stdenv-cross mkDerivation will be + # thrown away. TODO: find a better solution for this. + stdenv = buildPackages.makeStdenvCross + buildPackages.buildPackages.stdenv + buildPackages.targetPlatform + buildPackages.binutils + buildPackages.gccCrossStageStatic; }; # We can choose: - libcCrossChooser = name: if name == "glibc" then glibcCross + libcCrossChooser = name: + # libc is hackily often used from the previous stage. This `or` + # hack fixes the hack, *sigh*. + /**/ if name == "glibc" then __targetPackages.glibcCross or glibcCross else if name == "uclibc" then uclibcCross else if name == "msvcrt" then windows.mingw_w64 else if name == "libSystem" then darwin.xcode From 25edc476fd9fe1bd8bedf571d218ba4f27fb5a27 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 18 May 2017 06:55:08 -0400 Subject: [PATCH 2/2] glibc: Simplify derivation further No native hashes should be changed with this commit default.nix's cross hash should also not be changed --- pkgs/development/libraries/glibc/common.nix | 62 ++++++++++++++++---- pkgs/development/libraries/glibc/default.nix | 52 ++-------------- pkgs/development/libraries/glibc/info.nix | 9 +-- pkgs/development/libraries/glibc/locales.nix | 9 ++- pkgs/top-level/release-cross.nix | 1 + 5 files changed, 62 insertions(+), 71 deletions(-) diff --git a/pkgs/development/libraries/glibc/common.nix b/pkgs/development/libraries/glibc/common.nix index 74fb0050109..db80a8be299 100644 --- a/pkgs/development/libraries/glibc/common.nix +++ b/pkgs/development/libraries/glibc/common.nix @@ -1,26 +1,34 @@ /* Build configuration used to build glibc, Info files, and locale information. */ -cross: +{ stdenv, lib, fetchurl +, gd ? null, libpng ? null +, buildPlatform, hostPlatform +, buildPackages +}: -{ name, fetchurl, lib, stdenv, installLocales ? false -, linuxHeaders ? null -, profilingLibraries ? false, meta -, withGd ? false, gd ? null, libpng ? null -, preConfigure ? "" -, buildPackages ? {} +{ name +, withLinuxHeaders ? false +, profilingLibraries ? false +, installLocales ? false +, withGd ? false +, meta , ... } @ args: let + inherit (buildPackages) linuxHeaders; version = "2.25"; sha256 = "067bd9bb3390e79aa45911537d13c3721f1d9d3769931a30c2681bfee66f23a0"; + cross = if buildPlatform != hostPlatform then hostPlatform else null; in -assert cross != null -> buildPackages.stdenv ? cc; +assert withLinuxHeaders -> linuxHeaders != null; +assert withGd -> gd != null && libpng != null; stdenv.mkDerivation ({ - inherit linuxHeaders installLocales; + inherit installLocales; + linuxHeaders = if withLinuxHeaders then linuxHeaders else null; # The host/target system. crossConfig = if cross != null then cross.config else null; @@ -87,13 +95,13 @@ stdenv.mkDerivation ({ "--enable-obsolete-rpc" "--sysconfdir=/etc" "--enable-stackguard-randomization" - (if linuxHeaders != null + (if withLinuxHeaders then "--with-headers=${linuxHeaders}/include" else "--without-headers") (if profilingLibraries then "--enable-profile" else "--disable-profile") - ] ++ lib.optionals (cross == null && linuxHeaders != null) [ + ] ++ lib.optionals (cross == null && withLinuxHeaders) [ "--enable-kernel=2.6.32" ] ++ lib.optionals (cross != null) [ (if cross.withTLS then "--with-tls" else "--without-tls") @@ -125,7 +133,7 @@ stdenv.mkDerivation ({ BASH_SHELL = "/bin/sh"; } -// (removeAttrs args [ "lib" "buildPackages" "fetchurl" "withGd" "gd" "libpng" ]) // +// (removeAttrs args [ "withLinuxHeaders" "withGd" ]) // { name = name + "-${version}" + @@ -154,7 +162,22 @@ stdenv.mkDerivation ({ ''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib"'' } - ${preConfigure} + + '' + lib.optionalString (cross != null) '' + sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig" + + cat > config.cache << "EOF" + libc_cv_forced_unwind=yes + libc_cv_c_cleanup=yes + libc_cv_gnu89_inline=yes + # Only due to a problem in gcc configure scripts: + libc_cv_sparc64_tls=${if cross.withTLS then "yes" else "no"} + EOF + + export BUILD_CC=gcc + export CC="$crossConfig-gcc" + export AR="$crossConfig-ar" + export RANLIB="$crossConfig-ranlib" ''; preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH"; @@ -177,4 +200,17 @@ stdenv.mkDerivation ({ maintainers = [ lib.maintainers.eelco ]; platforms = lib.platforms.linux; } // meta; +} + +// lib.optionalAttrs (cross != null) { + preInstall = null; # clobber the native hook + + dontStrip = true; + + separateDebugInfo = false; # this is currently broken for crossDrv + + # To avoid a dependency on the build system 'bash'. + preFixup = '' + rm $bin/bin/{ldd,tzselect,catchsegv,xtrace} + ''; }) diff --git a/pkgs/development/libraries/glibc/default.nix b/pkgs/development/libraries/glibc/default.nix index 7295e4d62f4..976dbcde47f 100644 --- a/pkgs/development/libraries/glibc/default.nix +++ b/pkgs/development/libraries/glibc/default.nix @@ -1,23 +1,16 @@ -{ lib, stdenv, fetchurl +{ stdenv, callPackage +, withLinuxHeaders ? true , installLocales ? true , profilingLibraries ? false -, withGd ? false, gd ? null, libpng ? null -, buildPlatform, hostPlatform -, buildPackages +, withGd ? false }: assert stdenv.cc.isGNU; -let - build = import ./common.nix; - cross = if buildPlatform != hostPlatform then hostPlatform else null; - inherit (buildPackages) linuxHeaders; -in - build cross ({ - name = "glibc" + lib.optionalString withGd "-gd"; +callPackage ./common.nix { inherit stdenv; } { + name = "glibc" + stdenv.lib.optionalString withGd "-gd"; - inherit lib stdenv buildPackages fetchurl linuxHeaders installLocales - profilingLibraries withGd gd libpng; + inherit withLinuxHeaders profilingLibraries installLocales withGd; NIX_NO_SELF_RPATH = true; @@ -106,36 +99,3 @@ in meta.description = "The GNU C Library"; } - - // - - (if cross != null - then { - preConfigure = '' - sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig" - - cat > config.cache << "EOF" - libc_cv_forced_unwind=yes - libc_cv_c_cleanup=yes - libc_cv_gnu89_inline=yes - # Only due to a problem in gcc configure scripts: - libc_cv_sparc64_tls=${if cross.withTLS then "yes" else "no"} - EOF - export BUILD_CC=gcc - export CC="$crossConfig-gcc" - export AR="$crossConfig-ar" - export RANLIB="$crossConfig-ranlib" - - dontStrip=1 - ''; - - preInstall = null; # clobber the native hook - - separateDebugInfo = false; # this is currently broken for crossDrv - - # To avoid a dependency on the build system 'bash'. - preFixup = '' - rm $bin/bin/{ldd,tzselect,catchsegv,xtrace} - ''; - } - else {})) diff --git a/pkgs/development/libraries/glibc/info.nix b/pkgs/development/libraries/glibc/info.nix index 84ec43e11a8..5cb004cc870 100644 --- a/pkgs/development/libraries/glibc/info.nix +++ b/pkgs/development/libraries/glibc/info.nix @@ -1,13 +1,8 @@ -{ lib, stdenv, fetchurl, texinfo, perl }: +{ callPackage, texinfo, perl }: -let build = import ./common.nix; in - -/* null cross builder */ -build null { +callPackage ./common.nix {} { name = "glibc-info"; - inherit fetchurl stdenv lib; - outputs = [ "out" ]; configureFlags = [ "--enable-add-ons" ]; diff --git a/pkgs/development/libraries/glibc/locales.nix b/pkgs/development/libraries/glibc/locales.nix index 994390cf829..bf077a0c12c 100644 --- a/pkgs/development/libraries/glibc/locales.nix +++ b/pkgs/development/libraries/glibc/locales.nix @@ -6,14 +6,13 @@ http://sourceware.org/cgi-bin/cvsweb.cgi/libc/localedata/SUPPORTED?cvsroot=glibc */ -{ lib, stdenv, fetchurl, writeText, allLocales ? true, locales ? ["en_US.UTF-8/UTF-8"] }: +{ stdenv, callPackage, writeText +, allLocales ? true, locales ? [ "en_US.UTF-8/UTF-8" ] +}: -let build = import ./common.nix; in - -build null { +callPackage ./common.nix { inherit stdenv; } { name = "glibc-locales"; - inherit fetchurl stdenv lib; installLocales = true; builder = ./locales-builder.sh; diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix index ad868531598..1e764ef0072 100644 --- a/pkgs/top-level/release-cross.nix +++ b/pkgs/top-level/release-cross.nix @@ -15,6 +15,7 @@ let common = { buildPackages.binutils = nativePlatforms; gmp = nativePlatforms; + libcCross = nativePlatforms; }; gnuCommon = lib.recursiveUpdate common {