| 1 | $TARGET = "aarch64-windows-gnu" |
| 2 | $ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.17.0-dev.203+073889523" |
| 3 | $MCPU = "baseline" |
| 4 | $ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" |
| 5 | $PREFIX_PATH = "$(Get-Location)\..\$ZIG_LLVM_CLANG_LLD_NAME" |
| 6 | $ZIG = "$PREFIX_PATH\bin\zig.exe" |
| 7 | $ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 } |
| 8 | |
| 9 | if (!(Test-Path "..\$ZIG_LLVM_CLANG_LLD_NAME.zip")) { |
| 10 | Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" |
| 11 | Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "..\$ZIG_LLVM_CLANG_LLD_NAME.zip" |
| 12 | |
| 13 | Write-Output "Extracting..." |
| 14 | Add-Type -AssemblyName System.IO.Compression.FileSystem ; |
| 15 | [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\..\$ZIG_LLVM_CLANG_LLD_NAME.zip", "$PWD\..") |
| 16 | } |
| 17 | |
| 18 | function 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 | |
| 31 | Write-Output "Building from source..." |
| 32 | New-Item -Path 'build-release' -ItemType Directory |
| 33 | Set-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" ` |
| 45 | -DZIG_AR_WORKAROUND=ON ` |
| 46 | -DZIG_TARGET_TRIPLE="$TARGET" ` |
| 47 | -DZIG_TARGET_MCPU="$MCPU" ` |
| 48 | -DZIG_STATIC=ON ` |
| 49 | -DZIG_NO_LIB=ON |
| 50 | CheckLastExitCode |
| 51 | |
| 52 | ninja install |
| 53 | CheckLastExitCode |
| 54 | |
| 55 | # Must be done after zig cc is finished. |
| 56 | $Env:ZIG_LIB_DIR="$(Get-Location)\..\lib" |
| 57 | |
| 58 | Write-Output "Main test suite..." |
| 59 | & "stage3-release\bin\zig.exe" build test docs ` |
| 60 | --maxrss $ZSF_MAX_RSS ` |
| 61 | --search-prefix "$PREFIX_PATH" ` |
| 62 | -Dstatic-llvm ` |
| 63 | -Dskip-non-native ` |
| 64 | -Denable-symlinks-windows ` |
| 65 | --test-timeout 30m |
| 66 | CheckLastExitCode |
| 67 | |
| 68 | # Ensure that stage3 and stage4 are byte-for-byte identical. |
| 69 | Write-Output "Build and compare stage4..." |
| 70 | & "stage3-release\bin\zig.exe" build ` |
| 71 | --prefix stage4-release ` |
| 72 | -Denable-llvm ` |
| 73 | -Dno-lib ` |
| 74 | -Doptimize=ReleaseFast ` |
| 75 | -Dstrip ` |
| 76 | -Dtarget="$TARGET" ` |
| 77 | -Duse-zig-libcxx ` |
| 78 | -Dversion-string="$(stage3-release\bin\zig version)" |
| 79 | CheckLastExitCode |
| 80 | |
| 81 | # Compare-Object returns an error code if the files differ. |
| 82 | Write-Output "If the following command fails, it means nondeterminism has been" |
| 83 | Write-Output "introduced, making stage3 and stage4 no longer byte-for-byte identical." |
| 84 | Compare-Object (Get-Content stage3-release\bin\zig.exe) (Get-Content stage4-release\bin\zig.exe) |
| 85 | CheckLastExitCode |