From 67a5dcdc4124b886759baf3ed5c813c206cdc713 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Sat, 27 Jul 2024 12:58:16 -0700 Subject: [PATCH] freshBootstrapTools.test: extract a package --- pkgs/stdenv/linux/make-bootstrap-tools.nix | 54 +--------------- pkgs/stdenv/linux/test-bootstrap-tools.nix | 71 ++++++++++++++++++++++ 2 files changed, 74 insertions(+), 51 deletions(-) create mode 100644 pkgs/stdenv/linux/test-bootstrap-tools.nix diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix index 57b8f9cd4d91..6bf42fe0f9ca 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix @@ -74,56 +74,8 @@ in with pkgs; rec { } else throw "unsupported libc"; - test = derivation { - name = "test-bootstrap-tools"; - inherit (stdenv.hostPlatform) system; # We cannot "cross test" - builder = bootstrapFiles.busybox; - args = [ "ash" "-e" "-c" "eval \"$buildCommand\"" ]; - - buildCommand = '' - export PATH=${bootstrapTools}/bin - - ls -l - mkdir $out - mkdir $out/bin - sed --version - find --version - diff --version - patch --version - make --version - awk --version - grep --version - gcc --version - - '' + lib.optionalString (stdenv.hostPlatform.libc == "glibc") '' - rtld=$(echo ${bootstrapTools}/lib/${builtins.unsafeDiscardStringContext /* only basename */ (builtins.baseNameOf binutils.dynamicLinker)}) - libc_includes=${bootstrapTools}/include-glibc - '' + lib.optionalString (stdenv.hostPlatform.libc == "musl") '' - rtld=$(echo ${bootstrapTools}/lib/ld-musl*.so.?) - libc_includes=${bootstrapTools}/include-libc - '' + '' - # path to version-specific libraries, like libstdc++.so - cxx_libs=$(echo ${bootstrapTools}/lib/gcc/*/*) - export CPP="cpp -idirafter $libc_includes -B${bootstrapTools}" - export CC="gcc -idirafter $libc_includes -B${bootstrapTools} -Wl,-dynamic-linker,$rtld -Wl,-rpath,${bootstrapTools}/lib -Wl,-rpath,$cxx_libs" - export CXX="g++ -idirafter $libc_includes -B${bootstrapTools} -Wl,-dynamic-linker,$rtld -Wl,-rpath,${bootstrapTools}/lib -Wl,-rpath,$cxx_libs" - - echo '#include ' >> foo.c - echo '#include ' >> foo.c - echo 'int main() { printf("Hello World\\n"); return 0; }' >> foo.c - $CC -o $out/bin/foo foo.c - $out/bin/foo - - echo '#include ' >> bar.cc - echo 'int main() { std::cout << "Hello World\\n"; }' >> bar.cc - $CXX -v -o $out/bin/bar bar.cc - $out/bin/bar - - tar xvf ${hello.src} - cd hello-* - ./configure --prefix=$out - make - make install - ''; + test = callPackage ./test-bootstrap-tools.nix { + inherit bootstrapTools; + inherit (bootstrapFiles) busybox; }; } diff --git a/pkgs/stdenv/linux/test-bootstrap-tools.nix b/pkgs/stdenv/linux/test-bootstrap-tools.nix new file mode 100644 index 000000000000..e199e5159195 --- /dev/null +++ b/pkgs/stdenv/linux/test-bootstrap-tools.nix @@ -0,0 +1,71 @@ +{ + lib, + stdenv, + binutils, + busybox, + bootstrapTools, + hello, +}: + +builtins.derivation { + name = "test-bootstrap-tools"; + inherit (stdenv.hostPlatform) system; # We cannot "cross test" + builder = busybox; + args = [ + "ash" + "-e" + "-c" + "eval \"$buildCommand\"" + ]; + + buildCommand = + '' + export PATH=${bootstrapTools}/bin + + ls -l + mkdir $out + mkdir $out/bin + sed --version + find --version + diff --version + patch --version + make --version + awk --version + grep --version + gcc --version + + '' + + lib.optionalString (stdenv.hostPlatform.libc == "glibc") '' + rtld=$(echo ${bootstrapTools}/lib/${builtins.unsafeDiscardStringContext # only basename + (builtins.baseNameOf binutils.dynamicLinker)}) + libc_includes=${bootstrapTools}/include-glibc + '' + + lib.optionalString (stdenv.hostPlatform.libc == "musl") '' + rtld=$(echo ${bootstrapTools}/lib/ld-musl*.so.?) + libc_includes=${bootstrapTools}/include-libc + '' + + '' + # path to version-specific libraries, like libstdc++.so + cxx_libs=$(echo ${bootstrapTools}/lib/gcc/*/*) + export CPP="cpp -idirafter $libc_includes -B${bootstrapTools}" + export CC="gcc -idirafter $libc_includes -B${bootstrapTools} -Wl,-dynamic-linker,$rtld -Wl,-rpath,${bootstrapTools}/lib -Wl,-rpath,$cxx_libs" + export CXX="g++ -idirafter $libc_includes -B${bootstrapTools} -Wl,-dynamic-linker,$rtld -Wl,-rpath,${bootstrapTools}/lib -Wl,-rpath,$cxx_libs" + + echo '#include ' >> foo.c + echo '#include ' >> foo.c + echo 'int main() { printf("Hello World\\n"); return 0; }' >> foo.c + $CC -o $out/bin/foo foo.c + $out/bin/foo + + echo '#include ' >> bar.cc + echo 'int main() { std::cout << "Hello World\\n"; }' >> bar.cc + $CXX -v -o $out/bin/bar bar.cc + $out/bin/bar + + tar xvf ${hello.src} + cd hello-* + ./configure --prefix=$out + make + make install + ''; +}