mirror of
https://github.com/feigeCode/navop.git
synced 2026-09-22 00:01:25 +00:00
167 lines
4.8 KiB
PowerShell
167 lines
4.8 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[ValidateSet(
|
|
"x86_64-pc-windows-msvc",
|
|
"i686-pc-windows-msvc"
|
|
)]
|
|
[string[]] $Target = @(
|
|
"x86_64-pc-windows-msvc",
|
|
"i686-pc-windows-msvc"
|
|
)
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
Set-StrictMode -Version Latest
|
|
|
|
$nativeDesktop = "Microsoft.VisualStudio.Workload.NativeDesktop"
|
|
$atlComponent = "Microsoft.VisualStudio.Component.VC.ATL"
|
|
$supportedVisualStudioVersionRange = "[17.0,19.0)"
|
|
$vswhere = Join-Path ${env:ProgramFiles(x86)} `
|
|
"Microsoft Visual Studio\Installer\vswhere.exe"
|
|
|
|
function Get-VisualStudioInstallation {
|
|
if (-not (Test-Path -LiteralPath $vswhere)) {
|
|
throw "vswhere.exe not found: $vswhere"
|
|
}
|
|
|
|
$arguments = @(
|
|
"-latest",
|
|
"-products",
|
|
"*",
|
|
"-version",
|
|
$supportedVisualStudioVersionRange,
|
|
"-requires",
|
|
$nativeDesktop,
|
|
$atlComponent,
|
|
"-format",
|
|
"json"
|
|
)
|
|
$json = & $vswhere @arguments
|
|
$exitCode = $LASTEXITCODE
|
|
if ($exitCode -ne 0) {
|
|
throw "vswhere failed with exit code $exitCode"
|
|
}
|
|
|
|
$instances = @($json | ConvertFrom-Json)
|
|
$installation = $instances | Select-Object -First 1
|
|
if (
|
|
$null -eq $installation -or
|
|
[string]::IsNullOrWhiteSpace($installation.installationPath)
|
|
) {
|
|
throw "Visual Studio with NativeDesktop and VC.ATL was not found"
|
|
}
|
|
return $installation.installationPath
|
|
}
|
|
|
|
function Assert-HeaderExists {
|
|
param(
|
|
[string] $Root,
|
|
[string] $Header
|
|
)
|
|
|
|
if (-not (Test-Path -LiteralPath $Root)) {
|
|
throw "Header search root not found: $Root"
|
|
}
|
|
|
|
$match = Get-ChildItem `
|
|
-LiteralPath $Root `
|
|
-Filter $Header `
|
|
-File `
|
|
-Recurse `
|
|
-ErrorAction SilentlyContinue |
|
|
Select-Object -First 1
|
|
if ($null -eq $match) {
|
|
throw "$Header not found under $Root"
|
|
}
|
|
Write-Host "Found $Header at $($match.FullName)"
|
|
}
|
|
|
|
function Get-VcVarsArchitecture {
|
|
param([string] $RustTarget)
|
|
|
|
switch ($RustTarget) {
|
|
"x86_64-pc-windows-msvc" { return "x64" }
|
|
"i686-pc-windows-msvc" { return "x86" }
|
|
default { throw "Unsupported Windows RDP probe target: $RustTarget" }
|
|
}
|
|
}
|
|
|
|
function Invoke-ProbeBuild {
|
|
param(
|
|
[string] $VcVarsAll,
|
|
[string] $Architecture,
|
|
[string] $RustTarget,
|
|
[string] $RepoRoot
|
|
)
|
|
|
|
$commands = @(
|
|
"@echo off",
|
|
"chcp 65001 >nul",
|
|
"call `"$VcVarsAll`" $Architecture",
|
|
"if errorlevel 1 exit /b %errorlevel%",
|
|
"cd /d `"$RepoRoot`"",
|
|
"cargo build --locked -p windows-rdp-probe --target $RustTarget",
|
|
"if errorlevel 1 exit /b %errorlevel%",
|
|
"cargo test --locked -p windows_rdp_host --target $RustTarget",
|
|
"if errorlevel 1 exit /b %errorlevel%"
|
|
)
|
|
if ($RustTarget -eq "x86_64-pc-windows-msvc") {
|
|
$commands += (
|
|
"cargo test --locked -p remote_desktop_view " +
|
|
"--features windows-native-rdp --target $RustTarget"
|
|
)
|
|
$commands += "if errorlevel 1 exit /b %errorlevel%"
|
|
}
|
|
$commands += "exit /b 0"
|
|
$tempScript = Join-Path ([IO.Path]::GetTempPath()) `
|
|
("navop-rdp-probe-{0}.cmd" -f [guid]::NewGuid())
|
|
|
|
try {
|
|
$encoding = New-Object System.Text.UTF8Encoding($false)
|
|
[IO.File]::WriteAllLines($tempScript, $commands, $encoding)
|
|
& $env:ComSpec /d /s /c "`"$tempScript`""
|
|
$exitCode = $LASTEXITCODE
|
|
if ($exitCode -ne 0) {
|
|
throw "Probe build failed for $RustTarget with exit code $exitCode"
|
|
}
|
|
}
|
|
finally {
|
|
Remove-Item `
|
|
-LiteralPath $tempScript `
|
|
-Force `
|
|
-ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
$installationPath = Get-VisualStudioInstallation
|
|
$vcvarsall = Join-Path $installationPath `
|
|
"VC\Auxiliary\Build\vcvarsall.bat"
|
|
if (-not (Test-Path -LiteralPath $vcvarsall)) {
|
|
throw "vcvarsall.bat not found: $vcvarsall"
|
|
}
|
|
|
|
$msvcRoot = Join-Path $installationPath "VC\Tools\MSVC"
|
|
Assert-HeaderExists -Root $msvcRoot -Header "atlbase.h"
|
|
Write-Host (
|
|
"Remote Desktop ActiveX declarations will be generated by MSVC " +
|
|
"from the system-registered type library."
|
|
)
|
|
|
|
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
|
Write-Host (
|
|
"Compile-only probe gate and native runtime tests: builds the ATL shim, " +
|
|
"runs non-ActiveX host tests, and validates the x64 presentation feature."
|
|
)
|
|
foreach ($rustTarget in $Target) {
|
|
$architecture = Get-VcVarsArchitecture -RustTarget $rustTarget
|
|
Write-Host (
|
|
"Building Windows RDP probe and native host for " +
|
|
"$rustTarget ($architecture)"
|
|
)
|
|
Invoke-ProbeBuild `
|
|
-VcVarsAll $vcvarsall `
|
|
-Architecture $architecture `
|
|
-RustTarget $rustTarget `
|
|
-RepoRoot $repoRoot
|
|
}
|