nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 apple-sdk,
5 bootstrapTools,
6 hello,
7}:
8
9derivation {
10 name = "test-bootstrap-tools";
11
12 inherit (stdenv.hostPlatform) system;
13
14 builder = "${bootstrapTools}/bin/bash";
15
16 args = [
17 "-euo"
18 "pipefail"
19 "-c"
20 "eval \"$buildCommand\""
21 ];
22
23 PATH = lib.makeBinPath [ bootstrapTools ];
24
25 tools = bootstrapTools;
26
27 "${stdenv.cc.darwinMinVersionVariable}" = stdenv.cc.darwinMinVersion;
28
29 # Create a pure environment where we use just what's in the bootstrap tools.
30 buildCommand = ''
31 mkdir -p $out/bin
32
33 for exe in $tools/bin/*; do
34 [[ $exe =~ bunzip2|codesign.*|false|install_name_tool|ld|lipo|pbzx|ranlib|sigtool ]] && continue
35 $exe --version > /dev/null || { echo $exe failed >&2; exit 1; }
36 done
37
38 # run all exes that don't take a --version flag
39 bunzip2 -h
40 codesign --help
41 codesign_allocate -i $tools/bin/true -r -o true
42 false || (($? == 1))
43 install_name_tool -id true true
44 ld -v
45 lipo -info true
46 pbzx -v
47 # ranlib gets tested bulding hello
48 sigtool -h
49 rm true
50
51 # The grep will return a nonzero exit code if there is no match, and we want to assert that we have
52 # an SSL-capable curl
53 curl --version | grep SSL
54
55 # The stdenv bootstrap builds the SDK in the bootstrap. Use an existing SDK to test the tools.
56 export SDKROOT='${apple-sdk.sdkroot}'
57
58 export resource_dir="$(echo "$tools"/lib/clang/*)" # Expand wildcard
59 export flags="-resource-dir=$resource_dir -idirafter $SDKROOT/usr/include --sysroot=$SDKROOT -L$SDKROOT/usr/lib -L$tools/lib -DTARGET_OS_IPHONE=0"
60
61 export CPP="clang -E $flags"
62 export CC="clang $flags"
63 export CXX="clang++ $flags --stdlib=libc++ -isystem$tools/include/c++/v1"
64
65 echo '#include <stdio.h>' >> hello1.c
66 echo '#include <float.h>' >> hello1.c
67 echo '#include <limits.h>' >> hello1.c
68 echo 'int main() { printf("Hello World\n"); return 0; }' >> hello1.c
69 $CC -o $out/bin/hello1 hello1.c
70 $out/bin/hello1
71
72 echo '#include <iostream>' >> hello3.cc
73 echo 'int main() { std::cout << "Hello World\n"; }' >> hello3.cc
74 $CXX -v -o $out/bin/hello3 hello3.cc
75 $out/bin/hello3
76
77 # test that libc++.dylib rpaths are correct so it can reference libc++abi.dylib when linked.
78 # using -Wl,-flat_namespace is required to generate an error
79 mkdir libtest/
80 ln -s $tools/lib/libc++.dylib libtest/
81 clang++ -Wl,-flat_namespace -resource-dir=$resource_dir -idirafter $SDKROOT/usr/include -isystem$tools/include/c++/v1 \
82 --sysroot=$SDKROOT -L$SDKROOT/usr/lib -L./libtest -L$PWD/libSystem-boot hello3.cc
83
84 tar xvf ${hello.src}
85 cd hello-*
86 # hello configure detects -liconv is needed but doesn't add to the link step
87 LDFLAGS=-liconv ./configure --prefix=$out
88 make
89 make install
90 $out/bin/hello
91 '';
92}