Merge pull request #312213 from onemoresuza/hare-refactor-cross-comp-tests

hare: refactor cross-compilation tests
This commit is contained in:
Peder Bergebakken Sundt 2024-07-28 23:40:44 +02:00 committed by GitHub
commit 9be29d81eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 27 deletions

View File

@ -1,31 +1,40 @@
{ lib
, buildPackages
, hare
, runCommandNoCC
, stdenv
, writeText
{
lib,
file,
hare,
runCommandNoCC,
writeText,
}:
let
inherit (stdenv.hostPlatform.uname) processor;
inherit (stdenv.hostPlatform) emulator;
archs = lib.concatStringsSep " " (
builtins.map (lib.removeSuffix "-linux") (
builtins.filter (lib.hasSuffix "-linux") hare.meta.platforms
)
);
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);
};
};
export fn main() void = void;
'';
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
''
runCommandNoCC "${hare.pname}-cross-compilation-test"
{
nativeBuildInputs = [
hare
file
];
}
''
HARECACHE="$(mktemp -d)"
export HARECACHE
readonly binprefix="bin"
for a in ${archs}; do
outbin="$binprefix-$a"
set -x
hare build -o "$outbin" -q -R -a "$a" ${mainDotHare}
set +x
printf -- 'Built "%s" target\n' "$a"
done
file -- "$binprefix-"*
: 1>$out
''

View File

@ -161,7 +161,12 @@ stdenv.mkDerivation (finalAttrs: {
}
// lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) {
mimeModule = callPackage ./mime-module-test.nix { hare = finalAttrs.finalPackage; };
};
}
//
lib.optionalAttrs (enableCrossCompilation && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
{
crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; };
};
# To be propagated by `hareHook`.
inherit harec qbe;
};