From d8231a66ebb199fd5a1876ee0a9b3e3bf64dafc0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Jun 2013 18:39:23 +0200 Subject: [PATCH] glibc: Split into multiple outputs This reduces the size of closures a lot by getting rid of Glibc's header files, static libraries and utilities. For instance, the closure of GNU Hello went from 41 MiB to 22 MiB. TODO: We may want to merge back in parts of Glibc that we previously split off (such as the info files). --- pkgs/build-support/gcc-wrapper/builder.sh | 5 +++-- pkgs/build-support/gcc-wrapper/default.nix | 2 ++ pkgs/build-support/gcc-wrapper/setup-hook.sh | 2 +- .../development/libraries/glibc/2.17/builder.sh | 17 +++++++++++++++-- .../libraries/glibc/2.17/default.nix | 4 +++- pkgs/development/libraries/libelf/default.nix | 16 ++++++---------- pkgs/stdenv/linux/default.nix | 2 +- pkgs/top-level/all-packages.nix | 1 + 8 files changed, 32 insertions(+), 17 deletions(-) diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh index ed7ad0a50b7..c15fd1da9c0 100644 --- a/pkgs/build-support/gcc-wrapper/builder.sh +++ b/pkgs/build-support/gcc-wrapper/builder.sh @@ -24,7 +24,7 @@ if test -z "$nativeLibc"; then # compile, because it uses "#include_next " to find the # limits.h file in ../includes-fixed. To remedy the problem, # another -idirafter is necessary to add that directory again. - echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags + echo "-B$libc/lib/ -idirafter $libc_dev/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags echo "-L$libc/lib" > $out/nix-support/libc-ldflags @@ -85,6 +85,7 @@ doSubstitute() { -e "s^@binutils@^$binutils^g" \ -e "s^@coreutils@^$coreutils^g" \ -e "s^@libc@^$libc^g" \ + -e "s^@libc_bin@^$libc_bin^g" \ -e "s^@ld@^$ldPath/ld^g" \ < "$src" > "$dst" } @@ -191,5 +192,5 @@ cp -p $utils $out/nix-support/utils.sh # tools like gcov, the manpages, etc. as well (including for binutils # and Glibc). if test -z "$nativeTools"; then - echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages + echo $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages fi diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix index 992c0f9af37..82167cddf2e 100644 --- a/pkgs/build-support/gcc-wrapper/default.nix +++ b/pkgs/build-support/gcc-wrapper/default.nix @@ -41,6 +41,8 @@ stdenv.mkDerivation { inherit nativeTools nativeLibc nativePrefix gcc; libc = if nativeLibc then null else libc; + libc_dev = if nativeLibc then null else libc.dev or libc; + libc_bin = if nativeLibc then null else libc.bin or libc; binutils = if nativeTools then null else binutils; # The wrapper scripts use 'cat', so we may need coreutils coreutils = if nativeTools then null else coreutils; diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh index 513ab8053a7..26a722bac9b 100644 --- a/pkgs/build-support/gcc-wrapper/setup-hook.sh +++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh @@ -25,7 +25,7 @@ if test -n "@binutils@"; then fi if test -n "@libc@"; then - addToSearchPath PATH @libc@/bin + addToSearchPath PATH @libc_bin@/bin fi if test -n "@coreutils@"; then diff --git a/pkgs/development/libraries/glibc/2.17/builder.sh b/pkgs/development/libraries/glibc/2.17/builder.sh index b01977a33de..f9e491868ef 100644 --- a/pkgs/development/libraries/glibc/2.17/builder.sh +++ b/pkgs/development/libraries/glibc/2.17/builder.sh @@ -12,8 +12,10 @@ postConfigure() { export NIX_DONT_SET_RPATH=1 unset CFLAGS -} + # Apparently --bindir is not respected. + makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin") +} postInstall() { if test -n "$installLocales"; then @@ -27,7 +29,7 @@ postInstall() { if test -z "$hurdHeaders"; then # Include the Linux kernel headers in Glibc, except the `scsi' # subdirectory, which Glibc provides itself. - (cd $out/include && \ + (cd $dev/include && \ ln -sv $(ls -d $kernelHeaders/include/* | grep -v 'scsi$') .) fi @@ -49,6 +51,17 @@ postInstall() { # This file, that should not remain in the glibc derivation, # may have not been created during the preInstall rm -f $out/lib/libgcc_s.so.1 + + # Put libraries for static linking in a separate output. Note + # that libc_nonshared.a and libpthread_nonshared.a are required + # for dynamically-linked applications. + mkdir -p $static/lib + mv $out/lib/*.a $static/lib + mv $static/lib/lib*_nonshared.a $out/lib + + # Work around a Nix bug: hard links across outputs cause a build failure. + cp $bin/bin/getconf $bin/bin/getconf_ + mv $bin/bin/getconf_ $bin/bin/getconf } genericBuild diff --git a/pkgs/development/libraries/glibc/2.17/default.nix b/pkgs/development/libraries/glibc/2.17/default.nix index b6d91c932db..da2ddc7a797 100644 --- a/pkgs/development/libraries/glibc/2.17/default.nix +++ b/pkgs/development/libraries/glibc/2.17/default.nix @@ -23,6 +23,8 @@ in builder = ./builder.sh; + outputs = [ "out" "dev" "bin" "static" ]; + # When building glibc from bootstrap-tools, we need libgcc_s at RPATH for # any program we run, because the gcc will have been placed at a new # store path than that determined when built (as a source for the @@ -93,7 +95,7 @@ in # To avoid a dependency on the build system 'bash'. preFixup = '' - rm $out/bin/{ldd,tzselect,catchsegv,xtrace} + rm $bin/bin/{ldd,tzselect,catchsegv,xtrace} ''; } else {})) diff --git a/pkgs/development/libraries/libelf/default.nix b/pkgs/development/libraries/libelf/default.nix index 40eb2a10faf..b37bf593c03 100644 --- a/pkgs/development/libraries/libelf/default.nix +++ b/pkgs/development/libraries/libelf/default.nix @@ -1,6 +1,6 @@ { fetchurl, stdenv, gettext }: -stdenv.mkDerivation (rec { +stdenv.mkDerivation rec { name = "libelf-0.8.13"; src = fetchurl { @@ -10,6 +10,11 @@ stdenv.mkDerivation (rec { doCheck = true; + # Libelf's custom NLS macros fail to determine the catalog file extension on + # Darwin, so disable NLS for now. + # FIXME: Eventually make Gettext a build input on all platforms. + configureFlags = stdenv.lib.optional stdenv.isDarwin "--disable-nls"; + meta = { description = "Libelf, an ELF object file access library"; @@ -21,12 +26,3 @@ stdenv.mkDerivation (rec { maintainers = [ stdenv.lib.maintainers.ludo ]; }; } - -// - -# Libelf's custom NLS macros fail to determine the catalog file extension on -# Darwin, so disable NLS for now. -# FIXME: Eventually make Gettext a build input on all platforms. -(if stdenv.isDarwin - then { configureFlags = [ "--disable-nls" ]; } - else { })) diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 44f5ff6ab30..a20adb6aba2 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -7,7 +7,7 @@ # The function defaults are for easy testing. { system ? builtins.currentSystem , allPackages ? import ../../top-level/all-packages.nix -, platform ? null, config }: +, platform ? null, config ? {} }: rec { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cc7477950f6..0bbb81745a4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3902,6 +3902,7 @@ let })); glibc217 = callPackage ../development/libraries/glibc/2.17 { + stdenv = stdenvMulti; kernelHeaders = linuxHeaders; installLocales = config.glibc.locales or false; machHeaders = null;