about summary refs log tree commit diff
path: root/pkgs/development/tools/mold
diff options
context:
space:
mode:
authorArtturin <Artturin@artturin.com>2023-10-13 03:35:26 +0300
committerArtturin <Artturin@artturin.com>2023-10-13 05:23:32 +0300
commit77bf1395d6c5bb99a33c2bf76b2c6943b31ac85b (patch)
tree8852003faf373a35810c913f4511a13ba20bfb14 /pkgs/development/tools/mold
parent30f2ab26fe55137d1c8604880b52951bb6c46804 (diff)
mold: add tests for `mold-wrapped` and `useMoldLinker` adapter
Make both ready for cross with prefixes

Currently
`pkgsCross.aarch64-multiplatform.mold.passthru.tests.{wrapped,adapter}`
fail with

```
Testing running the 'hello' binary which should be linked with 'mold'
Hello, world!
Checking for mold in the '.comment' section
No mention of 'mold' detected in the '.comment' section
The command was:
aarch64-unknown-linux-gnu-readelf -p .comment ...bin/hello
The output was:
String dump of section '.comment':
  [     0]  GCC: (GNU) 12.3.0
```
Diffstat (limited to 'pkgs/development/tools/mold')
-rw-r--r--pkgs/development/tools/mold/default.nix47
1 files changed, 46 insertions, 1 deletions
diff --git a/pkgs/development/tools/mold/default.nix b/pkgs/development/tools/mold/default.nix
index 52844300f0875..84a7509c528c3 100644
--- a/pkgs/development/tools/mold/default.nix
+++ b/pkgs/development/tools/mold/default.nix
@@ -9,6 +9,11 @@
 , testers
 , mold
 , nix-update-script
+, runCommandCC
+, mold-wrapped
+, hello
+, buildPackages
+, useMoldLinker
 }:
 
 stdenv.mkDerivation rec {
@@ -44,7 +49,47 @@ stdenv.mkDerivation rec {
 
   passthru = {
     updateScript = nix-update-script { };
-    tests.version = testers.testVersion { package = mold; };
+    tests =
+      let
+        helloTest = name: helloMold:
+          let
+            command = "$READELF -p .comment ${lib.getExe helloMold}";
+            emulator = stdenv.hostPlatform.emulator buildPackages;
+          in
+          runCommandCC "mold-${name}-test" { passthru = { inherit helloMold; }; }
+            ''
+              echo "Testing running the 'hello' binary which should be linked with 'mold'" >&2
+              ${emulator} ${lib.getExe helloMold}
+
+              echo "Checking for mold in the '.comment' section" >&2
+              if output=$(${command} 2>&1); then
+                if grep -Fw -- "mold" - <<< "$output"; then
+                  touch $out
+                else
+                  echo "No mention of 'mold' 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
+      {
+        version = testers.testVersion { package = mold; };
+        wrapped = helloTest "wrapped" (hello.overrideAttrs (previousAttrs: {
+          nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ mold-wrapped ];
+          NIX_CFLAGS_LINK = toString (previousAttrs.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold";
+        }));
+        adapter = helloTest "adapter" (hello.override (old: { stdenv = useMoldLinker old.stdenv; }));
+      };
   };
 
   meta = with lib; {