1$TARGET = "aarch64-windows-gnu"
2$MCPU = "baseline"
3$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.18.0-dev.92+1e1964473"
4$ZIG = "$PREFIX_PATH\bin\zig.exe"
5$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
6
7$Env:PATH = "$($Env:USERPROFILE)\local\bin;$Env:PATH"
8
9function CheckLastExitCode {
10 if (!$?) {
11 exit 1
12 }
13 return 0
14}
15
16# Override the cache directories because they won't actually help other CI runs
17# which will be testing alternate versions of zig, and ultimately would just
18# fill up space on the hard drive for no reason.
19$Env:ZIG_GLOBAL_CACHE_DIR="$(Get-Location)\zig-global-cache"
20$Env:ZIG_LOCAL_CACHE_DIR="$(Get-Location)\zig-local-cache"
21
22Write-Output "Building from source..."
23New-Item -Force -Path 'build-release' -ItemType Directory
24Set-Location -Path 'build-release'
25
26# CMake gives a syntax error when file paths with backward slashes are used.
27# Here, we use forward slashes only to work around this.
28cmake .. `
29 -GNinja `
30 -DCMAKE_INSTALL_PREFIX="stage3-release" `
31 -DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
32 -DCMAKE_BUILD_TYPE=Release `
33 -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" `
34 -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" `
35 -DCMAKE_AR="$($ZIG -Replace "\\", "/")" `
36 -DZIG_AR_WORKAROUND=ON `
37 -DZIG_TARGET_TRIPLE="$TARGET" `
38 -DZIG_TARGET_MCPU="$MCPU" `
39 -DZIG_STATIC=ON `
40 -DZIG_NO_LIB=ON
41CheckLastExitCode
42
43ninja install
44CheckLastExitCode
45
46# Must be done after zig cc is finished.
47$Env:ZIG_LIB_DIR="$(Get-Location)\..\lib"
48
49Write-Output "Main test suite..."
50stage3-release\bin\zig.exe build install test docs `
51 --maxrss "$ZSF_MAX_RSS" `
52 --prefix stage4-release `
53 --search-prefix "$PREFIX_PATH" `
54 --test-timeout 30m `
55 -Dversion-string="$(stage3-release\bin\zig.exe version)" `
56 -Dtarget="$TARGET" `
57 -Dcpu="$MCPU" `
58 -Doptimize=ReleaseFast `
59 -Dstrip `
60 -Duse-zig-libcxx `
61 -Denable-llvm `
62 -Dno-lib `
63 -Denable-symlinks-windows `
64 -Dskip-non-native
65CheckLastExitCode
66
67# Ensure that the fuzzer at least compiles.
68# https://codeberg.org/ziglang/zig/issues/31893
69# stage3-release\bin\zig.exe build test-std --fuzz=1K -Dno-lib -Dfuzz-only -Doptimize=ReleaseSafe
70# CheckLastExitCode
71# stage3-release\bin\zig.exe build test-std --fuzz=1K -Dno-lib -Dfuzz-only -Doptimize=Debug
72# CheckLastExitCode
73
74# Ensure that stage3 and stage4 are byte-for-byte identical.
75Write-Output "If the following command fails, it means nondeterminism has been"
76Write-Output "introduced, making stage3 and stage4 no longer byte-for-byte identical."
77Compare-Object (Get-Content stage3-release\bin\zig.exe) (Get-Content stage4-release\bin\zig.exe)
78CheckLastExitCode