forked from gweslab/cerf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
101 lines (89 loc) · 4.84 KB
/
Copy pathbuild.ps1
File metadata and controls
101 lines (89 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
param([string]$Config = "Release")
# Run from the repo root, regardless of where the script is invoked from.
# Do NOT hardcode a drive letter -- this script ships in the repo and runs
# on whatever machine has it checked out (Z:\ on the maintainer's box,
# D:\a\cerf\cerf on a GitHub Actions runner, anything in between).
Set-Location $PSScriptRoot
# vcpkg MSBuild integration -- required for manifest-mode restore of libslirp + glib.
# One-time setup: run 'vcpkg integrate install' from the VS-bundled vcpkg at
# "<VS install>\VC\vcpkg\vcpkg.exe" (ships with the C++ desktop workload).
if (-not (Test-Path "$env:LOCALAPPDATA\vcpkg\vcpkg.user.props")) {
Write-Host "[BUILD] FAILED! vcpkg MSBuild integration missing. Run 'vcpkg integrate install' from the vcpkg that ships with Visual Studio (path is '<VS install>\VC\vcpkg\vcpkg.exe' inside the VS install -- comes with the C++ desktop workload)."
[Environment]::Exit(1)
}
# Kill everything that could hold PDB locks or interfere
@("cerf","MSBuild","cl","link") | ForEach-Object {
$p = Get-Process -Name $_ -ErrorAction SilentlyContinue
if ($p) {
Stop-Process -Name $_ -Force -ErrorAction SilentlyContinue
$p | Wait-Process -Timeout 5 -ErrorAction SilentlyContinue
}
}
if ($Config -match "^d(ebug)?$") { $Config = "Debug" }
Write-Host "============================================================"
Write-Host "[BUILD] Starting build: $Config x64"
Write-Host " Full rebuild might take 5+ minutes"
Write-Host "============================================================"
# Locate MSBuild via vswhere -- works for any VS edition / version installed
# at any path. vswhere ships with the VS Installer at a fixed location on
# every machine that has any VS install. -prerelease so VS preview/insider
# channels (e.g. early VS 2026 builds) are also picked up.
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
if (-not (Test-Path $vswhere)) {
Write-Host "[BUILD] FAILED! vswhere.exe not found at $vswhere. Install Visual Studio with the C++ desktop workload."
[Environment]::Exit(1)
}
$msbuild = & $vswhere -latest -prerelease -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\amd64\MSBuild.exe' | Select-Object -First 1
if (-not $msbuild -or -not (Test-Path $msbuild)) {
Write-Host "[BUILD] FAILED! MSBuild.exe not found via vswhere. Ensure Visual Studio's C++ desktop workload is installed."
[Environment]::Exit(1)
}
# Reset $LASTEXITCODE so a stale value from outside the script can't
# make a throw-before-native-run look successful.
$global:LASTEXITCODE = 0
# PlatformToolset is intentionally NOT set here -- the .vcxproj defers to
# Microsoft.Cpp.Default.props, which picks whichever toolset the installed
# VS provides (v143 on VS 2022, v145 on VS 2026). Forcing a specific value
# from the build script is what made this script unportable in the first
# place.
& $msbuild cerf.sln /p:Configuration=$Config /p:Platform=x64 /m /v:minimal
$msbuildExit = $LASTEXITCODE
if ($msbuildExit -ne 0) {
Write-Host "[BUILD] FAILED! (msbuild exit=$msbuildExit)"
[Environment]::Exit($msbuildExit)
}
# msbuild returned 0 -- but verify the artifact actually exists. Without
# this check, a "success" exit code combined with a missing cerf.exe lets
# the script fall through to "[BUILD] OK" and exit 0, which is the
# silent-failure mode callers have been bitten by.
$exePath = "build\$Config\x64\cerf.exe"
if (-not (Test-Path $exePath)) {
Write-Host "[BUILD] FAILED! msbuild reported success but cerf.exe not found at $exePath"
[Environment]::Exit(1)
}
$exe = Get-Item $exePath
Write-Host "[BUILD] OK: $($exe.FullName)"
Write-Host "[BUILD] Size: $($exe.Length) bytes"
Write-Host "[BUILD] Time: $($exe.LastWriteTime)"
# CERF-owned ARM CE apps (sampleapp + test fixtures). Each subdir under
# ce_apps/ ships a build.ps1 that delegates to tools/build_ce_app.ps1, which
# stages the artifact under build/<Config>/x64/platform/prebuilt/. Per-app
# builds are incremental, so this stage is a stat-only sweep when nothing
# changed. Failure here fails the overall build.
$env:CE_APPS_CONFIG = $Config
Get-ChildItem -Path "$PSScriptRoot/ce_apps" -Directory -ErrorAction SilentlyContinue | ForEach-Object {
$appBuild = Join-Path $_.FullName "build.ps1"
if (Test-Path $appBuild) {
Write-Host "[CE] $($_.Name)"
& powershell -NoProfile -ExecutionPolicy Bypass -File $appBuild
if ($LASTEXITCODE -ne 0) {
Write-Host "[BUILD] FAILED! ce_apps/$($_.Name) build returned $LASTEXITCODE"
[Environment]::Exit($LASTEXITCODE)
}
}
}
Write-Host "============================================================"
# Guarantee a clean zero exit code -- `exit 0` has been known to be
# swallowed by `powershell.exe -File` in some invocation chains; the
# Environment.Exit call goes straight to the Win32 terminator.
[Environment]::Exit(0)