Skip to content

Commit 81cb5ac

Browse files
committed
feat(windows): add libclang path resolution and update cargo commands with bundled Z3 features
Signed-off-by: Akber Raza <[email protected]>
1 parent 68844ba commit 81cb5ac

1 file changed

Lines changed: 56 additions & 4 deletions

File tree

‎tasks/scripts/windows-msvc.ps1‎

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ if ([string]::IsNullOrWhiteSpace($TargetDir)) {
3838
}
3939

4040
$UnsupportedDriverPackageExcludes = "--exclude openshell-driver-docker --exclude openshell-driver-kubernetes --exclude openshell-driver-podman --exclude openshell-driver-vm"
41+
$BundledZ3WorkspaceFeatures = "--features openshell-cli/bundled-z3,openshell-prover/bundled-z3"
42+
$BundledZ3ServerFeatures = "--features openshell-server/bundled-z3,openshell-prover/bundled-z3"
4143

4244
function Resolve-VsDevCmd {
4345
if ($env:OPENSHELL_VSDEVCMD -and (Test-Path $env:OPENSHELL_VSDEVCMD)) {
@@ -77,6 +79,54 @@ function Resolve-VsDevCmd {
7779
throw "Could not find VsDevCmd.bat. Install Visual Studio Build Tools, or set OPENSHELL_VSDEVCMD."
7880
}
7981

82+
function Resolve-LibclangPath {
83+
if ($env:LIBCLANG_PATH) {
84+
$candidate = Join-Path $env:LIBCLANG_PATH "libclang.dll"
85+
if (Test-Path $candidate) {
86+
return (Resolve-Path $env:LIBCLANG_PATH).Path
87+
}
88+
throw "LIBCLANG_PATH is set but libclang.dll was not found at: $candidate"
89+
}
90+
91+
$programFilesX86 = [Environment]::GetEnvironmentVariable("ProgramFiles(x86)")
92+
if ($programFilesX86) {
93+
$vswhere = Join-Path $programFilesX86 "Microsoft Visual Studio\Installer\vswhere.exe"
94+
} else {
95+
$vswhere = $null
96+
}
97+
if ($vswhere -and (Test-Path $vswhere)) {
98+
$found = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -find "VC\Tools\Llvm\x64\bin\libclang.dll" | Select-Object -First 1
99+
if ($found -and (Test-Path $found)) {
100+
return (Split-Path -Parent (Resolve-Path $found).Path)
101+
}
102+
}
103+
104+
$programFiles = @(
105+
[Environment]::GetEnvironmentVariable("ProgramFiles"),
106+
[Environment]::GetEnvironmentVariable("ProgramFiles(x86)")
107+
) | Where-Object { $_ }
108+
$versions = @("2022", "18", "17")
109+
$editions = @("Enterprise", "Professional", "Community", "BuildTools")
110+
foreach ($root in $programFiles) {
111+
foreach ($version in $versions) {
112+
foreach ($edition in $editions) {
113+
$candidateDir = Join-Path $root "Microsoft Visual Studio\$version\$edition\VC\Tools\Llvm\x64\bin"
114+
$candidate = Join-Path $candidateDir "libclang.dll"
115+
if (Test-Path $candidate) {
116+
return (Resolve-Path $candidateDir).Path
117+
}
118+
}
119+
}
120+
}
121+
122+
$llvmDir = "C:\Program Files\LLVM\bin"
123+
if (Test-Path (Join-Path $llvmDir "libclang.dll")) {
124+
return (Resolve-Path $llvmDir).Path
125+
}
126+
127+
throw "Could not find libclang.dll. Install Visual Studio C++ Clang tools, or set LIBCLANG_PATH to the directory containing libclang.dll."
128+
}
129+
80130
function Get-HostArch {
81131
switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()) {
82132
"Arm64" { "arm64" }
@@ -139,14 +189,14 @@ function Invoke-VsCargo {
139189
function Invoke-Check([string] $RustTarget) {
140190
Invoke-VsCargo `
141191
-RustTarget $RustTarget `
142-
-CargoArgs "cargo check --workspace $UnsupportedDriverPackageExcludes --target $RustTarget" `
192+
-CargoArgs "cargo check --workspace $UnsupportedDriverPackageExcludes --target $RustTarget $BundledZ3WorkspaceFeatures" `
143193
-LogName "build-$RustTarget-check.log"
144194
}
145195

146196
function Invoke-Build([string] $RustTarget) {
147197
Invoke-VsCargo `
148198
-RustTarget $RustTarget `
149-
-CargoArgs "cargo build --release --target $RustTarget --bin openshell-gateway --bin openshell" `
199+
-CargoArgs "cargo build --release --target $RustTarget --bin openshell-gateway --bin openshell $BundledZ3WorkspaceFeatures" `
150200
-LogName "build-$RustTarget-release.log"
151201
}
152202

@@ -156,7 +206,7 @@ function Invoke-Test([string] $RustTarget) {
156206
}
157207
Invoke-VsCargo `
158208
-RustTarget $RustTarget `
159-
-CargoArgs "cargo test --workspace $UnsupportedDriverPackageExcludes --target $RustTarget --no-fail-fast" `
209+
-CargoArgs "cargo test --workspace $UnsupportedDriverPackageExcludes --target $RustTarget --no-fail-fast $BundledZ3WorkspaceFeatures" `
160210
-LogName "test-$RustTarget.log"
161211
}
162212

@@ -172,7 +222,7 @@ function Invoke-UnsupportedContractTests([string] $RustTarget) {
172222
foreach ($test in $tests) {
173223
Invoke-VsCargo `
174224
-RustTarget $RustTarget `
175-
-CargoArgs "cargo test -p openshell-server --target $RustTarget $test" `
225+
-CargoArgs "cargo test -p openshell-server --target $RustTarget $test $BundledZ3ServerFeatures" `
176226
-LogName "test-$RustTarget-unsupported-$test.log"
177227
}
178228
}
@@ -204,6 +254,8 @@ function Show-Artifacts([string[]] $RustTargets) {
204254
}
205255

206256
$targets = Get-SelectedTargets $Target
257+
$env:LIBCLANG_PATH = Resolve-LibclangPath
258+
Write-Host "==> LIBCLANG_PATH=$env:LIBCLANG_PATH"
207259

208260
switch ($Action) {
209261
"check" {

0 commit comments

Comments
 (0)