fork
Configure Feed
Select the types of activity you want to include in your feed.
nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{
2 pkgs,
3 config,
4 lib,
5}:
6
7let
8
9 testedSystems = lib.filterAttrs (
10 name: value:
11 let
12 platform = lib.systems.elaborate value;
13 in
14 platform.isLinux || platform.isWindows
15 ) lib.systems.examples;
16
17 getExecutable =
18 pkgs: pkgFun: exec:
19 "${pkgFun pkgs}${exec}${pkgs.stdenv.hostPlatform.extensions.executable}";
20
21 compareTest =
22 {
23 emulator,
24 pkgFun,
25 hostPkgs,
26 crossPkgs,
27 exec,
28 args ? [ ],
29 }:
30 let
31 pkgName = (pkgFun hostPkgs).name;
32 args' = lib.concatStringsSep " " args;
33 in
34 crossPkgs.runCommand "test-${pkgName}-${crossPkgs.stdenv.hostPlatform.config}"
35 {
36 nativeBuildInputs = [ pkgs.dos2unix ];
37 }
38 ''
39 # Just in case we are using wine, get rid of that annoying extra
40 # stuff.
41 export WINEDEBUG=-all
42
43 HOME=$(pwd)
44 mkdir -p $out
45
46 # We need to remove whitespace, unfortunately
47 # Windows programs use \r but Unix programs use \n
48
49 echo Running native-built program natively
50
51 # find expected value natively
52 ${getExecutable hostPkgs pkgFun exec} ${args'} \
53 | dos2unix > $out/expected
54
55 echo Running cross-built program in emulator
56
57 # run emulator to get actual value
58 ${emulator} ${getExecutable crossPkgs pkgFun exec} ${args'} \
59 | dos2unix > $out/actual
60
61 echo Comparing results...
62
63 if [ "$(cat $out/actual)" != "$(cat $out/expected)" ]; then
64 echo "${pkgName} did not output expected value:"
65 cat $out/expected
66 echo "instead it output:"
67 cat $out/actual
68 exit 1
69 else
70 echo "${pkgName} test passed"
71 echo "both produced output:"
72 cat $out/actual
73 fi
74 '';
75
76 mapMultiPlatformTest =
77 crossSystemFun: test:
78 lib.dontRecurseIntoAttrs (
79 lib.mapAttrs (
80 name: system:
81 lib.recurseIntoAttrs (test rec {
82 crossPkgs = import pkgs.path {
83 localSystem = { inherit (pkgs.stdenv.hostPlatform) config; };
84 crossSystem = crossSystemFun system;
85 inherit config;
86 };
87
88 emulator = crossPkgs.stdenv.hostPlatform.emulator pkgs;
89
90 # Apply some transformation on windows to get dlls in the right
91 # place. Unfortunately mingw doesn’t seem to be able to do linking
92 # properly.
93 platformFun =
94 pkg:
95 if crossPkgs.stdenv.hostPlatform.isWindows then
96 pkgs.buildEnv {
97 name = "${pkg.name}-winlinks";
98 paths = [ pkg ] ++ pkg.buildInputs;
99 }
100 else
101 pkg;
102 })
103 ) testedSystems
104 );
105
106 tests = {
107
108 file =
109 {
110 platformFun,
111 crossPkgs,
112 emulator,
113 }:
114 compareTest {
115 inherit emulator crossPkgs;
116 hostPkgs = pkgs;
117 exec = "/bin/file";
118 args = [
119 "${pkgs.file}/share/man/man1/file.1.gz"
120 "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuMathTeXGyre.ttf"
121 ];
122 pkgFun = pkgs: platformFun pkgs.file;
123 };
124
125 hello =
126 {
127 platformFun,
128 crossPkgs,
129 emulator,
130 }:
131 compareTest {
132 inherit emulator crossPkgs;
133 hostPkgs = pkgs;
134 exec = "/bin/hello";
135 pkgFun = pkgs: pkgs.hello;
136 };
137
138 pkg-config =
139 {
140 platformFun,
141 crossPkgs,
142 emulator,
143 }:
144 crossPkgs.runCommand "test-pkg-config-${crossPkgs.stdenv.hostPlatform.config}"
145 {
146 depsBuildBuild = [ crossPkgs.pkgsBuildBuild.pkg-config ];
147 nativeBuildInputs = [
148 crossPkgs.pkgsBuildHost.pkg-config
149 crossPkgs.buildPackages.zlib
150 ];
151 depsBuildTarget = [ crossPkgs.pkgsBuildTarget.pkg-config ];
152 buildInputs = [ crossPkgs.zlib ];
153 NIX_DEBUG = 7;
154 }
155 ''
156 mkdir $out
157 ${crossPkgs.pkgsBuildBuild.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-build"
158 ${crossPkgs.pkgsBuildHost.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-host"
159 ! diff "$out/for-build" "$out/for-host"
160 '';
161 };
162
163 # see https://github.com/NixOS/nixpkgs/issues/213453
164 # this is a good test of a lot of tricky glibc/libgcc corner cases
165 mbuffer =
166 let
167 mbuffer = pkgs.pkgsCross.aarch64-multiplatform.mbuffer;
168 emulator = with lib.systems; (elaborate examples.aarch64-multiplatform).emulator pkgs;
169 in
170 pkgs.runCommand "test-mbuffer" { } ''
171 echo hello | ${emulator} ${mbuffer}/bin/mbuffer
172 touch $out
173 '';
174
175 # This is meant to be a carefully curated list of builds/packages
176 # that tend to break when refactoring our cross-compilation
177 # infrastructure.
178 #
179 # It should strike a balance between being small enough to fit in
180 # a single eval (i.e. not so large that hydra-eval-jobs is needed)
181 # so we can ask @ofborg to check it, yet should have good examples
182 # of things that often break. So, no buckshot `mapTestOnCross`
183 # calls here.
184 sanity = [
185 mbuffer
186 #pkgs.pkgsCross.gnu64.bash # https://github.com/NixOS/nixpkgs/issues/243164
187 pkgs.gcc_multi.cc
188 pkgs.pkgsMusl.stdenv
189 pkgs.pkgsLLVM.stdenv
190 pkgs.pkgsStatic.bash
191 #pkgs.pkgsCross.gnu64_simplekernel.bash # https://github.com/NixOS/nixpkgs/issues/264989
192 pkgs.pkgsCross.arm-embedded.stdenv
193 pkgs.pkgsCross.sheevaplug.stdenv # for armv5tel
194 pkgs.pkgsCross.raspberryPi.stdenv # for armv6l
195 pkgs.pkgsCross.armv7l-hf-multiplatform.stdenv
196 pkgs.pkgsCross.m68k.stdenv
197 pkgs.pkgsCross.aarch64-multiplatform.pkgsBuildTarget.gcc
198 pkgs.pkgsCross.powernv.pkgsBuildTarget.gcc
199 pkgs.pkgsCross.s390.stdenv
200 pkgs.pkgsCross.mips64el-linux-gnuabi64.stdenv
201 pkgs.pkgsCross.mips64el-linux-gnuabin32.stdenv
202 pkgs.pkgsCross.mingwW64.stdenv
203 # Uses the expression that is used by the most cross-compiled GHCs
204 pkgs.pkgsCross.riscv64.haskell.compiler.native-bignum.ghc948
205
206 ]
207 ++ lib.optionals (with pkgs.stdenv.buildPlatform; isx86_64 && isLinux) [
208 # Musl-to-glibc cross on the same architecture tends to turn up
209 # lots of interesting corner cases. Only expected to work for
210 # x86_64-linux buildPlatform.
211 pkgs.pkgsMusl.pkgsCross.gnu64.hello
212
213 # Two web browsers -- exercises almost the entire packageset
214 pkgs.pkgsCross.aarch64-multiplatform.qutebrowser
215 pkgs.pkgsCross.aarch64-multiplatform.firefox
216
217 # Uses pkgsCross.riscv64-embedded; see https://github.com/NixOS/nixpkgs/issues/267859
218 pkgs.spike
219 ];
220
221in
222{
223 gcc = lib.recurseIntoAttrs (
224 lib.mapAttrs (_: mapMultiPlatformTest (system: system // { useLLVM = false; })) tests
225 );
226 llvm = lib.recurseIntoAttrs (
227 lib.mapAttrs (_: mapMultiPlatformTest (system: system // { useLLVM = true; })) tests
228 );
229
230 inherit mbuffer sanity;
231}