Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 44 additions & 48 deletions .github/workflows/examples-msvc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MSVC Examples CI
#
# Runs all examples/msvc/*.build.ps1 scripts on a real Windows runner with
# MSVC Build Tools pre-installed (windows-latest already ships with VS 2022).
# MSVC tools pre-installed; discover the installed Visual Studio instance.
#
# Triggered when:
# - examples/msvc/** changes
Expand All @@ -17,10 +17,18 @@ on:
paths:
- "examples/msvc/**"
- "crates/vx-providers/msvc/**"
- ".github/workflows/examples-msvc.yml"
- "scripts/ensure-msvc-spectre.ps1"
- "scripts/tests/msvc-spectre.Tests.ps1"
- "scripts/tests/aionui-exit.Tests.ps1"
pull_request:
paths:
- "examples/msvc/**"
- "crates/vx-providers/msvc/**"
- ".github/workflows/examples-msvc.yml"
- "scripts/ensure-msvc-spectre.ps1"
- "scripts/tests/msvc-spectre.Tests.ps1"
- "scripts/tests/aionui-exit.Tests.ps1"
workflow_dispatch:
inputs:
script:
Expand All @@ -35,8 +43,23 @@ concurrency:
cancel-in-progress: true

jobs:
test-msvc-setup:
name: Test MSVC setup contracts
runs-on: windows-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- name: Test MSVC setup and example failure handling
shell: pwsh
run: |
Import-Module Pester -MinimumVersion 5.0 -ErrorAction Stop
$result = Invoke-Pester -Path scripts/tests/msvc-spectre.Tests.ps1,scripts/tests/aionui-exit.Tests.ps1 -Output Detailed -PassThru
if ($result.Result -ne 'Passed' -or $result.PassedCount -eq 0) { exit 1 }
exit 0

build-vx:
name: Build VX (Windows)
needs: test-msvc-setup
runs-on: windows-latest
env:
RUSTC_WRAPPER: sccache
Expand Down Expand Up @@ -187,55 +210,28 @@ jobs:
shell: pwsh
run: vx --version

- name: Verify MSVC is available (windows-latest ships VS 2022)
- name: Verify MSVC and Spectre libraries
shell: pwsh
run: |
$clPaths = @(
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC",
"C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC",
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC",
"C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
)
$found = $false
foreach ($p in $clPaths) {
if (Test-Path $p) {
Write-Host "Found MSVC at: $p"
$found = $true
break
}
}
if (-not $found) {
Write-Warning "MSVC not found in standard paths — vx will attempt to install it"
}

- name: Ensure Spectre-mitigated VC libraries are installed
shell: pwsh
run: |
$vsRoot = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
$hasSpectre = @(
"$vsRoot\VC\Tools\MSVC\*\lib\x64\spectre",
"$vsRoot\VC\Tools\MSVC\*\lib\arm64\spectre"
) | ForEach-Object { Test-Path $_ } | Where-Object { $_ } | Select-Object -First 1

if ($hasSpectre) {
Write-Host "Spectre libraries already installed"
exit 0
}

$installer = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe"
if (-not (Test-Path $installer)) {
throw "Visual Studio Installer not found at $installer"
}

& $installer modify `
--installPath $vsRoot `
--add Microsoft.VisualStudio.Component.VC.ATL.Spectre `
--add Microsoft.VisualStudio.Component.VC.MFC.Spectre `
--add Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre `
--quiet --norestart

if ($LASTEXITCODE -ne 0) {
throw "Failed to install Spectre-mitigated VC libraries"
New-Item -ItemType Directory -Force examples/msvc/logs | Out-Null
Start-Transcript -Path examples/msvc/logs/msvc-setup.log
try {
# Initialize the existing VX MSVC Provider before selecting the one
# instance shared by every example. node-gyp 11.x cannot use VS18.
vx cl /?
if ($LASTEXITCODE -ne 0) { throw "VX MSVC preflight failed with exit code $LASTEXITCODE" }
. ./scripts/ensure-msvc-spectre.ps1
$instance = Ensure-MsvcSpectre -MajorVersion 17
$generator = Get-MsvcCMakeGenerator -InstallationVersion $instance.installationVersion
"CMAKE_GENERATOR=$generator" >> $env:GITHUB_ENV
"CMAKE_GENERATOR_INSTANCE=$($instance.installationPath)" >> $env:GITHUB_ENV
# node-gyp accepts an exact installation path, not only a year.
# Export both supported config forms for the examples' gyp versions.
"npm_config_msvs_version=$($instance.installationPath)" >> $env:GITHUB_ENV
"npm_package_config_node_gyp_msvs_version=$($instance.installationPath)" >> $env:GITHUB_ENV
Write-Host "CMake generator: $generator"
} finally {
Stop-Transcript
}

- name: Run example — fmt (cmake + MSVC)
Expand Down
65 changes: 39 additions & 26 deletions examples/msvc/aionui.build.ps1
Original file line number Diff line number Diff line change
@@ -1,49 +1,62 @@
$ErrorActionPreference = "Stop"
$repoUrl = "https://github.com/iOfficeAI/AionUi.git"
# Keep the upstream workspace manifests and bun.lock from one reviewed revision.
$repoCommit = "6744099b279b991c17e31c243f0920477bd31cb6"
$workRoot = Join-Path $PSScriptRoot "work"
$repoDir = Join-Path $workRoot "aionui"
$repoDir = Join-Path $workRoot "aionui-$($repoCommit.Substring(0, 12))"
$logDir = Join-Path $PSScriptRoot "logs"
$logFile = Join-Path $logDir "aionui.log"

New-Item -ItemType Directory -Force -Path $workRoot | Out-Null
New-Item -ItemType Directory -Force -Path $logDir | Out-Null

"== AionUi build test ==" | Tee-Object -FilePath $logFile
"Working directory: $repoDir" | Tee-Object -FilePath $logFile -Append

if (-not (Test-Path $repoDir)) {
git clone --depth 1 $repoUrl $repoDir
git init $repoDir 2>&1 | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "git init failed with exit code $LASTEXITCODE" }
git -C $repoDir remote add origin $repoUrl 2>&1 | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "git remote add failed with exit code $LASTEXITCODE" }
git -C $repoDir fetch --depth 1 origin $repoCommit 2>&1 | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "git fetch failed with exit code $LASTEXITCODE" }
git -C $repoDir checkout --detach $repoCommit 2>&1 | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "git checkout failed with exit code $LASTEXITCODE" }
}

$actualCommit = git -C $repoDir rev-parse HEAD
if ($LASTEXITCODE -ne 0) { throw "git rev-parse failed with exit code $LASTEXITCODE" }
if ("$actualCommit".Trim() -ne $repoCommit) { throw "AionUi checkout must be at $repoCommit; found $actualCommit" }
git -C $repoDir diff --quiet HEAD --
if ($LASTEXITCODE -ne 0) { throw "AionUi checkout has local changes or cannot be checked (exit code $LASTEXITCODE)" }
"Source commit: $actualCommit" | Tee-Object -FilePath $logFile -Append

Push-Location $repoDir
try {
# Workaround 1: npm doesn't support pnpm/yarn "workspace:*" protocol.
# AionUi is a monorepo with internal deps like "@aionui/web-host": "workspace:*".
# Replace with "*" so npm can resolve workspace packages.
Get-ChildItem -Path . -Recurse -Filter "package.json" -Depth 3 | ForEach-Object {
$c = Get-Content $_.FullName -Raw -Encoding UTF8
if ($c -match 'workspace:') {
Write-Host "Replacing workspace:* in $($_.FullName)"
$c = $c -replace '"workspace:\*"', '"*"'
[System.IO.File]::WriteAllText($_.FullName, $c, [System.Text.Encoding]::UTF8)
}
}

# Workaround 2: npm EOVERRIDE — @codemirror/language is both a direct dependency
# and in overrides/resolutions. npm 10+ rejects overrides on direct deps when
# the version specs differ. Remove the redundant override/resolution entries.
vx npm pkg delete overrides.@codemirror/language resolutions.@codemirror/language 2>$null

"== AionUi build test ==" | Tee-Object -FilePath $logFile
"Working directory: $repoDir" | Tee-Object -FilePath $logFile -Append

vx --version | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "vx --version failed with exit code $LASTEXITCODE" }
# VX discovers this repository's existing Bun pin above the upstream checkout.
vx bun --version | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "bun --version failed with exit code $LASTEXITCODE" }
vx npm --version | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "npm --version failed with exit code $LASTEXITCODE" }

vx npm install 2>&1 | Tee-Object -FilePath $logFile -Append
# Follow upstream's Bun workspace contract without rewriting dependencies.
vx bun install --frozen-lockfile 2>&1 | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "bun install failed with exit code $LASTEXITCODE" }

vx npm rebuild better-sqlite3 --build-from-source 2>&1 | Tee-Object -FilePath $logFile -Append
# Source-build AionUi's locked native SQLite package for the VX Node ABI.
# Bun workspace links can reference one build directory more than once;
# serialize npm lifecycle scripts so those builds cannot race on Windows.
vx npm rebuild better-sqlite3 --build-from-source --foreground-scripts 2>&1 | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "npm rebuild failed with exit code $LASTEXITCODE" }

vx node -e "require('better-sqlite3');require('node-pty');console.log('AionUi native modules OK')" 2>&1 | Tee-Object -FilePath $logFile -Append
vx node -e "const Database = require('better-sqlite3'); const db = new Database(':memory:'); if (db.prepare('SELECT 1 AS value').get().value !== 1) { throw new Error('SQLite query failed'); } db.close(); console.log('AionUi native SQLite OK');" 2>&1 | Tee-Object -FilePath $logFile -Append
if ($LASTEXITCODE -ne 0) { throw "node module validation failed with exit code $LASTEXITCODE" }

"AionUi test passed" | Tee-Object -FilePath $logFile -Append
git diff --quiet HEAD --
if ($LASTEXITCODE -ne 0) { throw "AionUi source or lockfile changed during the test (exit code $LASTEXITCODE)" }
"AionUi test passed (better-sqlite3 rebuilt for Node)" | Tee-Object -FilePath $logFile -Append
}
finally {
Pop-Location
Expand Down
15 changes: 14 additions & 1 deletion examples/msvc/fmt.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ if ($null -ne (Get-Variable -Name PSNativeCommandUseErrorActionPreference -Error
$PSNativeCommandUseErrorActionPreference = $false
}

$generator = $env:CMAKE_GENERATOR
$instancePath = $env:CMAKE_GENERATOR_INSTANCE
if (-not $generator -or -not $instancePath) {
if ($generator -or $instancePath) {
throw "Set both CMAKE_GENERATOR and CMAKE_GENERATOR_INSTANCE, or leave both unset for discovery"
}
. (Join-Path $PSScriptRoot '../../scripts/ensure-msvc-spectre.ps1')
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio/Installer/vswhere.exe'
$instance = Get-MsvcInstallation -VsWherePath $vswhere
$generator = Get-MsvcCMakeGenerator -InstallationVersion $instance.installationVersion
$instancePath = $instance.installationPath
}

$repoUrl = "https://github.com/fmtlib/fmt.git"
$workRoot = Join-Path $PSScriptRoot "work"
$repoDir = Join-Path $workRoot "fmt"
Expand Down Expand Up @@ -50,7 +63,7 @@ try {
}

Invoke-LoggedNative "cmake configure" {
vx cmake -S . -B $buildDir -G "Visual Studio 17 2022" -A x64 -DFMT_TEST=OFF
vx cmake -S . -B $buildDir -G $generator -A x64 "-DCMAKE_GENERATOR_INSTANCE=$instancePath" -DFMT_TEST=OFF
}

Invoke-LoggedNative "cmake build" {
Expand Down
116 changes: 116 additions & 0 deletions scripts/ensure-msvc-spectre.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Discover the installed VC instance instead of assuming a VS year or edition.
# Dot-source this file to test the setup functions without changing the machine.

function Get-MsvcInstallation {
param(
[string]$VsWherePath,
# The current VX Provider and node-pty's node-gyp 11.x share VS2022 support.
# Callers may opt into a newer major when every consumer supports it.
[ValidateSet(17, 18)][int]$MajorVersion = 17
)

$PSNativeCommandUseErrorActionPreference = $false
if (-not (Test-Path -LiteralPath $VsWherePath -PathType Leaf)) {
throw "Visual Studio locator not found at $VsWherePath"
}

$versionRange = '[{0}.0,{1}.0)' -f $MajorVersion, ($MajorVersion + 1)
$json = (& $VsWherePath -latest -products '*' -version $versionRange `
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -format json -utf8) -join "`n"
if ($LASTEXITCODE -ne 0) {
throw "Visual Studio locator failed with exit code $LASTEXITCODE"
}

$instances = @($json | ConvertFrom-Json)
if ($instances.Count -ne 1 -or [string]::IsNullOrWhiteSpace($instances[0].installationPath)) {
throw "Expected one installed Visual Studio $MajorVersion instance with x64 C++ tools"
}
$instance = $instances[0]
if (([version]$instance.installationVersion).Major -ne $MajorVersion) {
throw "Discovered Visual Studio $($instance.installationVersion) outside required range $versionRange"
}
$tools = Join-Path $instance.installationPath 'VC/Tools/MSVC'
if (-not (Test-Path -LiteralPath $tools -PathType Container)) {
throw "MSVC tools were not found in the selected instance: $tools"
}
return $instance
}

function Test-MsvcSpectre {
param([string]$InstallationPath)

# The examples build x64 targets. ARM64 libraries alone do not satisfy them.
# MSVC places the mitigation before the target architecture: lib/spectre/x64.
$libraryPath = Join-Path $InstallationPath 'VC/Tools/MSVC/*/lib/spectre/x64'
$present = Test-Path -Path $libraryPath -PathType Container
if ($present) {
Write-Host "Found x64 Spectre libraries matching $libraryPath"
}
return [bool]$present
}

function Get-MsvcCMakeGenerator {
param([string]$InstallationVersion)

# These are CMake's documented generator names, not a name inferred from a year.
# https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html
switch (([version]$InstallationVersion).Major) {
17 { return 'Visual Studio 17 2022' }
18 { return 'Visual Studio 18 2026' }
default { throw "Unsupported Visual Studio version for the CMake example: $InstallationVersion" }
}
}

function Ensure-MsvcSpectre {
param(
[string]$InstallerDirectory = (Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio/Installer'),
[ValidateSet(17, 18)][int]$MajorVersion = 17
)

$instance = Get-MsvcInstallation -VsWherePath (Join-Path $InstallerDirectory 'vswhere.exe') -MajorVersion $MajorVersion
$vsRoot = $instance.installationPath
Write-Host "Selected Visual Studio $($instance.installationVersion) at $vsRoot"

if (Test-MsvcSpectre -InstallationPath $vsRoot) {
Write-Host "x64 Spectre libraries already installed in the selected instance"
return $instance
}

$installer = Join-Path $InstallerDirectory 'setup.exe'
if (-not (Test-Path -LiteralPath $installer -PathType Leaf)) {
throw "Visual Studio Installer not found at $installer"
}
if ([string]::IsNullOrWhiteSpace($instance.channelId)) {
throw "The selected Visual Studio instance has no channelId for modification"
}

# Start-Process joins ArgumentList into a command line, so preserve the quotes
# around an installation path containing spaces. --wait is bootstrapper-only;
# use PowerShell's -Wait and the returned process ExitCode for setup.exe.
$arguments = @(
'modify', '--installPath', ('"{0}"' -f $vsRoot),
'--channelId', $instance.channelId,
'--add', 'Microsoft.VisualStudio.Component.VC.ATL.Spectre',
'--add', 'Microsoft.VisualStudio.Component.VC.MFC.Spectre',
'--add', 'Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre',
'--quiet', '--norestart'
)
$process = Start-Process -FilePath $installer -ArgumentList $arguments -Wait -PassThru
$exitCode = $process.ExitCode
Write-Host "Visual Studio Installer exit code: $exitCode"
if ($exitCode -notin @(0, 3010)) {
throw "Spectre library installation failed for '$vsRoot' with exit code $exitCode"
}
if ($exitCode -eq 3010) {
Write-Warning "Installer requested a restart; validating the installed libraries before continuing"
}
if (-not (Test-MsvcSpectre -InstallationPath $vsRoot)) {
throw "Installer returned $exitCode but x64 Spectre libraries are still missing in '$vsRoot'"
}
return $instance
}

if ($MyInvocation.InvocationName -ne '.') {
$ErrorActionPreference = 'Stop'
Ensure-MsvcSpectre | Out-Null
}
Loading
Loading