Bootstrap tools for the upcoming new darwin stdenv (not working yet in this stdenv, but will soon)

+338
+284
pkgs/stdenv/darwin/make-bootstrap-tools.nix
··· 1 + {system ? builtins.currentSystem}: 2 + 3 + with import ../../top-level/all-packages.nix {inherit system;}; 4 + 5 + rec { 6 + # We want coreutils without ACL support. 7 + coreutils_ = coreutils.override (orig: { 8 + aclSupport = false; 9 + }); 10 + 11 + build = stdenv.mkDerivation { 12 + name = "build"; 13 + 14 + buildInputs = [nukeReferences cpio]; 15 + 16 + buildCommand = '' 17 + mkdir -p $out/bin $out/lib 18 + 19 + # Our (fake) loader 20 + cp -d ${darwin.dyld}/lib/dyld $out/lib/ 21 + 22 + # C standard library stuff 23 + cp -d ${darwin.Libsystem}/lib/*.o $out/lib/ 24 + cp -d ${darwin.Libsystem}/lib/*.dylib $out/lib/ 25 + cp -d ${darwin.Libsystem}/lib/system/*.dylib $out/lib/ 26 + 27 + # Resolv is actually a link to another package, so let's copy it properly 28 + rm $out/lib/libresolv.9.dylib 29 + cp -L ${darwin.Libsystem}/lib/libresolv.9.dylib $out/lib 30 + 31 + cp -rL ${darwin.Libsystem}/include $out 32 + chmod -R u+w $out/include 33 + cp -rL ${icu}/include* $out/include 34 + cp -rL ${libiconv}/include/* $out/include 35 + cp -rL ${gnugrep.pcre}/include/* $out/include 36 + mv $out/include $out/include-Libsystem 37 + 38 + # Copy coreutils, bash, etc. 39 + cp ${coreutils_}/bin/* $out/bin 40 + (cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users) 41 + 42 + cp ${bash}/bin/bash $out/bin 43 + cp ${findutils}/bin/find $out/bin 44 + cp ${findutils}/bin/xargs $out/bin 45 + cp -d ${diffutils}/bin/* $out/bin 46 + cp -d ${gnused}/bin/* $out/bin 47 + cp -d ${gnugrep}/bin/grep $out/bin 48 + cp ${gawk}/bin/gawk $out/bin 49 + cp -d ${gawk}/bin/awk $out/bin 50 + cp ${gnutar}/bin/tar $out/bin 51 + cp ${gzip}/bin/gzip $out/bin 52 + cp ${bzip2}/bin/bzip2 $out/bin 53 + cp -d ${gnumake}/bin/* $out/bin 54 + cp -d ${patch}/bin/* $out/bin 55 + cp -d ${xz}/bin/xz $out/bin 56 + 57 + # This used to be in-nixpkgs, but now is in the bundle 58 + # because I can't be bothered to make it partially static 59 + cp ${curl}/bin/curl $out/bin 60 + cp -d ${curl}/lib/libcurl*.dylib $out/lib 61 + cp -d ${libssh2}/lib/libssh*.dylib $out/lib 62 + cp -d ${openssl}/lib/*.dylib $out/lib 63 + 64 + cp -d ${gnugrep.pcre}/lib/libpcre*.dylib $out/lib 65 + cp -d ${libiconv}/lib/libiconv*.dylib $out/lib 66 + 67 + # Copy what we need of clang 68 + cp -d ${llvmPackages.clang}/bin/clang $out/bin 69 + cp -d ${llvmPackages.clang}/bin/clang++ $out/bin 70 + cp -d ${llvmPackages.clang}/bin/clang-3.5 $out/bin 71 + 72 + cp -rL ${llvmPackages.clang}/lib/clang $out/lib 73 + 74 + cp -d ${libcxx}/lib/libc++*.dylib $out/lib 75 + cp -d ${libcxxabi}/lib/libc++abi*.dylib $out/lib 76 + 77 + mkdir $out/include 78 + cp -rd ${libcxx}/include/c++ $out/include 79 + 80 + cp -d ${icu}/lib/libicu*.dylib $out/lib 81 + cp -d ${zlib}/lib/libz.* $out/lib 82 + cp -d ${gmpxx}/lib/libgmp*.* $out/lib 83 + cp -d ${xz}/lib/liblzma*.* $out/lib 84 + 85 + # Copy binutils. 86 + for i in as ld ar ranlib nm strip otool install_name_tool dsymutil; do 87 + cp ${darwin.cctools}/bin/$i $out/bin 88 + done 89 + 90 + cp -rd ${pkgs.darwin.CF}/Library $out 91 + 92 + chmod -R u+w $out 93 + 94 + nuke-refs $out/bin/* 95 + 96 + rpathify() { 97 + local libs=$(${darwin.cctools}/bin/otool -L "$1" | tail -n +2 | grep -o "$NIX_STORE.*-\S*") || true 98 + for lib in $libs; do 99 + ${darwin.cctools}/bin/install_name_tool -change $lib "@rpath/$(basename $lib)" "$1" 100 + done 101 + } 102 + 103 + fix_dyld() { 104 + # This is clearly a hack. Once we have an install_name_tool-alike that can patch dyld, this will be nicer. 105 + ${perl}/bin/perl -i -0777 -pe 's/\/nix\/store\/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-dyld-239\.4\/lib\/dyld/\/usr\/lib\/dyld\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/sg' "$1" 106 + } 107 + 108 + # Strip executables even further 109 + for i in $out/bin/*; do 110 + if test -x $i -a ! -L $i; then 111 + chmod +w $i 112 + 113 + fix_dyld $i 114 + strip $i || true 115 + fi 116 + done 117 + 118 + for i in $out/bin/* $out/lib/*.dylib $out/lib/clang/3.5.0/lib/darwin/*.dylib $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation; do 119 + if test -x $i -a ! -L $i; then 120 + echo "Adding rpath to $i" 121 + rpathify $i 122 + fi 123 + done 124 + 125 + nuke-refs $out/lib/* 126 + nuke-refs $out/lib/clang/3.5.0/lib/darwin/* 127 + nuke-refs $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation 128 + 129 + mkdir $out/.pack 130 + mv $out/* $out/.pack 131 + mv $out/.pack $out/pack 132 + 133 + mkdir $out/on-server 134 + (cd $out/pack && (find | cpio -o -H newc)) | bzip2 > $out/on-server/bootstrap-tools.cpio.bz2 135 + 136 + mkdir $out/in-nixpkgs 137 + cp ${stdenv.shell} $out/in-nixpkgs/sh 138 + cp ${cpio}/bin/cpio $out/in-nixpkgs 139 + cp ${coreutils_}/bin/mkdir $out/in-nixpkgs 140 + cp ${bzip2}/bin/bzip2 $out/in-nixpkgs 141 + 142 + chmod u+w $out/in-nixpkgs/* 143 + strip $out/in-nixpkgs/* 144 + nuke-refs $out/in-nixpkgs/* 145 + 146 + for i in $out/in-nixpkgs/*; do 147 + fix_dyld $i 148 + done 149 + ''; 150 + 151 + allowedReferences = []; 152 + }; 153 + 154 + host = stdenv.mkDerivation { 155 + name = "host"; 156 + 157 + buildCommand = '' 158 + mkdir -p $out/nix-support 159 + 160 + for i in "${build}/on-server/"*; do 161 + echo "file binary-dist $i" >> $out/nix-support/hydra-build-products 162 + done 163 + 164 + echo "darwin-bootstrap-tools-$(date +%Y.%m.%d)" >> $out/nix-support/hydra-release-name 165 + ''; 166 + 167 + allowedReferences = [ build ]; 168 + }; 169 + 170 + unpack = stdenv.mkDerivation { 171 + name = "unpack"; 172 + 173 + # This is by necessity a near-duplicate of unpack-bootstrap-tools.sh. If we refer to it directly, 174 + # we can't make any changes to it due to our testing stdenv depending on it. Think of this as the 175 + # unpack-bootstrap-tools.sh for the next round of bootstrap tools. 176 + # TODO: think through alternate designs, such as hosting this script as an output of the process. 177 + buildCommand = '' 178 + # Unpack the bootstrap tools tarball. 179 + echo Unpacking the bootstrap tools... 180 + $mkdir $out 181 + $bzip2 -d < $tarball | (cd $out && $cpio -i) 182 + 183 + # Set the ELF interpreter / RPATH in the bootstrap binaries. 184 + echo Patching the tools... 185 + 186 + export PATH=$out/bin 187 + 188 + for i in $out/bin/*; do 189 + if ! test -L $i; then 190 + echo patching $i 191 + install_name_tool -add_rpath $out/lib $i || true 192 + fi 193 + done 194 + 195 + for i in $out/lib/*.dylib $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation; do 196 + if ! test -L $i; then 197 + echo patching $i 198 + 199 + id=$(otool -D "$i" | tail -n 1) 200 + install_name_tool -id "$(dirname $i)/$(basename $id)" $i 201 + 202 + libs=$(otool -L "$i" | tail -n +2 | grep -v Libsystem | cat) 203 + if [ -n "$libs" ]; then 204 + install_name_tool -add_rpath $out/lib $i 205 + fi 206 + fi 207 + done 208 + 209 + ln -s bash $out/bin/sh 210 + ln -s bzip2 $out/bin/bunzip2 211 + 212 + cat >$out/bin/dsymutil << EOF 213 + #!$out/bin/sh 214 + EOF 215 + ''; 216 + 217 + tarball = "${build}/on-server/bootstrap-tools.cpio.bz2"; 218 + 219 + mkdir = "${build}/in-nixpkgs/mkdir"; 220 + bzip2 = "${build}/in-nixpkgs/bzip2"; 221 + cpio = "${build}/in-nixpkgs/cpio"; 222 + 223 + allowedReferences = [ "out" ]; 224 + }; 225 + 226 + test = stdenv.mkDerivation { 227 + name = "test"; 228 + 229 + realBuilder = "${unpack}/bin/bash"; 230 + 231 + buildCommand = '' 232 + export PATH=${unpack}/bin 233 + ls -l 234 + mkdir $out 235 + mkdir $out/bin 236 + sed --version 237 + find --version 238 + diff --version 239 + patch --version 240 + make --version 241 + awk --version 242 + grep --version 243 + clang --version 244 + xz --version 245 + 246 + # The grep will return a nonzero exit code if there is no match, and we want to assert that we have 247 + # an SSL-capable curl 248 + curl --version | grep SSL 249 + 250 + ${build}/in-nixpkgs/sh -c 'echo Hello World' 251 + 252 + export flags="-idirafter ${unpack}/include-Libsystem --sysroot=${unpack} -L${unpack}/lib" 253 + 254 + export CPP="clang -E $flags" 255 + export CC="clang $flags -Wl,-rpath,${unpack}/lib -Wl,-v" 256 + export CXX="clang++ $flags --stdlib=libc++ -lc++abi -isystem${unpack}/include/c++/v1 -Wl,-rpath,${unpack}/lib -Wl,-v" 257 + 258 + echo '#include <stdio.h>' >> foo.c 259 + echo '#include <float.h>' >> foo.c 260 + echo '#include <limits.h>' >> foo.c 261 + echo 'int main() { printf("Hello World\n"); return 0; }' >> foo.c 262 + $CC -o $out/bin/foo foo.c 263 + $out/bin/foo 264 + 265 + echo '#include <CoreFoundation/CoreFoundation.h>' >> bar.c 266 + echo 'int main() { CFShow(CFSTR("Hullo")); return 0; }' >> bar.c 267 + $CC -F${unpack}/Library/Frameworks -framework CoreFoundation -o $out/bin/bar bar.c 268 + $out/bin/bar 269 + 270 + echo '#include <iostream>' >> bar.cc 271 + echo 'int main() { std::cout << "Hello World\n"; }' >> bar.cc 272 + $CXX -v -o $out/bin/bar bar.cc 273 + $out/bin/bar 274 + 275 + tar xvf ${hello.src} 276 + cd hello-* 277 + ./configure --prefix=$out 278 + make 279 + make install 280 + 281 + $out/bin/hello 282 + ''; 283 + }; 284 + }
+54
pkgs/stdenv/darwin/unpack-bootstrap-tools.sh
··· 1 + set -e 2 + 3 + # Unpack the bootstrap tools tarball. 4 + echo Unpacking the bootstrap tools... 5 + $mkdir $out 6 + $bzip2 -d < $tarball | (cd $out && $cpio -i) 7 + 8 + # Set the ELF interpreter / RPATH in the bootstrap binaries. 9 + echo Patching the tools... 10 + 11 + export PATH=$out/bin 12 + 13 + for i in $out/bin/*; do 14 + if ! test -L $i; then 15 + echo patching $i 16 + install_name_tool -add_rpath $out/lib $i || true 17 + fi 18 + done 19 + 20 + for i in $out/lib/*.dylib $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation; do 21 + if ! test -L $i; then 22 + echo patching $i 23 + 24 + id=$(otool -D "$i" | tail -n 1) 25 + install_name_tool -id "$(dirname $i)/$(basename $id)" $i 26 + 27 + libs=$(otool -L "$i" | tail -n +2 | grep -v libSystem | cat) 28 + if [ -n "$libs" ]; then 29 + install_name_tool -add_rpath $out/lib $i 30 + fi 31 + fi 32 + done 33 + 34 + ln -s bash $out/bin/sh 35 + ln -s bzip2 $out/bin/bunzip2 36 + 37 + # Provide a gunzip script. 38 + cat > $out/bin/gunzip <<EOF 39 + #!$out/bin/sh 40 + exec $out/bin/gzip -d "\$@" 41 + EOF 42 + chmod +x $out/bin/gunzip 43 + 44 + # Provide fgrep/egrep. 45 + echo "#! $out/bin/sh" > $out/bin/egrep 46 + echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep 47 + echo "#! $out/bin/sh" > $out/bin/fgrep 48 + echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep 49 + 50 + cat >$out/bin/dsymutil << EOF 51 + #!$out/bin/sh 52 + EOF 53 + 54 + chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/dsymutil