zig/ci/azure/windows_script
2021-04-15 01:22:42 -07:00

114 lines
3.9 KiB
Bash

#!/bin/sh
set -x
set -e
pacman -Suy --needed --noconfirm
pacman -S --needed --noconfirm cmake git ninja wget p7zip python3-pip tar xz
pip install s3cmd
ZIGDIR="$(pwd)"
CACHE_BASENAME="zig+llvm+lld+clang-x86_64-windows-gnu-0.8.0-dev.1951+c59241bda"
PREFIX="$HOME/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig.exe"
cd "$HOME"
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
ln -s "$PREFIX/bin/llvm-ar.exe" "$PREFIX/bin/llvm-ranlib.exe"
cd "$ZIGDIR"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
export CC="$ZIG cc -fno-sanitize=all -target x86_64-windows-gnu -mcpu=native"
export CXX="$ZIG c++ -fno-sanitize=all -target x86_64-windows-gnu -mcpu=native"
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_PREFIX_PATH=$PREFIX" \
"-DCMAKE_INSTALL_PREFIX=$(pwd)/dist" \
-DCMAKE_CROSSCOMPILING=True \
-DCMAKE_SYSTEM_NAME="Windows" \
-DCMAKE_AR="$PREFIX/bin/llvm-ar.exe" \
-DCMAKE_RANLIB="$PREFIX/bin/llvm-ranlib.exe" \
-DZIG_OMIT_STAGE2=ON \
-DZIG_STATIC=ON \
-DZIG_TARGET_TRIPLE="x86_64-windows-gnu" \
-DZIG_TARGET_MCPU="baseline" \
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$(pwd)/dist/bin/zig.exe" -DZIG_TARGET_MCPU="x86_64_v2"
ninja install
dist/bin/zig.exe build test-behavior -Dskip-non-native
# Disabled to prevent OOM
# dist/bin/zig build test-stage2
dist/bin/zig.exe build test-fmt -Dskip-non-native
dist/bin/zig.exe build test-std -Dskip-non-native
dist/bin/zig.exe build test-compiler-rt -Dskip-non-native
dist/bin/zig.exe build test-compare-output -Dskip-non-native
dist/bin/zig.exe build test-standalone -Dskip-non-native
dist/bin/zig.exe build test-stack-traces -Dskip-non-native
dist/bin/zig.exe build test-cli -Dskip-non-native
dist/bin/zig.exe build test-asm-link -Dskip-non-native
dist/bin/zig.exe build test-runtime-safety -Dskip-non-native
dist/bin/zig.exe build test-translate-c -Dskip-non-native
dist/bin/zig.exe build test-run-translated-c -Dskip-non-native
dist/bin/zig.exe build docs
if [ "${BUILD_REASON}" != "PullRequest" ]; then
cd "$ZIGDIR/build"
mv ../LICENSE dist/
mv ../zig-cache/langref.html dist/
mv dist/bin/zig.exe dist/
rmdir dist/bin
VERSION=$(dist/zig.exe version)
DIRNAME="zig-windows-x86_64-$VERSION"
TARBALL="$DIRNAME.zip"
mv dist "$DIRNAME"
7z a "$TARBALL" "$DIRNAME"
# mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="windows-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-windows-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html
set +x
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
fi