mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-27 01:13:05 +00:00
Merge pull request #312213 from onemoresuza/hare-refactor-cross-comp-tests
hare: refactor cross-compilation tests
This commit is contained in:
commit
9be29d81eb
@ -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
|
||||
''
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user