From 088b29159d2e14a6e722cdc2a8204af7b3118b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 1 Jun 2022 18:18:07 +0200 Subject: [PATCH] libidn2: hack to avoid referencing bootstrap tools Due to bootstrap tools getting purged from closure of libidn2.dev, a very large rebuild is caused. --- .../development/libraries/libidn2/default.nix | 1 + .../libidn2/no-bootstrap-reference.nix | 30 +++++++++++++++++++ pkgs/stdenv/linux/default.nix | 10 ++++++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/libraries/libidn2/no-bootstrap-reference.nix diff --git a/pkgs/development/libraries/libidn2/default.nix b/pkgs/development/libraries/libidn2/default.nix index d8294f56adc35..933bafa429f59 100644 --- a/pkgs/development/libraries/libidn2/default.nix +++ b/pkgs/development/libraries/libidn2/default.nix @@ -16,6 +16,7 @@ stdenv.mkDerivation rec { sha256 = "sha256-dpQM1Od46Ak1eanRlbJf/16Tbp3GJCBoUotDenZ2T5E="; }; + # Beware: non-bootstrap libidn2 is overridden by ./hack.nix outputs = [ "bin" "dev" "out" "info" "devdoc" ]; patches = optional stdenv.isDarwin ./fix-error-darwin.patch; diff --git a/pkgs/development/libraries/libidn2/no-bootstrap-reference.nix b/pkgs/development/libraries/libidn2/no-bootstrap-reference.nix new file mode 100644 index 0000000000000..e5922073437de --- /dev/null +++ b/pkgs/development/libraries/libidn2/no-bootstrap-reference.nix @@ -0,0 +1,30 @@ +{ stdenv, lib, libidn2, libunistring, runCommandLocal, patchelf }: +# Construct a copy of libidn2.* where all (transitive) libc references (in .bin) +# get replaced by a new one, so that there's no reference to bootstrap tools. +runCommandLocal + "${libidn2.pname}-${libidn2.version}" + { + outputs = [ "bin" "dev" "out" ]; + passthru = { + inherit (libidn2) out info devdoc; # no need to touch these store paths + }; + } + '' + cp -r '${libidn2.bin}' "$bin" + chmod +w "$bin"/bin/* + patchelf \ + --set-interpreter '${stdenv.cc.bintools.dynamicLinker}' \ + --set-rpath '${lib.concatMapStringsSep ":" (p: lib.getLib p + "/lib") + [ stdenv.cc.libc libunistring libidn2 ]}' \ + "$bin"/bin/* + + cp -r '${libidn2.dev}' "$dev" + chmod +w "$dev"/nix-support/propagated-build-inputs + substituteInPlace "$dev"/nix-support/propagated-build-inputs \ + --replace '${libidn2.bin}' "$bin" + substituteInPlace "$dev"/lib/pkgconfig/libidn2.pc \ + --replace '${libidn2.dev}' "$dev" + + ln -s '${libidn2.out}' "$out" # it's hard to be without any $out + '' + diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 64c21fa105d42..d5b220b8520a7 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -432,8 +432,16 @@ in inherit (prevStage) gzip bzip2 xz bash coreutils diffutils findutils gawk gnumake gnused gnutar gnugrep gnupatch patchelf - attr acl zlib pcre libunistring libidn2; + attr acl zlib pcre libunistring; ${localSystem.libc} = getLibc prevStage; + + # Hack: avoid libidn2.{bin,dev} referencing bootstrap tools. There's a logical cycle. + libidn2 = import ../../development/libraries/libidn2/no-bootstrap-reference.nix { + inherit lib; + inherit (prevStage) libidn2; + inherit (self) stdenv runCommandLocal patchelf libunistring; + }; + } // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) { # Need to get rid of these when cross-compiling. inherit (prevStage) binutils binutils-unwrapped;