1$TARGET = "x86_64-windows-gnu"
2$MCPU = "baseline"
3$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.17.0-dev.203+073889523"
4$ZIG = "$PREFIX_PATH\bin\zig.exe"
5$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
6
7function CheckLastExitCode {
8 if (!$?) {
9 exit 1
10 }
11 return 0
12}
13
14# Override the cache directories because they won't actually help other CI runs
15# which will be testing alternate versions of zig, and ultimately would just
16# fill up space on the hard drive for no reason.
17$Env:ZIG_GLOBAL_CACHE_DIR="$(Get-Location)\zig-global-cache"
18$Env:ZIG_LOCAL_CACHE_DIR="$(Get-Location)\zig-local-cache"
19
20Write-Output "Building from source..."
21New-Item -Path 'build-release' -ItemType Directory
22Set-Location -Path 'build-release'
23
24# CMake gives a syntax error when file paths with backward slashes are used.
25# Here, we use forward slashes only to work around this.
26cmake .. `
27 -GNinja `
28 -DCMAKE_INSTALL_PREFIX="stage3-release" `
29 -DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
30 -DCMAKE_BUILD_TYPE=Release `
31 -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" `
32 -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" `
33 -DCMAKE_AR="$($ZIG -Replace "\\", "/")" `
34 -DZIG_AR_WORKAROUND=ON `
35 -DZIG_TARGET_TRIPLE="$TARGET" `
36 -DZIG_TARGET_MCPU="$MCPU" `
37 -DZIG_STATIC=ON `
38 -DZIG_NO_LIB=ON
39CheckLastExitCode
40
41ninja install
42CheckLastExitCode
43
44# Must be done after zig cc is finished.
45$Env:ZIG_LIB_DIR="$(Get-Location)\..\lib"
46
47Write-Output "Main test suite..."
48stage3-release\bin\zig.exe build test docs `
49 --maxrss $ZSF_MAX_RSS `
50 --search-prefix "$PREFIX_PATH" `
51 -Dstatic-llvm `
52 -Dskip-non-native `
53 -Dskip-test-incremental `
54 -Denable-symlinks-windows `
55 --test-timeout 30m
56CheckLastExitCode
57
58# Ensure that the fuzzer at least compiles.
59# https://codeberg.org/ziglang/zig/issues/31893
60# stage3-release\bin\zig.exe build test-std --fuzz=1K -Dno-lib -Dfuzz-only -Doptimize=ReleaseSafe
61# CheckLastExitCode
62# stage3-release\bin\zig.exe build test-std --fuzz=1K -Dno-lib -Dfuzz-only -Doptimize=Debug
63# CheckLastExitCode
64
65# Ensure that stage3 and stage4 are byte-for-byte identical.
66Write-Output "Build and compare stage4..."
67stage3-release\bin\zig.exe build `
68 --prefix stage4-release `
69 -Denable-llvm `
70 -Dno-lib `
71 -Doptimize=ReleaseFast `
72 -Dstrip `
73 -Dtarget="$TARGET" `
74 -Duse-zig-libcxx `
75 -Dversion-string="$(stage3-release\bin\zig version)"
76CheckLastExitCode
77
78# Compare-Object returns an error code if the files differ.
79Write-Output "If the following command fails, it means nondeterminism has been"
80Write-Output "introduced, making stage3 and stage4 no longer byte-for-byte identical."
81Compare-Object (Get-Content stage3-release\bin\zig.exe) (Get-Content stage4-release\bin\zig.exe)
82CheckLastExitCode
83
84Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
85stage3-release\bin\zig.exe build-obj `
86 -ofmt=c `
87 -OReleaseSmall `
88 --name compiler_rt `
89 -femit-bin="compiler_rt-x86_64-windows-msvc.c" `
90 -target x86_64-windows-msvc `
91 -lc `
92 ..\lib\compiler_rt.zig
93CheckLastExitCode
94
95stage3-release\bin\zig.exe test `
96 -ofmt=c `
97 -femit-bin="behavior-x86_64-windows-msvc.c" `
98 --test-no-exec `
99 -target x86_64-windows-msvc `
100 -lc `
101 ..\test\behavior.zig
102CheckLastExitCode
103
104Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
105CheckLastExitCode
106
107Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
108 -DevCmdArguments '-arch=x64 -no_logo' `
109 -StartInPath $(Get-Location)
110CheckLastExitCode
111
112Write-Output "Build and run behavior tests with msvc..."
113cl /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib
114CheckLastExitCode
115
116.\behavior-x86_64-windows-msvc
117CheckLastExitCode