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-debug' -ItemType Directory
22Set-Location -Path 'build-debug'
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-debug" `
29 -DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
30 -DCMAKE_BUILD_TYPE=Debug `
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-debug\bin\zig 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
58Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
59stage3-debug\bin\zig build-obj `
60 -ofmt=c `
61 -OReleaseSmall `
62 --name compiler_rt `
63 -femit-bin="compiler_rt-x86_64-windows-msvc.c" `
64 -target x86_64-windows-msvc `
65 -lc `
66 ..\lib\compiler_rt.zig
67CheckLastExitCode
68
69stage3-debug\bin\zig test `
70 -ofmt=c `
71 -femit-bin="behavior-x86_64-windows-msvc.c" `
72 --test-no-exec `
73 -target x86_64-windows-msvc `
74 -lc `
75 ..\test\behavior.zig
76CheckLastExitCode
77
78Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
79CheckLastExitCode
80
81Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
82 -DevCmdArguments '-arch=x64 -no_logo' `
83 -StartInPath $(Get-Location)
84CheckLastExitCode
85
86Write-Output "Build and run behavior tests with msvc..."
87cl /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
88CheckLastExitCode
89
90.\behavior-x86_64-windows-msvc
91CheckLastExitCode