Commit a4bc70d4 authored by Ross Smyth's avatar Ross Smyth
Browse files

adapters: Add useWildLinker

parent d538006b
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
{
  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;
    })
  );
}
+16 −0
Original line number Diff line number Diff line
@@ -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.