Merge pull request #140271 from sternenseemann/executable-cross

stdenv.mkDerivation: be less strict about check execution for cross

authored by

sternenseemann and committed by
GitHub
392b95da 6f044ed7

+66 -27
+5 -2
lib/systems/default.nix
··· 34 34 # Either of these can be losslessly-extracted from `parsed` iff parsing succeeds. 35 35 system = parse.doubleFromSystem final.parsed; 36 36 config = parse.tripleFromSystem final.parsed; 37 - # Determine whether we are compatible with the provided CPU 38 - isCompatible = platform: parse.isCompatible final.parsed.cpu platform.parsed.cpu; 37 + # Determine whether we can execute binaries built for the provided platform. 38 + canExecute = platform: 39 + parse.isCompatible final.parsed.cpu platform.parsed.cpu 40 + && final.parsed.kernel == platform.parsed.kernel; 41 + isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details"; 39 42 # Derived meta-data 40 43 libc = 41 44 /**/ if final.isDarwin then "libSystem"
+6 -13
lib/systems/parse.nix
··· 148 148 # Every CPU is compatible with itself. 149 149 # - (transitivity) 150 150 # If A is compatible with B and B is compatible with C then A is compatible with C. 151 - # - (compatible under multiple endianness) 152 - # CPUs with multiple modes of endianness are pairwise compatible. 151 + # 152 + # Note: Since 22.11 the archs of a mode switching CPU are no longer considered 153 + # pairwise compatible. Mode switching implies that binaries built for A 154 + # and B respectively can't be executed at the same time. 153 155 isCompatible = a: b: with cpuTypes; lib.any lib.id [ 154 156 # x86 155 157 (b == i386 && isCompatible a i486) ··· 191 193 (b == aarch64 && a == armv8a) 192 194 (b == armv8a && isCompatible a aarch64) 193 195 194 - (b == aarch64 && a == aarch64_be) 195 - (b == aarch64_be && isCompatible a aarch64) 196 - 197 196 # PowerPC 198 197 (b == powerpc && isCompatible a powerpc64) 199 - (b == powerpcle && isCompatible a powerpc) 200 - (b == powerpc && a == powerpcle) 201 - (b == powerpc64le && isCompatible a powerpc64) 202 - (b == powerpc64 && a == powerpc64le) 198 + (b == powerpcle && isCompatible a powerpc64le) 203 199 204 200 # MIPS 205 201 (b == mips && isCompatible a mips64) 206 - (b == mips && a == mipsel) 207 - (b == mipsel && isCompatible a mips) 208 - (b == mips64 && a == mips64el) 209 - (b == mips64el && isCompatible a mips64) 202 + (b == mipsel && isCompatible a mips64el) 210 203 211 204 # RISCV 212 205 (b == riscv32 && isCompatible a riscv64)
+29 -4
nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
··· 13 13 <itemizedlist spacing="compact"> 14 14 <listitem> 15 15 <para> 16 - Please remove this line when you add the first item since 17 - docbook requires the section to be non-empty 16 + During cross-compilation, tests are now executed if the test 17 + suite can be executed by the build platform. This is the case 18 + when doing “native” cross-compilation where the build and host 19 + platforms are largely the same, but the nixpkgs’ cross 20 + compilation infrastructure is used, e.g. 21 + <literal>pkgsStatic</literal> and <literal>pkgsLLVM</literal>. 22 + Another possibility is that the build platform is a superset 23 + of the host platform, e.g. when cross-compiling from 24 + <literal>x86_64-unknown-linux</literal> to 25 + <literal>i686-unknown-linux</literal>. The predicate gating 26 + test suite execution is the newly added 27 + <literal>canExecute</literal> predicate: You can e.g. check if 28 + <literal>stdenv.buildPlatform</literal> can execute binaries 29 + built for <literal>stdenv.hostPlatform</literal> (i.e. 30 + produced by <literal>stdenv.cc</literal>) by evaluating 31 + <literal>stdenv.buildPlatform.canExecute stdenv.hostPlatform</literal>. 18 32 </para> 19 33 </listitem> 20 34 </itemizedlist> ··· 35 49 <itemizedlist spacing="compact"> 36 50 <listitem> 37 51 <para> 38 - Please remove this line when you add the first item since 39 - docbook requires the section to be non-empty 52 + The <literal>isCompatible</literal> predicate checking CPU 53 + compatibility is no longer exposed by the platform sets 54 + generated using <literal>lib.systems.elaborate</literal>. In 55 + most cases you will want to use the new 56 + <literal>canExecute</literal> predicate instead which also 57 + considers the kernel / syscall interface. It is briefly 58 + described in the release’s 59 + <link linkend="sec-release-22.11-highlights">highlights 60 + section</link>. 61 + <literal>lib.systems.parse.isCompatible</literal> still 62 + exists, but has changed semantically: Architectures with 63 + differing endianness modes are <emphasis>no longer considered 64 + compatible</emphasis>. 40 65 </para> 41 66 </listitem> 42 67 </itemizedlist>
+18 -2
nixos/doc/manual/release-notes/rl-2211.section.md
··· 6 6 7 7 In addition to numerous new and upgraded packages, this release has the following highlights: 8 8 9 - - Please remove this line when you add the first item since docbook requires the section to be non-empty 9 + - During cross-compilation, tests are now executed if the test suite can be executed 10 + by the build platform. This is the case when doing “native” cross-compilation 11 + where the build and host platforms are largely the same, but the nixpkgs' cross 12 + compilation infrastructure is used, e.g. `pkgsStatic` and `pkgsLLVM`. Another 13 + possibility is that the build platform is a superset of the host platform, e.g. when 14 + cross-compiling from `x86_64-unknown-linux` to `i686-unknown-linux`. 15 + The predicate gating test suite execution is the newly added `canExecute` 16 + predicate: You can e.g. check if `stdenv.buildPlatform` can execute binaries 17 + built for `stdenv.hostPlatform` (i.e. produced by `stdenv.cc`) by evaluating 18 + `stdenv.buildPlatform.canExecute stdenv.hostPlatform`. 10 19 11 20 <!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. --> 12 21 ··· 18 27 19 28 ## Backward Incompatibilities {#sec-release-22.11-incompatibilities} 20 29 21 - - Please remove this line when you add the first item since docbook requires the section to be non-empty 30 + - The `isCompatible` predicate checking CPU compatibility is no longer exposed 31 + by the platform sets generated using `lib.systems.elaborate`. In most cases 32 + you will want to use the new `canExecute` predicate instead which also 33 + considers the kernel / syscall interface. It is briefly described in the 34 + release's [highlights section](#sec-release-22.11-highlights). 35 + `lib.systems.parse.isCompatible` still exists, but has changed semantically: 36 + Architectures with differing endianness modes are *no longer considered compatible*. 37 + 22 38 <!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. --> 23 39 24 40 ## Other Notable Changes {#sec-release-22.11-notable-changes}
+2 -2
pkgs/development/libraries/capnproto/default.nix
··· 17 17 }; 18 18 19 19 nativeBuildInputs = [ cmake ] 20 - ++ lib.optional (!(stdenv.hostPlatform.isCompatible stdenv.buildPlatform)) capnproto; 20 + ++ lib.optional (!(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) capnproto; 21 21 22 - cmakeFlags = lib.optional (!(stdenv.hostPlatform.isCompatible stdenv.buildPlatform)) "-DEXTERNAL_CAPNP"; 22 + cmakeFlags = lib.optional (!(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) "-DEXTERNAL_CAPNP"; 23 23 24 24 # Upstream 77ac9154440bcc216fda1092fd5bb51da62ae09c, modified to apply to v0.9.1. Drop on update. 25 25 patches = lib.optional stdenv.hostPlatform.isMusl ./musl-no-fibers.patch;
+3 -1
pkgs/development/libraries/libffi/default.nix
··· 1 1 { lib, stdenv, fetchurl, fetchpatch 2 2 , autoreconfHook 3 3 4 - , doCheck ? true # test suite depends on dejagnu which cannot be used during bootstrapping 4 + # test suite depends on dejagnu which cannot be used during bootstrapping 5 + # dejagnu also requires tcl which can't be built statically at the moment 6 + , doCheck ? !(stdenv.hostPlatform.isStatic) 5 7 , dejagnu 6 8 }: 7 9
+2 -2
pkgs/stdenv/generic/make-derivation.nix
··· 167 167 let 168 168 # TODO(@oxij, @Ericson2314): This is here to keep the old semantics, remove when 169 169 # no package has `doCheck = true`. 170 - doCheck' = doCheck && stdenv.hostPlatform == stdenv.buildPlatform; 171 - doInstallCheck' = doInstallCheck && stdenv.hostPlatform == stdenv.buildPlatform; 170 + doCheck' = doCheck && stdenv.buildPlatform.canExecute stdenv.hostPlatform; 171 + doInstallCheck' = doInstallCheck && stdenv.buildPlatform.canExecute stdenv.hostPlatform; 172 172 173 173 separateDebugInfo' = separateDebugInfo && stdenv.hostPlatform.isLinux && !(stdenv.hostPlatform.useLLVM or false); 174 174 outputs' = outputs ++ lib.optional separateDebugInfo' "debug";
+1 -1
pkgs/stdenv/linux/default.nix
··· 31 31 # compatible with or current architecture. 32 32 getCompatibleTools = lib.foldl (v: system: 33 33 if v != null then v 34 - else if localSystem.isCompatible (lib.systems.elaborate { inherit system; }) then archLookupTable.${system} 34 + else if localSystem.canExecute (lib.systems.elaborate { inherit system; }) then archLookupTable.${system} 35 35 else null) null (lib.attrNames archLookupTable); 36 36 37 37 archLookupTable = table.${localSystem.libc}