2018-11-13 22:54:08 +00:00
|
|
|
|
{ pkgs, lib }:
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
2018-11-13 22:54:08 +00:00
|
|
|
|
testedSystems = lib.filterAttrs (name: value: let
|
|
|
|
|
platform = lib.systems.elaborate value;
|
|
|
|
|
in platform.isLinux || platform.isWindows
|
|
|
|
|
) lib.systems.examples;
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
|
|
|
|
getExecutable = pkgs: pkgFun: exec:
|
2023-01-09 03:36:01 +00:00
|
|
|
|
"${pkgFun pkgs}${exec}${pkgs.stdenv.hostPlatform.extensions.executable}";
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
|
|
|
|
compareTest = { emulator, pkgFun, hostPkgs, crossPkgs, exec, args ? [] }: let
|
|
|
|
|
pkgName = (pkgFun hostPkgs).name;
|
|
|
|
|
args' = lib.concatStringsSep " " args;
|
2023-11-03 22:32:06 +00:00
|
|
|
|
in crossPkgs.runCommand "test-${pkgName}-${crossPkgs.stdenv.hostPlatform.config}" {
|
2018-07-21 02:43:55 +00:00
|
|
|
|
nativeBuildInputs = [ pkgs.dos2unix ];
|
|
|
|
|
} ''
|
2018-11-13 22:54:08 +00:00
|
|
|
|
# Just in case we are using wine, get rid of that annoying extra
|
|
|
|
|
# stuff.
|
|
|
|
|
export WINEDEBUG=-all
|
|
|
|
|
|
2018-07-21 02:43:55 +00:00
|
|
|
|
HOME=$(pwd)
|
|
|
|
|
mkdir -p $out
|
|
|
|
|
|
|
|
|
|
# We need to remove whitespace, unfortunately
|
|
|
|
|
# Windows programs use \r but Unix programs use \n
|
|
|
|
|
|
2019-02-14 06:17:10 +00:00
|
|
|
|
echo Running native-built program natively
|
|
|
|
|
|
2018-07-21 02:43:55 +00:00
|
|
|
|
# find expected value natively
|
|
|
|
|
${getExecutable hostPkgs pkgFun exec} ${args'} \
|
|
|
|
|
| dos2unix > $out/expected
|
|
|
|
|
|
2019-02-14 06:17:10 +00:00
|
|
|
|
echo Running cross-built program in emulator
|
|
|
|
|
|
2018-07-21 02:43:55 +00:00
|
|
|
|
# run emulator to get actual value
|
|
|
|
|
${emulator} ${getExecutable crossPkgs pkgFun exec} ${args'} \
|
|
|
|
|
| dos2unix > $out/actual
|
|
|
|
|
|
2019-02-14 06:17:10 +00:00
|
|
|
|
echo Comparing results...
|
|
|
|
|
|
2018-07-21 02:43:55 +00:00
|
|
|
|
if [ "$(cat $out/actual)" != "$(cat $out/expected)" ]; then
|
|
|
|
|
echo "${pkgName} did not output expected value:"
|
|
|
|
|
cat $out/expected
|
|
|
|
|
echo "instead it output:"
|
|
|
|
|
cat $out/actual
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
echo "${pkgName} test passed"
|
|
|
|
|
echo "both produced output:"
|
|
|
|
|
cat $out/actual
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
|
2019-02-26 03:54:40 +00:00
|
|
|
|
mapMultiPlatformTest = crossSystemFun: test: lib.mapAttrs (name: system: test rec {
|
2018-11-13 22:54:08 +00:00
|
|
|
|
crossPkgs = import pkgs.path {
|
2023-01-09 03:36:01 +00:00
|
|
|
|
localSystem = { inherit (pkgs.stdenv.hostPlatform) config; };
|
2019-02-26 03:54:40 +00:00
|
|
|
|
crossSystem = crossSystemFun system;
|
2018-11-13 22:54:08 +00:00
|
|
|
|
};
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
2023-11-03 22:32:06 +00:00
|
|
|
|
emulator = crossPkgs.stdenv.hostPlatform.emulator pkgs;
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
2018-11-13 22:54:08 +00:00
|
|
|
|
# Apply some transformation on windows to get dlls in the right
|
|
|
|
|
# place. Unfortunately mingw doesn’t seem to be able to do linking
|
|
|
|
|
# properly.
|
2023-11-03 22:32:06 +00:00
|
|
|
|
platformFun = pkg: if crossPkgs.stdenv.hostPlatform.isWindows then
|
2018-11-13 22:54:08 +00:00
|
|
|
|
pkgs.buildEnv {
|
|
|
|
|
name = "${pkg.name}-winlinks";
|
|
|
|
|
paths = [pkg] ++ pkg.buildInputs;
|
|
|
|
|
} else pkg;
|
|
|
|
|
}) testedSystems;
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
2019-02-26 03:54:40 +00:00
|
|
|
|
tests = {
|
|
|
|
|
|
|
|
|
|
file = {platformFun, crossPkgs, emulator}: compareTest {
|
|
|
|
|
inherit emulator crossPkgs;
|
|
|
|
|
hostPkgs = pkgs;
|
|
|
|
|
exec = "/bin/file";
|
|
|
|
|
args = [
|
|
|
|
|
"${pkgs.file}/share/man/man1/file.1.gz"
|
|
|
|
|
"${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuMathTeXGyre.ttf"
|
|
|
|
|
];
|
|
|
|
|
pkgFun = pkgs: platformFun pkgs.file;
|
|
|
|
|
};
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
2019-02-26 03:54:40 +00:00
|
|
|
|
hello = {platformFun, crossPkgs, emulator}: compareTest {
|
|
|
|
|
inherit emulator crossPkgs;
|
|
|
|
|
hostPkgs = pkgs;
|
|
|
|
|
exec = "/bin/hello";
|
|
|
|
|
pkgFun = pkgs: pkgs.hello;
|
|
|
|
|
};
|
2018-07-21 02:43:55 +00:00
|
|
|
|
|
2020-04-28 02:39:58 +00:00
|
|
|
|
pkg-config = {platformFun, crossPkgs, emulator}: crossPkgs.runCommand
|
2023-11-03 22:32:06 +00:00
|
|
|
|
"test-pkg-config-${crossPkgs.stdenv.hostPlatform.config}"
|
2020-04-28 02:39:58 +00:00
|
|
|
|
{
|
|
|
|
|
depsBuildBuild = [ crossPkgs.pkgsBuildBuild.pkg-config ];
|
|
|
|
|
nativeBuildInputs = [ crossPkgs.pkgsBuildHost.pkg-config crossPkgs.buildPackages.zlib ];
|
|
|
|
|
depsBuildTarget = [ crossPkgs.pkgsBuildTarget.pkg-config ];
|
|
|
|
|
buildInputs = [ crossPkgs.zlib ];
|
|
|
|
|
NIX_DEBUG = 7;
|
|
|
|
|
} ''
|
|
|
|
|
mkdir $out
|
|
|
|
|
${crossPkgs.pkgsBuildBuild.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-build"
|
|
|
|
|
${crossPkgs.pkgsBuildHost.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-host"
|
|
|
|
|
! diff "$out/for-build" "$out/for-host"
|
|
|
|
|
'';
|
2018-11-13 22:54:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-06-30 00:52:08 +00:00
|
|
|
|
# see https://github.com/NixOS/nixpkgs/issues/213453
|
|
|
|
|
# this is a good test of a lot of tricky glibc/libgcc corner cases
|
|
|
|
|
mbuffer = let
|
|
|
|
|
mbuffer = pkgs.pkgsCross.aarch64-multiplatform.mbuffer;
|
|
|
|
|
emulator = with lib.systems; (elaborate examples.aarch64-multiplatform).emulator pkgs;
|
|
|
|
|
in
|
|
|
|
|
pkgs.runCommand "test-mbuffer" {} ''
|
|
|
|
|
echo hello | ${emulator} ${mbuffer}/bin/mbuffer
|
2023-08-08 09:06:04 +00:00
|
|
|
|
touch $out
|
2023-06-30 00:52:08 +00:00
|
|
|
|
'';
|
2023-06-30 08:58:19 +00:00
|
|
|
|
|
|
|
|
|
# This is meant to be a carefully curated list of builds/packages
|
|
|
|
|
# that tend to break when refactoring our cross-compilation
|
|
|
|
|
# infrastructure.
|
|
|
|
|
#
|
|
|
|
|
# It should strike a balance between being small enough to fit in
|
|
|
|
|
# a single eval (i.e. not so large that hydra-eval-jobs is needed)
|
|
|
|
|
# so we can ask @ofborg to check it, yet should have good examples
|
|
|
|
|
# of things that often break. So, no buckshot `mapTestOnCross`
|
|
|
|
|
# calls here.
|
|
|
|
|
sanity = [
|
2023-08-08 09:06:04 +00:00
|
|
|
|
mbuffer
|
2023-06-30 08:58:19 +00:00
|
|
|
|
#pkgs.pkgsCross.gnu64.bash # https://github.com/NixOS/nixpkgs/issues/243164
|
|
|
|
|
pkgs.gcc_multi.cc
|
|
|
|
|
pkgs.pkgsMusl.stdenv
|
|
|
|
|
pkgs.pkgsLLVM.stdenv
|
|
|
|
|
pkgs.pkgsStatic.bash
|
2023-11-02 10:40:19 +00:00
|
|
|
|
#pkgs.pkgsCross.gnu64_simplekernel.bash # https://github.com/NixOS/nixpkgs/issues/264989
|
2023-06-30 08:58:19 +00:00
|
|
|
|
pkgs.pkgsCross.arm-embedded.stdenv
|
2023-08-16 02:11:09 +00:00
|
|
|
|
pkgs.pkgsCross.sheevaplug.stdenv # for armv5tel
|
|
|
|
|
pkgs.pkgsCross.raspberryPi.stdenv # for armv6l
|
2023-08-14 20:34:42 +00:00
|
|
|
|
pkgs.pkgsCross.armv7l-hf-multiplatform.stdenv
|
2023-07-01 23:34:00 +00:00
|
|
|
|
pkgs.pkgsCross.m68k.stdenv
|
2023-06-30 08:58:19 +00:00
|
|
|
|
pkgs.pkgsCross.aarch64-multiplatform.pkgsBuildTarget.gcc
|
2023-07-06 10:24:33 +00:00
|
|
|
|
pkgs.pkgsCross.powernv.pkgsBuildTarget.gcc
|
2023-10-23 08:48:18 +00:00
|
|
|
|
pkgs.pkgsCross.s390.stdenv
|
2023-06-30 08:58:19 +00:00
|
|
|
|
pkgs.pkgsCross.mips64el-linux-gnuabi64.stdenv
|
|
|
|
|
pkgs.pkgsCross.mips64el-linux-gnuabin32.stdenv
|
|
|
|
|
pkgs.pkgsCross.mingwW64.stdenv
|
2024-03-29 10:05:19 +00:00
|
|
|
|
# Uses the expression that is used by the most cross-compil_ed_ GHCs
|
|
|
|
|
pkgs.pkgsCross.riscv64.haskell.compiler.native-bignum.ghc948
|
2023-11-03 04:29:09 +00:00
|
|
|
|
|
|
|
|
|
] ++ lib.optionals (with pkgs.stdenv.buildPlatform; isx86_64 && isLinux) [
|
|
|
|
|
# Musl-to-glibc cross on the same architecture tends to turn up
|
|
|
|
|
# lots of interesting corner cases. Only expected to work for
|
|
|
|
|
# x86_64-linux buildPlatform.
|
|
|
|
|
pkgs.pkgsMusl.pkgsCross.gnu64.hello
|
2023-11-04 21:55:44 +00:00
|
|
|
|
|
|
|
|
|
# Two web browsers -- exercises almost the entire packageset
|
2024-01-25 10:47:49 +00:00
|
|
|
|
pkgs.pkgsCross.aarch64-multiplatform.qutebrowser-qt5
|
2023-11-04 21:55:44 +00:00
|
|
|
|
pkgs.pkgsCross.aarch64-multiplatform.firefox
|
2023-11-17 04:00:22 +00:00
|
|
|
|
|
|
|
|
|
# Uses pkgsCross.riscv64-embedded; see https://github.com/NixOS/nixpkgs/issues/267859
|
|
|
|
|
pkgs.spike
|
2023-06-30 08:58:19 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
gcc = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = false;})) tests);
|
|
|
|
|
llvm = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = true;})) tests);
|
|
|
|
|
|
|
|
|
|
inherit mbuffer sanity;
|
2019-01-30 02:01:24 +00:00
|
|
|
|
}
|