Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at python-updates 329 lines 11 kB view raw
1/* 2 This file defines some basic smoke tests for cross compilation. 3 Individual jobs can be tested by running: 4 5 $ nix-build pkgs/top-level/release-cross.nix -A <jobname>.<package> --arg supportedSystems '[builtins.currentSystem]' 6 7 e.g. 8 9 $ nix-build pkgs/top-level/release-cross.nix -A crossMingw32.nix --arg supportedSystems '[builtins.currentSystem]' 10 11 To build all of the bootstrapFiles bundles on every enabled platform, use: 12 13 $ nix-build --expr 'with import ./pkgs/top-level/release-cross.nix {supportedSystems = [builtins.currentSystem];}; builtins.mapAttrs (k: v: v.build) bootstrapTools' 14*/ 15 16{ 17 # The platforms *from* which we cross compile. 18 supportedSystems ? [ 19 "x86_64-linux" 20 "aarch64-linux" 21 "aarch64-darwin" 22 ], 23 # Strip most of attributes when evaluating to spare memory usage 24 scrubJobs ? true, 25 # Attributes passed to nixpkgs. Don't build packages marked as unfree. 26 nixpkgsArgs ? { 27 config = { 28 allowAliases = false; 29 allowUnfree = false; 30 inHydra = true; 31 }; 32 __allowFileset = false; 33 }, 34}: 35 36let 37 release-lib = import ./release-lib.nix { 38 inherit supportedSystems scrubJobs nixpkgsArgs; 39 }; 40 41 inherit (release-lib) 42 all 43 assertTrue 44 darwin 45 forMatchingSystems 46 hydraJob' 47 linux 48 mapTestOnCross 49 pkgsForCross 50 unix 51 ; 52 53 inherit (release-lib.lib) 54 mapAttrs 55 addMetaAttrs 56 elem 57 getAttrFromPath 58 isDerivation 59 maintainers 60 mapAttrsRecursive 61 mapAttrsRecursiveCond 62 recursiveUpdate 63 systems 64 ; 65 66 inherit (release-lib.lib.attrsets) 67 removeAttrs 68 ; 69 70 nativePlatforms = all; 71 72 embedded = { 73 buildPackages.binutils = nativePlatforms; 74 buildPackages.gcc = nativePlatforms; 75 libc = nativePlatforms; 76 }; 77 78 common = { 79 buildPackages.binutils = nativePlatforms; 80 gmp = nativePlatforms; 81 libc = nativePlatforms; 82 nix = nativePlatforms; 83 nixVersions.git = nativePlatforms; 84 mesa = nativePlatforms; 85 rustc = nativePlatforms; 86 cargo = nativePlatforms; 87 }; 88 89 gnuCommon = recursiveUpdate common { 90 buildPackages.gcc = nativePlatforms; 91 coreutils = nativePlatforms; 92 haskell.packages.ghcHEAD.hello = nativePlatforms; 93 haskellPackages.hello = nativePlatforms; 94 }; 95 96 linuxCommon = recursiveUpdate gnuCommon { 97 buildPackages.gdb = nativePlatforms; 98 99 bison = nativePlatforms; 100 busybox = nativePlatforms; 101 dropbear = nativePlatforms; 102 ed = nativePlatforms; 103 ncurses = nativePlatforms; 104 patch = nativePlatforms; 105 }; 106 107 windowsCommon = recursiveUpdate gnuCommon { 108 boehmgc = nativePlatforms; 109 libffi = nativePlatforms; 110 libtool = nativePlatforms; 111 libunistring = nativePlatforms; 112 windows.pthreads = nativePlatforms; 113 }; 114 115 wasiCommon = { 116 gmp = nativePlatforms; 117 boehmgc = nativePlatforms; 118 hello = nativePlatforms; 119 zlib = nativePlatforms; 120 }; 121 122 darwinCommon = { 123 buildPackages.binutils = darwin; 124 }; 125 126 rpiCommon = linuxCommon // { 127 vim = nativePlatforms; 128 unzip = nativePlatforms; 129 ddrescue = nativePlatforms; 130 lynx = nativePlatforms; 131 patchelf = nativePlatforms; 132 buildPackages.binutils = nativePlatforms; 133 mpg123 = nativePlatforms; 134 }; 135 136 # Enabled-but-unsupported platforms for which nix is known to build. 137 # We provide Hydra-built `nixStatic` for these platforms. This 138 # allows users to bootstrap their own system without either (a) 139 # trusting binaries from a non-Hydra source or (b) having to fight 140 # with their host distribution's versions of nix's numerous 141 # build dependencies. 142 nixCrossStatic = { 143 nixStatic = linux; # no need for buildPlatform=*-darwin 144 }; 145 146in 147 148{ 149 # These derivations from a cross package set's `buildPackages` should be 150 # identical to their vanilla equivalents --- none of these package should 151 # observe the target platform which is the only difference between those 152 # package sets. 153 ensureUnaffected = 154 let 155 # Absurd values are fine here, as we are not building anything. In fact, 156 # there probably a good idea to try to be "more parametric" --- i.e. avoid 157 # any special casing. 158 crossSystem = { 159 config = "mips64el-apple-windows-gnu"; 160 libc = "glibc"; 161 }; 162 163 # Converting to a string (drv path) before checking equality is probably a 164 # good idea lest there be some irrelevant pass-through debug attrs that 165 # cause false negatives. 166 testEqualOne = 167 path: system: 168 let 169 f = 170 path: crossSystem: system: 171 toString (getAttrFromPath path (pkgsForCross crossSystem system)); 172 in 173 assertTrue (f path null system == f ([ "buildPackages" ] ++ path) crossSystem system); 174 175 testEqual = path: systems: forMatchingSystems systems (testEqualOne path); 176 177 mapTestEqual = mapAttrsRecursive testEqual; 178 179 in 180 mapTestEqual { 181 boehmgc = nativePlatforms; 182 libffi = nativePlatforms; 183 libiconv = nativePlatforms; 184 libtool = nativePlatforms; 185 zlib = nativePlatforms; 186 readline = nativePlatforms; 187 libxml2 = nativePlatforms; 188 guile = nativePlatforms; 189 }; 190 191 crossIphone64 = mapTestOnCross systems.examples.iphone64 darwinCommon; 192 193 crossIphone32 = mapTestOnCross systems.examples.iphone32 darwinCommon; 194 195 # Test some cross builds to the Sheevaplug 196 crossSheevaplugLinux = mapTestOnCross systems.examples.sheevaplug ( 197 linuxCommon 198 // { 199 ubootSheevaplug = nativePlatforms; 200 } 201 ); 202 203 # Test some cross builds on 32 bit mingw-w64 204 crossMingw32 = mapTestOnCross systems.examples.mingw32 windowsCommon; 205 206 # Test some cross builds on 64 bit mingw-w64 207 crossMingwW64 = mapTestOnCross systems.examples.mingwW64 windowsCommon; 208 209 # Linux on mipsel 210 fuloongminipc = mapTestOnCross systems.examples.fuloongminipc linuxCommon; 211 ben-nanonote = mapTestOnCross systems.examples.ben-nanonote linuxCommon; 212 213 # Javascript 214 ghcjs = mapTestOnCross systems.examples.ghcjs { 215 haskell.packages.ghcjs.hello = nativePlatforms; 216 haskell.packages.native-bignum.ghcHEAD.hello = nativePlatforms; 217 haskellPackages.hello = nativePlatforms; 218 }; 219 220 # Linux on Raspberrypi 221 rpi = mapTestOnCross systems.examples.raspberryPi rpiCommon; 222 rpi-musl = mapTestOnCross systems.examples.muslpi rpiCommon; 223 224 # Linux on the Remarkable 225 remarkable1 = mapTestOnCross systems.examples.remarkable1 linuxCommon; 226 remarkable2 = mapTestOnCross systems.examples.remarkable2 linuxCommon; 227 228 # Linux on armv7l-hf 229 armv7l-hf = mapTestOnCross systems.examples.armv7l-hf-multiplatform linuxCommon; 230 231 pogoplug4 = mapTestOnCross systems.examples.pogoplug4 linuxCommon; 232 233 # Linux on aarch64 234 aarch64 = mapTestOnCross systems.examples.aarch64-multiplatform linuxCommon; 235 aarch64-musl = mapTestOnCross systems.examples.aarch64-multiplatform-musl linuxCommon; 236 237 # Linux on RISCV 238 riscv64 = mapTestOnCross systems.examples.riscv64 linuxCommon; 239 riscv32 = mapTestOnCross systems.examples.riscv32 linuxCommon; 240 241 # Linux on LoongArch 242 loongarch64-linux = mapTestOnCross systems.examples.loongarch64-linux linuxCommon; 243 244 m68k = mapTestOnCross systems.examples.m68k linuxCommon; 245 s390x = mapTestOnCross systems.examples.s390x linuxCommon; 246 247 # (Cross-compiled) Linux on x86 248 x86_64-musl = mapTestOnCross systems.examples.musl64 linuxCommon; 249 x86_64-gnu = mapTestOnCross systems.examples.gnu64 linuxCommon; 250 i686-musl = mapTestOnCross systems.examples.musl32 linuxCommon; 251 i686-gnu = mapTestOnCross systems.examples.gnu32 linuxCommon; 252 253 ppc64le = mapTestOnCross systems.examples.powernv linuxCommon; 254 ppc64le-musl = mapTestOnCross systems.examples.musl-power linuxCommon; 255 256 android64 = mapTestOnCross systems.examples.aarch64-android-prebuilt linuxCommon; 257 android32 = mapTestOnCross systems.examples.armv7a-android-prebuilt linuxCommon; 258 259 wasi32 = mapTestOnCross systems.examples.wasi32 wasiCommon; 260 261 msp430 = mapTestOnCross systems.examples.msp430 embedded; 262 mmix = mapTestOnCross systems.examples.mmix embedded; 263 vc4 = mapTestOnCross systems.examples.vc4 embedded; 264 or1k = mapTestOnCross systems.examples.or1k embedded; 265 avr = mapTestOnCross systems.examples.avr embedded; 266 arm-embedded = mapTestOnCross systems.examples.arm-embedded embedded; 267 arm-embedded-nano = mapTestOnCross systems.examples.arm-embedded-nano embedded; 268 armhf-embedded = mapTestOnCross systems.examples.armhf-embedded embedded; 269 aarch64-embedded = mapTestOnCross systems.examples.aarch64-embedded embedded; 270 aarch64be-embedded = mapTestOnCross systems.examples.aarch64be-embedded embedded; 271 powerpc-embedded = mapTestOnCross systems.examples.ppc-embedded embedded; 272 powerpcle-embedded = mapTestOnCross systems.examples.ppcle-embedded embedded; 273 i686-embedded = mapTestOnCross systems.examples.i686-embedded embedded; 274 x86_64-embedded = mapTestOnCross systems.examples.x86_64-embedded embedded; 275 riscv64-embedded = mapTestOnCross systems.examples.riscv64-embedded embedded; 276 riscv32-embedded = mapTestOnCross systems.examples.riscv32-embedded embedded; 277 rx-embedded = mapTestOnCross systems.examples.rx-embedded embedded; 278 279 x86_64-freebsd = mapTestOnCross systems.examples.x86_64-freebsd common; 280 x86_64-netbsd = mapTestOnCross systems.examples.x86_64-netbsd common; 281 x86_64-openbsd = mapTestOnCross systems.examples.x86_64-openbsd common; 282 283 # we test `embedded` instead of `linuxCommon` because very few packages 284 # successfully cross-compile to Redox so far 285 x86_64-redox = mapTestOnCross systems.examples.x86_64-unknown-redox embedded; 286 287 # Cross-built bootstrap tools for every supported platform 288 bootstrapTools = 289 let 290 linuxTools = import ../stdenv/linux/make-bootstrap-tools-cross.nix { system = "x86_64-linux"; }; 291 freebsdTools = import ../stdenv/freebsd/make-bootstrap-tools-cross.nix { system = "x86_64-linux"; }; 292 linuxMeta = { 293 maintainers = [ maintainers.dezgeg ]; 294 }; 295 freebsdMeta = { 296 maintainers = [ maintainers.rhelmot ]; 297 }; 298 mkBootstrapToolsJob = 299 meta: drv: 300 assert elem drv.system supportedSystems; 301 hydraJob' (addMetaAttrs meta drv); 302 linux = 303 mapAttrsRecursiveCond (as: !isDerivation as) (name: mkBootstrapToolsJob linuxMeta) 304 # The `bootstrapTools.${platform}.bootstrapTools` derivation 305 # *unpacks* the bootstrap-files using their own `busybox` binary, 306 # so it will fail unless buildPlatform.canExecute hostPlatform. 307 # Unfortunately `bootstrapTools` also clobbers its own `system` 308 # attribute, so there is no way to detect this -- we must add it 309 # as a special case. We filter the "test" attribute (only from 310 # *cross*-built bootstrapTools) for the same reason. 311 ( 312 mapAttrs ( 313 _: v: 314 removeAttrs v [ 315 "bootstrapTools" 316 "test" 317 ] 318 ) linuxTools 319 ); 320 freebsd = mapAttrsRecursiveCond (as: !isDerivation as) ( 321 name: mkBootstrapToolsJob freebsdMeta 322 ) freebsdTools; 323 in 324 linux // freebsd; 325 326 # Cross-built nixStatic for platforms for enabled-but-unsupported platforms 327 mips64el-nixCrossStatic = mapTestOnCross systems.examples.mips64el-linux-gnuabi64 nixCrossStatic; 328 powerpc64le-nixCrossStatic = mapTestOnCross systems.examples.powernv nixCrossStatic; 329}