From 72870b3293a3c8a92dbba5a244470566fbc06539 Mon Sep 17 00:00:00 2001 From: annalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:04:55 +0000 Subject: [PATCH 1/3] freshBootstrapTools.{build,test}: fix as script. test all executables as is a wrapper around clang and the path to bash and clang need to be updated when unpacked run all executables in bin get run in the test --- pkgs/stdenv/darwin/make-bootstrap-tools.nix | 34 +++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index 836a938b84ae..3476748a8fd2 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -77,6 +77,9 @@ rec { updateInstallName "$lib" done + # as is a wrapper around clang. need to replace the nuked store paths + sed -i 's|/.*/bin/|'"$out"'/bin/|' $out/bin/as + # Provide a gunzip script. cat > $out/bin/gunzip < /dev/null || { echo $exe failed >&2; exit 1; } + done + + # run all exes that don't take a --version flag + bunzip2 -h + codesign --help + codesign_allocate -i $tools/bin/true -r -o true + false || (($? == 1)) + install_name_tool -id true true + ld -v + lipo -info true + pbzx -v + # ranlib gets tested bulding hello + rewrite-tbd Date: Mon, 1 Apr 2024 22:13:44 +0000 Subject: [PATCH 2/3] freshBootstrapTools.{build,test}: allow exes with libs unpack --- pkgs/stdenv/darwin/make-bootstrap-tools.nix | 50 +++++++-------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index 3476748a8fd2..3064e7f76260 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -49,14 +49,6 @@ rec { scpSupport = false; }); - gnutar_ = (gnutar.override { libintl = null; }).overrideAttrs (old: { - configureFlags = [ - "--disable-nls" - ] ++ old.configureFlags or []; - }); - - xz_ = xz.override { enableStatic = true; }; - unpackScript = writeText "bootstrap-tools-unpack.sh" '' set -euo pipefail @@ -102,7 +94,7 @@ rec { in '' - mkdir -p $out/bin $out/lib $out/lib/system $out/lib/darwin + mkdir -p $out/bin $out/lib $out/lib/darwin ${lib.optionalString stdenv.targetPlatform.isx86_64 '' # Copy libSystem's .o files for various low-level boot stuff. @@ -192,15 +184,15 @@ rec { cp -d ${getLib darwin.libtapi}/lib/libtapi* $out/lib - # tools needed to unpack bootstrap archive. they should not contain any - # external references. we will process them like the other tools but - # perform some additional checks and will not pack them into the archive. - mkdir -p unpack/bin - cp ${getBin bash}/bin/bash unpack/bin - ln -s bash unpack/bin/sh + # tools needed to unpack bootstrap archive + mkdir -p unpack/bin unpack/lib + cp -d ${getBin bash}/bin/{bash,sh} unpack/bin cp ${getBin coreutils_}/bin/mkdir unpack/bin - cp ${getBin gnutar_}/bin/tar unpack/bin - cp ${getBin xz_}/bin/xz unpack/bin + cp ${getBin gnutar}/bin/tar unpack/bin + cp ${getBin xz}/bin/xz unpack/bin + cp -d ${getLib gettext}/lib/libintl*.dylib unpack/lib + cp -d ${getLib libiconv}/lib/lib*.dylib unpack/lib + cp -d ${getLib xz}/lib/liblzma*.dylib unpack/lib cp ${unpackScript} unpack/bootstrap-tools-unpack.sh # @@ -245,45 +237,37 @@ rec { fi } - # check that linked library paths exist in $out/lib + # check that linked library paths exist in lib # must be run after rpathify is performed checkDeps() { local deps=$(${stdenv.cc.targetPrefix}otool -l "$1"| grep -o '@rpath/[^ ]*' || true) local lib + shopt -s extglob for lib in $deps; do - if [[ ! -e $out/''${lib/@rpath/lib} ]]; then + local root="''${1/\/@(lib|bin)\/*}" + if [[ ! -e $root/''${lib/@rpath/lib} ]]; then echo "error: $1 missing lib for $lib" >&2 exit 1 fi done + shopt -u extglob } - for i in $out/bin/* unpack/bin/* $out/lib{,/darwin}/*.dylib; do + for i in {unpack,$out}/bin/* {unpack,$out}/lib{,/darwin}/*.dylib; do if [[ ! -L $i ]] && isMachO "$i"; then rpathify "$i" checkDeps "$i" fi done - nuke-refs $out/bin/* - nuke-refs $out/lib/* + nuke-refs {unpack,$out}/bin/* + nuke-refs {unpack,$out}/lib/* nuke-refs $out/lib/darwin/* - nuke-refs $out/lib/system/* - nuke-refs unpack/bin/* mkdir $out/.pack mv $out/* $out/.pack mv $out/.pack $out/pack - # validate that tools contain no references into the archive - for tool in unpack/bin/*; do - deps=$(${stdenv.cc.targetPrefix}otool -l "$tool"| grep '@rpath/' || true) - if [[ -n "$deps" ]]; then - printf "error: $tool is not self contained\n$deps\n" >&2 - exit 1 - fi - done - mkdir $out/on-server cp -r unpack $out From 39b3d15ad8861f9957c754d301dc3a0d7f8b7129 Mon Sep 17 00:00:00 2001 From: annalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:15:28 +0000 Subject: [PATCH 3/3] freshBootstrapTools.{build,test}: group tools together --- pkgs/stdenv/darwin/make-bootstrap-tools.nix | 73 ++++++++++----------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index 3064e7f76260..83e982142d30 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -110,27 +110,42 @@ rec { cp -rL ${getDev gnugrep.pcre2}/include/* $out/include mv $out/include $out/include-Libsystem + # Copy binutils. + for i in as ld ar ranlib nm strip otool install_name_tool lipo codesign_allocate; do + cp ${getBin cctools_}/bin/$i $out/bin + done + # Copy coreutils, bash, etc. cp ${getBin coreutils_}/bin/* $out/bin (cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users) - cp ${getBin bash}/bin/bash $out/bin - ln -s bash $out/bin/sh - cp ${getBin findutils}/bin/find $out/bin - cp ${getBin findutils}/bin/xargs $out/bin + cp -d ${getBin bash}/bin/{ba,}sh $out/bin cp -d ${getBin diffutils}/bin/* $out/bin - cp -d ${getBin gnused}/bin/* $out/bin + cp ${getBin findutils}/bin/{find,xargs} $out/bin + cp -d ${getBin gawk}/bin/{g,}awk $out/bin cp -d ${getBin gnugrep}/bin/grep $out/bin - cp ${getBin gawk}/bin/gawk $out/bin - cp -d ${getBin gawk}/bin/awk $out/bin + cp -d ${getBin gnumake}/bin/* $out/bin + cp -d ${getBin gnused}/bin/* $out/bin + cp -d ${getBin patch}/bin/* $out/bin + + cp -d ${getLib gettext}/lib/libintl*.dylib $out/lib + cp -d ${getLib gnugrep.pcre2}/lib/libpcre2*.dylib $out/lib + cp -d ${getLib libiconv}/lib/lib*.dylib $out/lib + cp -d ${getLib libxml2}/lib/libxml2*.dylib $out/lib + cp -d ${getLib ncurses}/lib/libncurses*.dylib $out/lib + + # copy package extraction tools + cp -d ${getBin bzip2}/bin/b{,un}zip2 $out/bin + cp ${getBin cpio}/bin/cpio $out/bin cp ${getBin gnutar}/bin/tar $out/bin cp ${getBin gzip}/bin/.gzip-wrapped $out/bin/gzip - cp ${getBin bzip2}/bin/bzip2 $out/bin - ln -s bzip2 $out/bin/bunzip2 - cp -d ${getBin gnumake}/bin/* $out/bin - cp -d ${getBin patch}/bin/* $out/bin - cp -d ${getBin xz}/bin/xz $out/bin - cp ${getBin cpio}/bin/cpio $out/bin + cp ${getBin pbzx}/bin/pbzx $out/bin + cp ${getBin xz}/bin/xz $out/bin + cp -d ${getLib bzip2}/lib/libbz2*.dylib $out/lib + cp -d ${getLib gmpxx}/lib/libgmp*.dylib $out/lib + cp -d ${getLib xar}/lib/libxar*.dylib $out/lib + cp -d ${getLib xz}/lib/liblzma*.dylib $out/lib + cp -d ${getLib zlib}/lib/libz*.dylib $out/lib # This used to be in-nixpkgs, but now is in the bundle # because I can't be bothered to make it partially static @@ -138,13 +153,6 @@ rec { cp -d ${getLib curl_}/lib/libcurl*.dylib $out/lib cp -d ${getLib openssl}/lib/*.dylib $out/lib - cp -d ${getLib gnugrep.pcre2}/lib/libpcre2*.dylib $out/lib - cp -d ${getLib libiconv}/lib/lib*.dylib $out/lib - cp -d ${getLib gettext}/lib/libintl*.dylib $out/lib - chmod +x $out/lib/libintl*.dylib - cp -d ${getLib ncurses}/lib/libncurses*.dylib $out/lib - cp -d ${getLib libxml2}/lib/libxml2*.dylib $out/lib - # Copy what we need of clang cp -d ${getBin llvmPackages.clang-unwrapped}/bin/clang{,++,-cl,-cpp,-[0-9]*} $out/bin cp -d ${getLib llvmPackages.clang-unwrapped}/lib/libclang-cpp*.dylib $out/lib @@ -158,31 +166,16 @@ rec { cp -d ${getLib libffi}/lib/libffi*.dylib $out/lib mkdir $out/include - cp -rd ${getDev llvmPackages.libcxx}/include/c++ $out/include + cp -rd ${getDev llvmPackages.libcxx}/include/c++ $out/include # copy .tbd assembly utils - cp -d ${getBin pkgs.darwin.rewrite-tbd}/bin/rewrite-tbd $out/bin - cp -d ${getLib pkgs.libyaml}/lib/libyaml*.dylib $out/lib - - # copy package extraction tools - cp -d ${getBin pkgs.pbzx}/bin/pbzx $out/bin - cp -d ${getLib pkgs.xar}/lib/libxar*.dylib $out/lib - cp -d ${getLib pkgs.bzip2}/lib/libbz2*.dylib $out/lib + cp ${getBin darwin.rewrite-tbd}/bin/rewrite-tbd $out/bin + cp -d ${getLib libyaml}/lib/libyaml*.dylib $out/lib # copy sigtool - cp -d ${getBin pkgs.darwin.sigtool}/bin/sigtool $out/bin - cp -d ${getBin pkgs.darwin.sigtool}/bin/codesign $out/bin + cp -d ${getBin darwin.sigtool}/bin/{codesign,sigtool} $out/bin - cp -d ${getLib zlib}/lib/libz.* $out/lib - cp -d ${getLib gmpxx}/lib/libgmp*.* $out/lib - cp -d ${getLib xz}/lib/liblzma*.* $out/lib - - # Copy binutils. - for i in as ld ar ranlib nm strip otool install_name_tool lipo codesign_allocate; do - cp ${getBin cctools_}/bin/$i $out/bin - done - - cp -d ${getLib darwin.libtapi}/lib/libtapi* $out/lib + cp -d ${getLib darwin.libtapi}/lib/libtapi*.dylib $out/lib # tools needed to unpack bootstrap archive mkdir -p unpack/bin unpack/lib