nixpkgs/pkgs/by-name/ha/hare/cross-compilation-tests.nix
Gustavo Coutinho de Souza 3ff0cd7263
hare: embedd paths for cross-compilation toolchains
Also strip the `HAREPATH` make variable embedded in the binary from
empty `$(SRCDIR)/hare/third-party`, since since nix does not follows the
FHS and relies on the `HAREPATH` environment variable to find third
party libraries.
2024-01-17 13:31:00 -03:00

32 lines
844 B
Nix

{ 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
''