diff --git a/pkgs/by-name/wi/wild/adapterTest.nix b/pkgs/by-name/wi/wild/adapterTest.nix index db334485cd80..44f80e2634e9 100644 --- a/pkgs/by-name/wi/wild/adapterTest.nix +++ b/pkgs/by-name/wi/wild/adapterTest.nix @@ -1,6 +1,10 @@ { lib, stdenv, + gccStdenv, + clangStdenv, + buildPackages, + runCommandCC, makeBinaryWrapper, gcc, wild, @@ -8,6 +12,8 @@ clang, lld, clang-tools, + useWildLinker, + hello, }: let # These wrappers are REQUIRED for the Wild test suite to pass @@ -51,6 +57,38 @@ let runHook postBuild ''; }; + + # Test helper that takes in a binary and checks that it runs + # and was built with Wild + helloTest = + name: helloWild: + let + command = "$READELF -p .comment ${lib.getExe helloWild}"; + emulator = stdenv.hostPlatform.emulator buildPackages; + in + runCommandCC "wild-${name}-test" { passthru = { inherit helloWild; }; } '' + echo "Testing running the 'hello' binary which should be linked with 'wild'" >&2 + ${emulator} ${lib.getExe helloWild} + + echo "Checking for wild in the '.comment' section" >&2 + if output=$(${command} 2>&1); then + if grep -Fw -- "Wild" - <<< "$output"; then + touch $out + else + echo "No mention of 'wild' detected in the '.comment' section" >&2 + echo "The command was:" >&2 + echo "${command}" >&2 + echo "The output was:" >&2 + echo "$output" >&2 + exit 1 + fi + else + echo -n "${command}" >&2 + echo " returned a non-zero exit code." >&2 + echo "$output" >&2 + exit 1 + fi + ''; in { testWild = wild.overrideAttrs { @@ -96,4 +134,18 @@ in installPhase = "touch $out"; }; + + # Test that the adapter works with a gcc stdenv + adapterGcc = helloTest "adapter-gcc" ( + hello.override (_: { + stdenv = useWildLinker gccStdenv; + }) + ); + + # Test the adapter works with a clang stdenv + adapter-llvm = helloTest "adapter-llvm" ( + hello.override (_: { + stdenv = useWildLinker clangStdenv; + }) + ); } diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 4ef0e31896df..d7360aa3360f 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -335,6 +335,22 @@ rec { } ); + useWildLinker = + stdenv: + if !stdenv.targetPlatform.isLinux then + throw "Wild only supports building Linux ELF files from Linux hosts." + else + stdenv.override (prev: { + allowedRequisites = null; + cc = prev.cc.override { + bintools = prev.cc.bintools.override { + extraBuildCommands = '' + ln -fs ${pkgs.buildPackages.wild-wrapped}/bin/* "$out/bin" + ''; + }; + }; + }); + /* Modify a stdenv so that it builds binaries optimized specifically for the machine they are built on.