about summary refs log tree commit diff
path: root/nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix')
-rw-r--r--nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix31
1 files changed, 31 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix b/nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix
new file mode 100644
index 000000000000..26611fea9d65
--- /dev/null
+++ b/nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix
@@ -0,0 +1,31 @@
+{ lib
+, buildPackages
+, hare
+, runCommandNoCC
+, stdenv
+, writeText
+}:
+let
+  inherit (stdenv.hostPlatform.uname) processor;
+  inherit (stdenv.hostPlatform) emulator;
+  mainDotHare = writeText "main.ha" ''
+    use fmt;
+    use os;
+    export fn main() void = {
+        const machine = os::machine();
+        if (machine == "${processor}") {
+            fmt::println("os::machine() matches ${processor}")!;
+        } else {
+            fmt::fatalf("os::machine() does not match ${processor}: {}", machine);
+        };
+    };
+  '';
+in
+runCommandNoCC "${hare.pname}-cross-compilation-test" { meta.timeout = 60; } ''
+  HARECACHE="$(mktemp -d --tmpdir harecache.XXXXXXXX)"
+  export HARECACHE
+  outbin="test-${processor}"
+  ${lib.getExe hare} build -q -a "${processor}" -o "$outbin" ${mainDotHare}
+  ${emulator buildPackages} "./$outbin"
+  : 1>$out
+''