about summary refs log tree commit diff
path: root/nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix
blob: 26611fea9d6588ba95a2c508fb55af58bb8ce2cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
''