linux bootstrap tools: Use same derivation whether cross compiling or not

+42 -238
+10 -227
pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
··· 1 1 {system ? builtins.currentSystem}: 2 2 3 - let buildFor = toolsArch: ( 4 - 5 3 let 6 - lib = import ../../../lib; 7 - pkgsFun = import ../../..; 8 - 9 - inherit (lib.systems.examples) 10 - sheevaplug raspberryPi armv7l-hf-multiplatform 11 - aarch64-multiplatform scaleway-c1 pogoplug4; 12 - 13 - selectedCrossSystem = 14 - if toolsArch == "armv5tel" then sheevaplug else 15 - if toolsArch == "scaleway" then scaleway-c1 else 16 - if toolsArch == "pogoplug4" then pogoplug4 else 17 - if toolsArch == "armv6l" then raspberryPi else 18 - if toolsArch == "armv7l" then armv7l-hf-multiplatform else 19 - if toolsArch == "aarch64" then aarch64-multiplatform else null; 20 - 21 - pkgs = pkgsFun ({ inherit system; crossSystem = selectedCrossSystem; }); 22 - 23 - glibc = pkgs.libcCross; 24 - bash = pkgs.bash; 25 - findutils = pkgs.findutils; 26 - diffutils = pkgs.diffutils; 27 - gnused = pkgs.gnused; 28 - gnugrep = pkgs.gnugrep; 29 - gawk = pkgs.gawk; 30 - gzip = pkgs.gzip; 31 - bzip2 = pkgs.bzip2; 32 - gnumake = pkgs.gnumake; 33 - patch = pkgs.patch; 34 - patchelf = pkgs.patchelf; 35 - gcc = pkgs.gcc.cc; 36 - gmpxx = pkgs.gmpxx; 37 - mpfr = pkgs.mpfr; 38 - zlib = pkgs.zlib; 39 - libmpc = pkgs.libmpc; 40 - binutils = pkgs.binutils; 41 - libelf = pkgs.libelf; 42 - 43 - # Keep these versions in sync with the versions used in the current GCC! 44 - isl = pkgs.isl_0_14; 45 - in 46 - 47 - rec { 48 - 49 - 50 - coreutilsMinimal = pkgs.coreutils.override (args: { 51 - # We want coreutils without ACL/attr support. 52 - aclSupport = false; 53 - attrSupport = false; 54 - # Our tooling currently can't handle scripts in bin/, only ELFs and symlinks. 55 - singleBinary = "symlinks"; 56 - }); 57 - 58 - tarMinimal = pkgs.gnutar.override { acl = null; }; 59 - 60 - busyboxMinimal = pkgs.busybox.override { 61 - useMusl = true; 62 - enableStatic = true; 63 - enableMinimal = true; 64 - extraConfig = '' 65 - CONFIG_ASH y 66 - CONFIG_ASH_BUILTIN_ECHO y 67 - CONFIG_ASH_BUILTIN_TEST y 68 - CONFIG_ASH_OPTIMIZE_FOR_SIZE y 69 - CONFIG_MKDIR y 70 - CONFIG_TAR y 71 - CONFIG_UNXZ y 72 - ''; 4 + make = crossSystem: import ./make-bootstrap-tools.nix { 5 + localSystem = { inherit system; }; 6 + inherit crossSystem; 73 7 }; 74 8 75 - build = 76 - 77 - pkgs.stdenv.mkDerivation { 78 - name = "stdenv-bootstrap-tools-cross"; 79 - crossConfig = pkgs.hostPlatform.config; 80 - 81 - nativeBuildInputs = [ 82 - pkgs.buildPackages.nukeReferences 83 - pkgs.buildPackages.cpio 84 - ]; 85 - 86 - buildCommand = '' 87 - set -x 88 - mkdir -p $out/bin $out/lib $out/libexec 89 - 90 - # Copy what we need of Glibc. 91 - cp -d ${glibc.out}/lib/ld-*.so* $out/lib 92 - cp -d ${glibc.out}/lib/libc*.so* $out/lib 93 - cp -d ${glibc.out}/lib/libc_nonshared.a $out/lib 94 - cp -d ${glibc.out}/lib/libm*.so* $out/lib 95 - cp -d ${glibc.out}/lib/libdl*.so* $out/lib 96 - cp -d ${glibc.out}/lib/librt*.so* $out/lib 97 - cp -d ${glibc.out}/lib/libpthread*.so* $out/lib 98 - cp -d ${glibc.out}/lib/libnsl*.so* $out/lib 99 - cp -d ${glibc.out}/lib/libutil*.so* $out/lib 100 - cp -d ${glibc.out}/lib/libnss*.so* $out/lib 101 - cp -d ${glibc.out}/lib/libresolv*.so* $out/lib 102 - cp -d ${glibc.out}/lib/crt?.o $out/lib 103 - 104 - cp -rL ${glibc.dev}/include $out 105 - chmod -R u+w "$out" 106 - 107 - # glibc can contain linker scripts: find them, copy their deps, 108 - # and get rid of absolute paths (nuke-refs would make them useless) 109 - local lScripts=$(grep --files-with-matches --max-count=1 'GNU ld script' -R "$out/lib") 110 - cp -d -t "$out/lib/" $(cat $lScripts | tr " " "\n" | grep -F '${glibc.out}' | sort -u) 111 - for f in $lScripts; do 112 - substituteInPlace "$f" --replace '${glibc.out}/lib/' "" 113 - done 114 - 115 - # Hopefully we won't need these. 116 - rm -rf $out/include/mtd $out/include/rdma $out/include/sound $out/include/video 117 - find $out/include -name .install -exec rm {} \; 118 - find $out/include -name ..install.cmd -exec rm {} \; 119 - mv $out/include $out/include-glibc 120 - 121 - # Copy coreutils, bash, etc. 122 - cp ${coreutilsMinimal}/bin/* $out/bin 123 - (cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users) 124 - 125 - cp ${bash}/bin/bash $out/bin 126 - cp ${findutils}/bin/find $out/bin 127 - cp ${findutils}/bin/xargs $out/bin 128 - cp -d ${diffutils}/bin/* $out/bin 129 - cp -d ${gnused}/bin/* $out/bin 130 - cp -d ${gnugrep}/bin/grep $out/bin 131 - cp ${gawk}/bin/gawk $out/bin 132 - cp -d ${gawk}/bin/awk $out/bin 133 - cp ${tarMinimal}/bin/tar $out/bin 134 - cp ${gzip}/bin/gzip $out/bin 135 - cp ${bzip2.bin}/bin/bzip2 $out/bin 136 - cp -d ${gnumake}/bin/* $out/bin 137 - cp -d ${patch}/bin/* $out/bin 138 - cp ${patchelf}/bin/* $out/bin 139 - 140 - cp -d ${gnugrep.pcre.out}/lib/libpcre*.so* $out/lib # needed by grep 141 - 142 - # Copy what we need of GCC. 143 - cp -d ${gcc.out}/bin/gcc $out/bin 144 - cp -d ${gcc.out}/bin/cpp $out/bin 145 - cp -d ${gcc.out}/bin/g++ $out/bin 146 - cp -d ${gcc.lib}/lib*/libgcc_s.so* $out/lib 147 - cp -d ${gcc.lib}/lib*/libstdc++.so* $out/lib 148 - cp -rd ${gcc.out}/lib/gcc $out/lib 149 - chmod -R u+w $out/lib 150 - rm -f $out/lib/gcc/*/*/include*/linux 151 - rm -f $out/lib/gcc/*/*/include*/sound 152 - rm -rf $out/lib/gcc/*/*/include*/root 153 - rm -f $out/lib/gcc/*/*/include-fixed/asm 154 - rm -rf $out/lib/gcc/*/*/plugin 155 - #rm -f $out/lib/gcc/*/*/*.a 156 - cp -rd ${gcc.out}/libexec/* $out/libexec 157 - chmod -R u+w $out/libexec 158 - rm -rf $out/libexec/gcc/*/*/plugin 159 - mkdir $out/include 160 - cp -rd ${gcc.out}/include/c++ $out/include 161 - chmod -R u+w $out/include 162 - rm -rf $out/include/c++/*/ext/pb_ds 163 - rm -rf $out/include/c++/*/ext/parallel 164 - 165 - cp -d ${gmpxx.out}/lib/libgmp*.so* $out/lib 166 - cp -d ${mpfr.out}/lib/libmpfr*.so* $out/lib 167 - cp -d ${libmpc.out}/lib/libmpc*.so* $out/lib 168 - cp -d ${zlib.out}/lib/libz.so* $out/lib 169 - cp -d ${libelf}/lib/libelf.so* $out/lib 170 - 171 - # These needed for cross but not native tools because the stdenv 172 - # GCC has certain things built in statically. See 173 - # pkgs/stdenv/linux/default.nix for the details. 174 - cp -d ${isl}/lib/libisl*.so* $out/lib 175 - 176 - cp -d ${bzip2.out}/lib/libbz2.so* $out/lib 177 - 178 - # Copy binutils. 179 - for i in as ld ar ranlib nm strip readelf objdump; do 180 - cp ${binutils.bintools.out}/bin/$i $out/bin 181 - done 182 - 183 - chmod -R u+w $out 184 - 185 - # Strip executables even further. 186 - for i in $out/bin/* $out/libexec/gcc/*/*/*; do 187 - if test -x $i -a ! -L $i; then 188 - chmod +w $i 189 - $crossConfig-strip -s $i || true 190 - fi 191 - done 192 - 193 - nuke-refs $out/bin/* 194 - nuke-refs $out/lib/* 195 - nuke-refs $out/libexec/gcc/*/*/* 196 - nuke-refs $out/lib/gcc/*/*/* 197 - 198 - mkdir $out/.pack 199 - mv $out/* $out/.pack 200 - mv $out/.pack $out/pack 201 - 202 - mkdir $out/on-server 203 - tar cvfJ $out/on-server/bootstrap-tools.tar.xz --hard-dereference --sort=name --numeric-owner --owner=0 --group=0 --mtime=@1 -C $out/pack . 204 - cp ${busyboxMinimal}/bin/busybox $out/on-server 205 - chmod u+w $out/on-server/busybox 206 - nuke-refs $out/on-server/busybox 207 - ''; # */ 208 - 209 - # The result should not contain any references (store paths) so 210 - # that we can safely copy them out of the store and to other 211 - # locations in the store. 212 - allowedReferences = []; 213 - }; 214 - 215 - dist = pkgs.stdenv.mkDerivation { 216 - name = "stdenv-bootstrap-tools-cross"; 217 - 218 - buildCommand = '' 219 - mkdir -p $out/nix-support 220 - echo "file tarball ${build}/on-server/bootstrap-tools.tar.xz" >> $out/nix-support/hydra-build-products 221 - echo "file busybox ${build}/on-server/busybox" >> $out/nix-support/hydra-build-products 222 - ''; 223 - }; 224 - } 225 - 226 - ); in { 227 - armv5tel = buildFor "armv5tel"; 228 - armv6l = buildFor "armv6l"; 229 - armv7l = buildFor "armv7l"; 230 - aarch64 = buildFor "aarch64"; 231 - scaleway = buildFor "scaleway"; 232 - pogoplug4 = buildFor "pogoplug4"; 9 + in with (import ../../../lib).systems.examples; { 10 + armv5tel = make sheevaplug; 11 + scaleway = make scaleway-c1; 12 + pogoplug4 = make pogoplug4; 13 + armv6l = make raspberryPi; 14 + armv7l = make armv7l-hf-multiplatform; 15 + aarch64 = make aarch64-multiplatform; 233 16 }
+25 -9
pkgs/stdenv/linux/make-bootstrap-tools.nix
··· 1 - { system ? builtins.currentSystem }: 1 + { localSystem ? { system = builtins.currentSystem; } 2 + , crossSystem ? null 3 + }: 2 4 3 - with import ../../.. {inherit system;}; 4 - 5 - rec { 5 + let 6 + pkgs = import ../../.. { inherit localSystem crossSystem; }; 7 + glibc = if pkgs.hostPlatform != pkgs.buildPlatform 8 + then pkgs.glibcCross 9 + else pkgs.glibc; 10 + in with pkgs; rec { 6 11 7 12 8 13 coreutilsMinimal = coreutils.override (args: { ··· 35 40 stdenv.mkDerivation { 36 41 name = "stdenv-bootstrap-tools"; 37 42 38 - buildInputs = [nukeReferences cpio]; 43 + nativeBuildInputs = [ buildPackages.nukeReferences buildPackages.cpio ]; 39 44 40 45 buildCommand = '' 41 46 set -x ··· 118 123 119 124 cp -d ${gmpxx.out}/lib/libgmp*.so* $out/lib 120 125 cp -d ${mpfr.out}/lib/libmpfr*.so* $out/lib 121 - cp -d ${libmpc}/lib/libmpc*.so* $out/lib 126 + cp -d ${libmpc.out}/lib/libmpc*.so* $out/lib 122 127 cp -d ${zlib.out}/lib/libz.so* $out/lib 123 128 cp -d ${libelf}/lib/libelf.so* $out/lib 124 129 130 + '' + lib.optionalString (hostPlatform != buildPlatform) '' 131 + # These needed for cross but not native tools because the stdenv 132 + # GCC has certain things built in statically. See 133 + # pkgs/stdenv/linux/default.nix for the details. 134 + cp -d ${isl_0_14.out}/lib/libisl*.so* $out/lib 135 + 136 + '' + '' 125 137 cp -d ${bzip2.out}/lib/libbz2.so* $out/lib 126 138 127 139 # Copy binutils. ··· 135 147 for i in $out/bin/* $out/libexec/gcc/*/*/*; do 136 148 if test -x $i -a ! -L $i; then 137 149 chmod +w $i 138 - strip -s $i || true 150 + $STRIP -s $i || true 139 151 fi 140 152 done 141 153 142 154 nuke-refs $out/bin/* 143 155 nuke-refs $out/lib/* 144 156 nuke-refs $out/libexec/gcc/*/*/* 157 + nuke-refs $out/lib/gcc/*/*/* 145 158 146 159 mkdir $out/.pack 147 160 mv $out/* $out/.pack ··· 176 189 bootstrapTools = runCommand "bootstrap-tools.tar.xz" {} "cp ${build}/on-server/bootstrap-tools.tar.xz $out"; 177 190 }; 178 191 179 - bootstrapTools = import ./bootstrap-tools { inherit system bootstrapFiles; }; 192 + bootstrapTools = import ./bootstrap-tools { 193 + inherit (hostPlatform) system; 194 + inherit bootstrapFiles; 195 + }; 180 196 181 197 test = derivation { 182 198 name = "test-bootstrap-tools"; 183 - inherit system; 199 + inherit (hostPlatform) system; 184 200 builder = bootstrapFiles.busybox; 185 201 args = [ "ash" "-e" "-c" "eval \"$buildCommand\"" ]; 186 202
+3 -1
pkgs/top-level/release-cross.nix
··· 123 123 bootstrapTools = let 124 124 tools = import ../stdenv/linux/make-bootstrap-tools-cross.nix { system = "x86_64-linux"; }; 125 125 maintainers = [ lib.maintainers.dezgeg ]; 126 - mkBootstrapToolsJob = drv: hydraJob' (lib.addMetaAttrs { inherit maintainers; } drv); 126 + mkBootstrapToolsJob = drv: 127 + assert lib.elem drv.system (supportedSystems ++ [ "aarch64-linux" ]); 128 + hydraJob' (lib.addMetaAttrs { inherit maintainers; } drv); 127 129 in lib.mapAttrsRecursiveCond (as: !lib.isDerivation as) (name: mkBootstrapToolsJob) tools; 128 130 }
+4 -1
pkgs/top-level/release.nix
··· 123 123 stdenvBootstrapTools = with lib; 124 124 genAttrs systemsWithAnySupport 125 125 (system: { 126 - inherit (import ../stdenv/linux/make-bootstrap-tools.nix { inherit system; }) 126 + inherit 127 + (import ../stdenv/linux/make-bootstrap-tools.nix { 128 + localSystem = { inherit system; }; 129 + }) 127 130 dist test; 128 131 }) 129 132 # darwin is special in this