Merge pull request #25897 from obsidiansystems/glibc-cross

glibc: Clean up cross compilation
This commit is contained in:
John Ericson 2017-05-20 22:26:15 -04:00 committed by GitHub
commit bb37fc90c7
7 changed files with 81 additions and 78 deletions

View File

@ -1,23 +1,34 @@
/* Build configuration used to build glibc, Info files, and locale /* Build configuration used to build glibc, Info files, and locale
information. */ information. */
cross: { stdenv, lib, fetchurl
, gd ? null, libpng ? null
, buildPlatform, hostPlatform
, buildPackages
}:
{ name, fetchurl, lib, stdenv, installLocales ? false { name
, gccCross ? null, linuxHeaders ? null , withLinuxHeaders ? false
, profilingLibraries ? false, meta , profilingLibraries ? false
, withGd ? false, gd ? null, libpng ? null , installLocales ? false
, preConfigure ? "", ... }@args: , withGd ? false
, meta
, ...
} @ args:
let let
inherit (buildPackages) linuxHeaders;
version = "2.25"; version = "2.25";
sha256 = "067bd9bb3390e79aa45911537d13c3721f1d9d3769931a30c2681bfee66f23a0"; sha256 = "067bd9bb3390e79aa45911537d13c3721f1d9d3769931a30c2681bfee66f23a0";
cross = if buildPlatform != hostPlatform then hostPlatform else null;
in in
assert cross != null -> gccCross != null; assert withLinuxHeaders -> linuxHeaders != null;
assert withGd -> gd != null && libpng != null;
stdenv.mkDerivation ({ stdenv.mkDerivation ({
inherit linuxHeaders installLocales; inherit installLocales;
linuxHeaders = if withLinuxHeaders then linuxHeaders else null;
# The host/target system. # The host/target system.
crossConfig = if cross != null then cross.config else null; crossConfig = if cross != null then cross.config else null;
@ -84,13 +95,13 @@ stdenv.mkDerivation ({
"--enable-obsolete-rpc" "--enable-obsolete-rpc"
"--sysconfdir=/etc" "--sysconfdir=/etc"
"--enable-stackguard-randomization" "--enable-stackguard-randomization"
(if linuxHeaders != null (if withLinuxHeaders
then "--with-headers=${linuxHeaders}/include" then "--with-headers=${linuxHeaders}/include"
else "--without-headers") else "--without-headers")
(if profilingLibraries (if profilingLibraries
then "--enable-profile" then "--enable-profile"
else "--disable-profile") else "--disable-profile")
] ++ lib.optionals (cross == null && linuxHeaders != null) [ ] ++ lib.optionals (cross == null && withLinuxHeaders) [
"--enable-kernel=2.6.32" "--enable-kernel=2.6.32"
] ++ lib.optionals (cross != null) [ ] ++ lib.optionals (cross != null) [
(if cross.withTLS then "--with-tls" else "--without-tls") (if cross.withTLS then "--with-tls" else "--without-tls")
@ -113,8 +124,8 @@ stdenv.mkDerivation ({
outputs = [ "out" "bin" "dev" "static" ]; outputs = [ "out" "bin" "dev" "static" ];
buildInputs = lib.optionals (cross != null) [ gccCross ] nativeBuildInputs = lib.optional (cross != null) buildPackages.stdenv.cc;
++ lib.optionals withGd [ gd libpng ]; buildInputs = lib.optionals withGd [ gd libpng ];
# Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to # 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 # prevent a retained dependency on the bootstrap tools in the stdenv-linux
@ -122,9 +133,7 @@ stdenv.mkDerivation ({
BASH_SHELL = "/bin/sh"; BASH_SHELL = "/bin/sh";
} }
# Remove the `gccCross' attribute so that the *native* glibc store path // (removeAttrs args [ "withLinuxHeaders" "withGd" ]) //
# doesn't depend on whether `gccCross' is null or not.
// (removeAttrs args [ "lib" "gccCross" "fetchurl" "withGd" "gd" "libpng" ]) //
{ {
name = name + "-${version}" + name = name + "-${version}" +
@ -153,7 +162,22 @@ stdenv.mkDerivation ({
''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib"'' ''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"; preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH";
@ -176,4 +200,17 @@ stdenv.mkDerivation ({
maintainers = [ lib.maintainers.eelco ]; maintainers = [ lib.maintainers.eelco ];
platforms = lib.platforms.linux; platforms = lib.platforms.linux;
} // meta; } // 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}
'';
}) })

View File

@ -1,21 +1,16 @@
{ lib, stdenv, fetchurl, linuxHeaders { stdenv, callPackage
, withLinuxHeaders ? true
, installLocales ? true , installLocales ? true
, profilingLibraries ? false , profilingLibraries ? false
, gccCross ? null , withGd ? false
, withGd ? false, gd ? null, libpng ? null
}: }:
assert stdenv.cc.isGNU; assert stdenv.cc.isGNU;
let callPackage ./common.nix { inherit stdenv; } {
build = import ./common.nix; name = "glibc" + stdenv.lib.optionalString withGd "-gd";
cross = if gccCross != null then gccCross.target else null;
in
build cross ({
name = "glibc" + lib.optionalString withGd "-gd";
inherit lib stdenv fetchurl linuxHeaders installLocales inherit withLinuxHeaders profilingLibraries installLocales withGd;
profilingLibraries gccCross withGd gd libpng;
NIX_NO_SELF_RPATH = true; NIX_NO_SELF_RPATH = true;
@ -104,36 +99,3 @@ in
meta.description = "The GNU C Library"; 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 {}))

View File

@ -1,13 +1,8 @@
{ lib, stdenv, fetchurl, texinfo, perl }: { callPackage, texinfo, perl }:
let build = import ./common.nix; in callPackage ./common.nix {} {
/* null cross builder */
build null {
name = "glibc-info"; name = "glibc-info";
inherit fetchurl stdenv lib;
outputs = [ "out" ]; outputs = [ "out" ];
configureFlags = [ "--enable-add-ons" ]; configureFlags = [ "--enable-add-ons" ];

View File

@ -6,14 +6,13 @@
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/localedata/SUPPORTED?cvsroot=glibc 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 callPackage ./common.nix { inherit stdenv; } {
build null {
name = "glibc-locales"; name = "glibc-locales";
inherit fetchurl stdenv lib;
installLocales = true; installLocales = true;
builder = ./locales-builder.sh; builder = ./locales-builder.sh;

View File

@ -92,7 +92,7 @@ let
pkgs = pkgsFun ({inherit system;} // selectedCrossSystem); pkgs = pkgsFun ({inherit system;} // selectedCrossSystem);
glibc = pkgs.buildPackages.libcCross; glibc = pkgs.libcCross;
bash = pkgs.bash; bash = pkgs.bash;
findutils = pkgs.findutils; findutils = pkgs.findutils;
diffutils = pkgs.diffutils; diffutils = pkgs.diffutils;

View File

@ -7762,7 +7762,6 @@ with pkgs;
glibc = callPackage ../development/libraries/glibc { glibc = callPackage ../development/libraries/glibc {
installLocales = config.glibc.locales or false; installLocales = config.glibc.locales or false;
gccCross = null;
}; };
glibc_memusage = callPackage ../development/libraries/glibc { glibc_memusage = callPackage ../development/libraries/glibc {
@ -7770,13 +7769,23 @@ with pkgs;
withGd = true; withGd = true;
}; };
glibcCross = forcedNativePackages.glibc.override { # Being redundant to avoid cycles on boot. TODO: find a better way
gccCross = gccCrossStageStatic; glibcCross = callPackage ../development/libraries/glibc {
inherit (forcedNativePackages) linuxHeaders; 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: # 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 == "uclibc" then uclibcCross
else if name == "msvcrt" then windows.mingw_w64 else if name == "msvcrt" then windows.mingw_w64
else if name == "libSystem" then darwin.xcode else if name == "libSystem" then darwin.xcode

View File

@ -15,6 +15,7 @@ let
common = { common = {
buildPackages.binutils = nativePlatforms; buildPackages.binutils = nativePlatforms;
gmp = nativePlatforms; gmp = nativePlatforms;
libcCross = nativePlatforms;
}; };
gnuCommon = lib.recursiveUpdate common { gnuCommon = lib.recursiveUpdate common {