authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-10 18:41:29-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-05-10 18:41:29-04:00
log2e4a48ef295fee2180079a01c59b47e47a414efb
tree8de57a99f4a56865c2ec4e0267b87aff2335aaff
parent24dfa61236aba6d1c613f929ef06e67f7ce5ddcf
parentb7a6a251a0a86d5ffa4780bc01515854f7032ccd
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #8736 from ziglang/macos-zig-bootstrap

Use zig-bootstrap to build macOS binaries

2 files changed, 69 insertions(+), 70 deletions(-)

ci/azure/macos_arm64_script+60-60
...@@ -3,24 +3,31 @@...@@ -3,24 +3,31 @@
3set -x3set -x
4set -e4set -e
55
6brew update && brew install s3cmd ninja gnu-tar6brew update && brew install s3cmd
77
8ZIGDIR="$(pwd)"8ZIGDIR="$(pwd)"
9
10HOST_ARCH="x86_64"
11HOST_TARGET="$HOST_ARCH-macos-gnu"
12HOST_MCPU="baseline"
13HOST_CACHE_BASENAME="zig+llvm+lld+clang-$HOST_TARGET-0.8.0-dev.2168+2d1196773"
14HOST_PREFIX="$HOME/$HOST_CACHE_BASENAME"
15
9ARCH="aarch64"16ARCH="aarch64"
10# {product}-{os}{sdk_version}-{arch}-{llvm_version}-{cmake_build_type}17TARGET="$ARCH-macos-gnu"
11CACHE_HOST_BASENAME="ci-llvm-macos10.15-x86_64-12.0.0.1-release"18MCPU="cyclone"
12CACHE_ARM64_BASENAME="ci-llvm-macos11.0-arm64-12.0.0.1-release"19CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2168+2d1196773"
13PREFIX_HOST="$HOME/$CACHE_HOST_BASENAME"20PREFIX="$HOME/$CACHE_BASENAME"
14PREFIX_ARM64="$HOME/$CACHE_ARM64_BASENAME"21
15JOBS="-j2"22JOBS="-j2"
1623
17rm -rf $PREFIX24rm -rf $HOST_PREFIX $PREFIX
18cd $HOME25cd $HOME
19wget -nv "https://ziglang.org/deps/$CACHE_HOST_BASENAME.tar.xz"
20wget -nv "https://ziglang.org/deps/$CACHE_ARM64_BASENAME.tar.xz"
2126
22gtar xf "$CACHE_HOST_BASENAME.tar.xz"27wget -nv "https://ziglang.org/deps/$HOST_CACHE_BASENAME.tar.xz"
23gtar xf "$CACHE_ARM64_BASENAME.tar.xz"28wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
29tar xf "$HOST_CACHE_BASENAME.tar.xz"
30tar xf "$CACHE_BASENAME.tar.xz"
2431
25cd $ZIGDIR32cd $ZIGDIR
2633
...@@ -30,83 +37,75 @@ git config core.abbrev 9...@@ -30,83 +37,75 @@ git config core.abbrev 9
30git fetch --unshallow || true37git fetch --unshallow || true
31git fetch --tags38git fetch --tags
3239
33# Select xcode: latest version found on vmImage macOS-10.15 .40# Build host zig compiler in debug so that we can get the
34DEVELOPER_DIR=/Applications/Xcode_12.4.app41# current version when packaging
3542
36export ZIG_LOCAL_CACHE_DIR="$ZIGDIR/zig-cache"43ZIG="$HOST_PREFIX/bin/zig"
37export ZIG_GLOBAL_CACHE_DIR="$ZIGDIR/zig-cache"
3844
39# Build zig for host and use `Debug` type to make builds a little faster.45export CC="$ZIG cc -target $HOST_TARGET -mcpu=$HOST_MCPU"
46export CXX="$ZIG c++ -target $HOST_TARGET -mcpu=$HOST_MCPU"
4047
41cd $ZIGDIR
42mkdir build.host48mkdir build.host
43cd build.host49cd build.host
44cmake -G "Ninja" .. \50cmake .. \
45 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \51 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
46 -DCMAKE_PREFIX_PATH="$PREFIX_HOST" \52 -DCMAKE_PREFIX_PATH="$HOST_PREFIX" \
47 -DCMAKE_BUILD_TYPE="Debug" \53 -DCMAKE_BUILD_TYPE=Debug \
48 -DZIG_STATIC="OFF"54 -DZIG_TARGET_TRIPLE="$HOST_TARGET" \
4955 -DZIG_TARGET_MCPU="$HOST_MCPU" \
50# Build but do not install.56 -DZIG_STATIC=ON
51ninja $JOBS
5257
53ZIG_EXE="$ZIGDIR/build.host/zig"58make $JOBS install
5459
55# Build zig for arm64 target.60unset CC
56# - use `Release` type for published tarballs61unset CXX
57# - ad-hoc codesign with linker
58# - note: apple quarantine of downloads (eg. via safari) still apply
5962
63# Build zig compiler cross-compiled for arm64
60cd $ZIGDIR64cd $ZIGDIR
61mkdir build.arm6465
62cd build.arm6466ZIG="$ZIGDIR/build.host/release/bin/zig"
63cmake -G "Ninja" .. \67
68export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
69export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
70
71mkdir build
72cd build
73cmake .. \
64 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \74 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
65 -DCMAKE_PREFIX_PATH="$PREFIX_ARM64" \75 -DCMAKE_PREFIX_PATH="$PREFIX" \
66 -DCMAKE_BUILD_TYPE="Release" \76 -DCMAKE_BUILD_TYPE=Release \
67 -DCMAKE_CROSSCOMPILING="True" \77 -DZIG_TARGET_TRIPLE="$TARGET" \
68 -DCMAKE_SYSTEM_NAME="Darwin" \78 -DZIG_TARGET_MCPU="$MCPU" \
69 -DCMAKE_C_FLAGS="-arch arm64" \79 -DZIG_EXECUTABLE="$ZIG" \
70 -DCMAKE_CXX_FLAGS="-arch arm64" \80 -DZIG_STATIC=ON
71 -DCMAKE_EXE_LINKER_FLAGS="-lz -Xlinker -adhoc_codesign" \81
72 -DZIG_USE_LLVM_CONFIG="OFF" \82make $JOBS install
73 -DZIG_EXECUTABLE="$ZIG_EXE" \83
74 -DZIG_TARGET_TRIPLE="${ARCH}-macos" \84unset CC
75 -DZIG_STATIC="OFF"85unset CXX
76
77ninja $JOBS install
78
79# Disable test because binary is foreign arch.
80#release/bin/zig build test
8186
82if [ "${BUILD_REASON}" != "PullRequest" ]; then87if [ "${BUILD_REASON}" != "PullRequest" ]; then
83 mv ../LICENSE release/88 mv ../LICENSE release/
8489
85 # We do not run test suite but still need langref.90 # We do not run test suite but still need langref.
86 mkdir -p release/docs91 mkdir -p release/docs
87 $ZIG_EXE run ../doc/docgen.zig -- $ZIG_EXE ../doc/langref.html.in release/docs/langref.html92 $ZIG run ../doc/docgen.zig -- $ZIG ../doc/langref.html.in release/docs/langref.html
8893
89 # Produce the experimental std lib documentation.94 # Produce the experimental std lib documentation.
90 mkdir -p release/docs/std95 mkdir -p release/docs/std
91 $ZIG_EXE test ../lib/std/std.zig \96 $ZIG test ../lib/std/std.zig \
92 --override-lib-dir ../lib \97 --override-lib-dir ../lib \
93 -femit-docs=release/docs/std \98 -femit-docs=release/docs/std \
94 -fno-emit-bin99 -fno-emit-bin
95100
96 # Remove the unnecessary bin dir in $prefix/bin/zig
97 mv release/bin/zig release/101 mv release/bin/zig release/
98 rmdir release/bin102 rmdir release/bin
99103
100 # Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig104 VERSION=$(../build.host/release/bin/zig version)
101 mv release/lib/zig release/lib2
102 rmdir release/lib
103 mv release/lib2 release/lib
104
105 VERSION=$($ZIG_EXE version)
106 DIRNAME="zig-macos-$ARCH-$VERSION"105 DIRNAME="zig-macos-$ARCH-$VERSION"
107 TARBALL="$DIRNAME.tar.xz"106 TARBALL="$DIRNAME.tar.xz"
108 gtar cJf "$TARBALL" release/ --owner=root --sort=name --transform="s,^release,${DIRNAME},"107 mv release "$DIRNAME"
109 ln "$TARBALL" "$BUILD_ARTIFACTSTAGINGDIRECTORY/."108 tar cfJ "$TARBALL" "$DIRNAME"
110109
111 mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"110 mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
112 s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/111 s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
...@@ -114,12 +113,13 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then...@@ -114,12 +113,13 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
114 SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)113 SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
115 BYTESIZE=$(wc -c < $TARBALL)114 BYTESIZE=$(wc -c < $TARBALL)
116115
117 JSONFILE="tarball.json"116 JSONFILE="macos-$GITBRANCH.json"
118 touch $JSONFILE117 touch $JSONFILE
119 echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE118 echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
120 echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE119 echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
121 echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE120 echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
122121
122 s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
123 s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-macos-$VERSION.json"123 s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-macos-$VERSION.json"
124124
125 # `set -x` causes these variables to be mangled.125 # `set -x` causes these variables to be mangled.
ci/azure/macos_script+9-10
...@@ -7,21 +7,21 @@ brew update && brew install s3cmd...@@ -7,21 +7,21 @@ brew update && brew install s3cmd
77
8ZIGDIR="$(pwd)"8ZIGDIR="$(pwd)"
9ARCH="x86_64"9ARCH="x86_64"
10CACHE_BASENAME="zig+llvm+lld+clang-$ARCH-macos-gnu-0.8.0-dev.1939+5a3ea9bec"10TARGET="$ARCH-macos-gnu"
11MCPU="baseline"
12CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2168+2d1196773"
11PREFIX="$HOME/$CACHE_BASENAME"13PREFIX="$HOME/$CACHE_BASENAME"
12JOBS="-j2"14JOBS="-j2"
1315
14rm -rf $PREFIX16rm -rf $PREFIX
15cd $HOME17cd $HOME
18
16wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"19wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
17tar xf "$CACHE_BASENAME.tar.xz"20tar xf "$CACHE_BASENAME.tar.xz"
1821
19ZIG="$PREFIX/bin/zig"22ZIG="$PREFIX/bin/zig"
20NATIVE_LIBC_TXT="$HOME/native_libc.txt"23export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
21$ZIG libc >"$NATIVE_LIBC_TXT"24export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
22export ZIG_LIBC="$NATIVE_LIBC_TXT"
23export CC="$ZIG cc"
24export CXX="$ZIG c++"
2525
26cd $ZIGDIR26cd $ZIGDIR
2727
...@@ -37,22 +37,21 @@ cmake .. \...@@ -37,22 +37,21 @@ cmake .. \
37 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \37 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
38 -DCMAKE_PREFIX_PATH="$PREFIX" \38 -DCMAKE_PREFIX_PATH="$PREFIX" \
39 -DCMAKE_BUILD_TYPE=Release \39 -DCMAKE_BUILD_TYPE=Release \
40 -DZIG_TARGET_TRIPLE="$ARCH-native-gnu" \40 -DZIG_TARGET_TRIPLE="$TARGET" \
41 -DZIG_TARGET_MCPU="baseline" \41 -DZIG_TARGET_MCPU="$MCPU" \
42 -DZIG_STATIC=ON42 -DZIG_STATIC=ON
4343
44# Now cmake will use zig as the C/C++ compiler. We reset the environment variables44# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
45# so that installation and testing do not get affected by them.45# so that installation and testing do not get affected by them.
46unset CC46unset CC
47unset CXX47unset CXX
48unset ZIG_LIBC
4948
50make $JOBS install49make $JOBS install
5150
52# Here we rebuild zig but this time using the Zig binary we just now produced to51# Here we rebuild zig but this time using the Zig binary we just now produced to
53# build zig1.o rather than relying on the one built with stage0. See52# build zig1.o rather than relying on the one built with stage0. See
54# https://github.com/ziglang/zig/issues/6830 for more details.53# https://github.com/ziglang/zig/issues/6830 for more details.
55cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig" -DZIG_TARGET_MCPU="x86_64_v2"54cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
56make $JOBS install55make $JOBS install
5756
58for step in test-toolchain test-std docs; do57for step in test-toolchain test-std docs; do