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