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-debug' -ItemType Directory
33Set-Location -Path 'build-debug'
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-debug" `
40 -DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
41 -DCMAKE_BUILD_TYPE=Debug `
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-debug\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-release `
62 -Dskip-test-incremental `
63 -Denable-symlinks-windows `
64 --test-timeout 30m
65CheckLastExitCode
66
67Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
68& "stage3-debug\bin\zig.exe" test `
69 ..\test\behavior.zig `
70 --zig-lib-dir "$ZIG_LIB_DIR" `
71 -ofmt=c `
72 -femit-bin="test-x86_64-windows-msvc.c" `
73 --test-no-exec `
74 -target x86_64-windows-msvc `
75 -lc
76CheckLastExitCode
77
78& "stage3-debug\bin\zig.exe" build-obj `
79 --zig-lib-dir "$ZIG_LIB_DIR" `
80 -ofmt=c `
81 -OReleaseSmall `
82 --name compiler_rt `
83 -femit-bin="compiler_rt-x86_64-windows-msvc.c" `
84 --dep build_options `
85 -target x86_64-windows-msvc `
86 -Mroot="..\lib\compiler_rt.zig" `
87 -Mbuild_options="config.zig"
88CheckLastExitCode
89
90Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
91CheckLastExitCode
92
93Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" `
94 -DevCmdArguments '-arch=x64 -no_logo' `
95 -StartInPath $(Get-Location)
96CheckLastExitCode
97
98Write-Output "Build and run behavior tests with msvc..."
99& 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
100CheckLastExitCode
101
102& .\test-x86_64-windows-msvc.exe
103CheckLastExitCode