diff --git a/pkgs/by-name/ha/hare/cross-compilation-tests.nix b/pkgs/by-name/ha/hare/cross-compilation-tests.nix index 26611fea9d65..c5797a9a1566 100644 --- a/pkgs/by-name/ha/hare/cross-compilation-tests.nix +++ b/pkgs/by-name/ha/hare/cross-compilation-tests.nix @@ -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 + '' diff --git a/pkgs/by-name/ha/hare/package.nix b/pkgs/by-name/ha/hare/package.nix index 6090106f7b43..c809d73c3897 100644 --- a/pkgs/by-name/ha/hare/package.nix +++ b/pkgs/by-name/ha/hare/package.nix @@ -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; };