From 046df08be989a14e9c99fed5c83ac96a012c1562 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Sat, 27 Jul 2024 10:17:11 -0700 Subject: [PATCH] freshBootstrapTools.test: extract as a package --- pkgs/stdenv/darwin/make-bootstrap-tools.nix | 92 +---------------- pkgs/stdenv/darwin/test-bootstrap-tools.nix | 109 ++++++++++++++++++++ 2 files changed, 110 insertions(+), 91 deletions(-) create mode 100644 pkgs/stdenv/darwin/test-bootstrap-tools.nix diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index 0e47fbd8c4de..b921333f1bf7 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -295,97 +295,7 @@ rec { inherit (bootstrapFiles) bootstrapTools unpack; }; - test = derivation { - name = "test-bootstrap-tools"; - inherit (stdenv.hostPlatform) system; - builder = "${bootstrapTools}/bin/bash"; - args = [ "-euo" "pipefail" "-c" "eval \"$buildCommand\"" ]; - PATH = lib.makeBinPath [ bootstrapTools ]; - tools = bootstrapTools; - "${stdenv.cc.darwinMinVersionVariable}" = stdenv.cc.darwinMinVersion; - - # Create a pure environment where we use just what's in the bootstrap tools. - buildCommand = '' - mkdir -p $out/bin - - for exe in $tools/bin/*; do - [[ $exe =~ bunzip2|codesign.*|false|install_name_tool|ld|lipo|pbzx|ranlib|rewrite-tbd|sigtool ]] && continue - $exe --version > /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 ' >> hello1.c - echo '#include ' >> hello1.c - echo '#include ' >> hello1.c - echo 'int main() { printf("Hello World\n"); return 0; }' >> hello1.c - $CC -o hello1 hello1.c - cp hello1 $out/bin/ - $out/bin/hello1 - - echo '#include ' >> hello3.cc - echo 'int main() { std::cout << "Hello World\n"; }' >> hello3.cc - $CXX -v -o hello3 hello3.cc - cp hello3 $out/bin/ - $out/bin/hello3 - - # test that libc++.dylib rpaths are correct so it can reference libc++abi.dylib when linked. - # using -Wl,-flat_namespace is required to generate an error - mkdir libtest/ - ln -s $tools/lib/libc++.dylib libtest/ - clang++ -Wl,-flat_namespace -idirafter $tools/include-Libsystem -isystem$tools/include/c++/v1 \ - --sysroot=$tools -L./libtest -L$PWD/libSystem-boot hello3.cc - - tar xvf ${pkgs.hello.src} - cd hello-* - # hello configure detects -liconv is needed but doesn't add to the link step - LDFLAGS=-liconv ./configure --prefix=$out - make - make install - $out/bin/hello - ''; - }; + test = pkgs.callPackage ./test-bootstrap-tools.nix { inherit bootstrapTools; }; # The ultimate test: bootstrap a whole stdenv from the tools specified above and get a package set out of it # eg: nix-build -A freshBootstrapTools.test-pkgs.stdenv diff --git a/pkgs/stdenv/darwin/test-bootstrap-tools.nix b/pkgs/stdenv/darwin/test-bootstrap-tools.nix new file mode 100644 index 000000000000..84a4ca76566a --- /dev/null +++ b/pkgs/stdenv/darwin/test-bootstrap-tools.nix @@ -0,0 +1,109 @@ +{ + lib, + stdenv, + bootstrapTools, + hello, +}: + +builtins.derivation { + name = "test-bootstrap-tools"; + + inherit (stdenv.hostPlatform) system; + + builder = "${bootstrapTools}/bin/bash"; + + args = [ + "-euo" + "pipefail" + "-c" + "eval \"$buildCommand\"" + ]; + + PATH = lib.makeBinPath [ bootstrapTools ]; + + tools = bootstrapTools; + + "${stdenv.cc.darwinMinVersionVariable}" = stdenv.cc.darwinMinVersion; + + # Create a pure environment where we use just what's in the bootstrap tools. + buildCommand = '' + mkdir -p $out/bin + + for exe in $tools/bin/*; do + [[ $exe =~ bunzip2|codesign.*|false|install_name_tool|ld|lipo|pbzx|ranlib|rewrite-tbd|sigtool ]] && continue + $exe --version > /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 ' >> hello1.c + echo '#include ' >> hello1.c + echo '#include ' >> hello1.c + echo 'int main() { printf("Hello World\n"); return 0; }' >> hello1.c + $CC -o hello1 hello1.c + cp hello1 $out/bin/ + $out/bin/hello1 + + echo '#include ' >> hello3.cc + echo 'int main() { std::cout << "Hello World\n"; }' >> hello3.cc + $CXX -v -o hello3 hello3.cc + cp hello3 $out/bin/ + $out/bin/hello3 + + # test that libc++.dylib rpaths are correct so it can reference libc++abi.dylib when linked. + # using -Wl,-flat_namespace is required to generate an error + mkdir libtest/ + ln -s $tools/lib/libc++.dylib libtest/ + clang++ -Wl,-flat_namespace -idirafter $tools/include-Libsystem -isystem$tools/include/c++/v1 \ + --sysroot=$tools -L./libtest -L$PWD/libSystem-boot hello3.cc + + tar xvf ${hello.src} + cd hello-* + # hello configure detects -liconv is needed but doesn't add to the link step + LDFLAGS=-liconv ./configure --prefix=$out + make + make install + $out/bin/hello + ''; +}