Skip to content

Commit 0e25ab7

Browse files
committed
fix(windows): restore prebuilt Z3
Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>
1 parent 6b8a6da commit 0e25ab7

7 files changed

Lines changed: 63 additions & 47 deletions

File tree

‎.agents/skills/build-openshell-mxc-windows/SKILL.md‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ The lane targets a Windows host with Visual Studio Build Tools and rustup.
116116
| Visual C++ ARM64 tools | `vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.ARM64 -property installationPath` | Required for native ARM64 check, build, and tests and for x64-to-ARM64 check/build. Tests always require a native runner. |
117117
| Visual C++ ARM64 Spectre-mitigated libraries | `vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Runtimes.ARM64.Spectre -property installationPath` | Required by `regorus` through `msvc_spectre_libs`; the build fails when the selected MSVC toolset lacks `lib\spectre\arm64`. |
118118
| Visual C++ Clang tools | `vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath` | Provides host-native `libclang.dll` for `bindgen` and `clang-cl.exe` for ARM64 crypto dependencies such as `aws-lc-sys`. On ARM64, the wrapper uses `VC\Tools\Llvm\Arm64\bin`. |
119-
| Visual C++ CMake tools | `vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.CMake.Project -property installationPath` | Provides CMake and Ninja for bundled Z3 and other native dependencies. The x64-to-ARM64 path adds Ninja to `PATH`; Z3 uses MSVC's Visual Studio generator. |
119+
| Visual C++ CMake tools | `vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.CMake.Project -property installationPath` | Provides CMake and Ninja for native dependencies. The x64-to-ARM64 path adds Ninja to `PATH`; Z3 uses an architecture-specific prebuilt release. |
120120
| Windows SDK | `where.exe rc.exe` from a Developer PowerShell | Install an SDK containing target libraries and ARM64 tools. |
121121
| Rust via rustup | `rustc --version` | Add each target being validated: `x86_64-pc-windows-msvc` and/or `aarch64-pc-windows-msvc`. The wrapper also adds the selected target. |
122122
| mise | `mise --version` | Used as a task runner only. |
@@ -136,6 +136,8 @@ from this skill.
136136
| `CARGO_TARGET_DIR` | `target` under repo root | Override Cargo output location. Use a short absolute path when x64-to-ARM64 builds approach Windows path-length limits. |
137137
| `Z3_LIBRARY_PATH_OVERRIDE` | unset | Directory containing an x64 system `libz3.lib`; not valid for ARM64. |
138138
| `Z3_SYS_Z3_HEADER` | unset | Full `z3.h` path required with a system Z3 library. |
139+
| `Z3_SYS_Z3_VERSION` | `4.16.0` | Pinned official prebuilt Z3 release selected by the wrapper. |
140+
| `READ_ONLY_GITHUB_TOKEN` | unset | Optional token for the Z3 release lookup; GitHub Actions supplies `github.token`. |
139141
| `RUSTC_WRAPPER` | inherited | The wrapper resolves an available command to an absolute path. If it is unavailable, the wrapper warns and continues without compiler caching. |
140142

141143
Legacy fork variables such as `OPENSHELL_UPSTREAM`,
@@ -216,8 +218,7 @@ jobs in the current mirror push run, or push a new mirrored commit. The binaries
216218
The ARM64 check/build steps in this x64-host contract are cross-builds. The
217219
wrapper discovers and adds host-native LLVM and Ninja to `PATH`, requires the
218220
ARM64 compiler and Spectre-mitigated libraries, lets ARM64 crypto crates select
219-
`clang-cl`, and builds bundled Z3 with native MSVC `cl.exe` and the Visual
220-
Studio generator.
221+
`clang-cl`, and downloads the official prebuilt ARM64 Z3 static library.
221222

222223
On ARM64 hosts, validate the native ARM64 check, build, and test path. The
223224
wrapper rejects test targets that do not match the host architecture, so x64
@@ -328,12 +329,13 @@ Useful log files:
328329
| `test-x86_64-pc-windows-msvc-mxc-real.log` | Native x64 real-MXC integration output. |
329330
| `test-aarch64-pc-windows-msvc-mxc-real.log` | Native ARM64 real-MXC integration output. |
330331

331-
The first check builds bundled Z3 from source through `z3-sys`. Cargo stores the
332-
native build output in its target tree, so the Windows target cache reuses it.
333-
The resulting release executables do not require `libz3.dll`. The artifact
334-
report computes SHA256 through .NET directly and does not rely on the
335-
`Get-FileHash` module being available inside the mise-launched Windows
336-
PowerShell process.
332+
The first check downloads the pinned official Z3 archive for the target
333+
architecture through `z3-sys`. GitHub Actions authenticates the lookup with its
334+
read-only workflow token; local users can set `READ_ONLY_GITHUB_TOKEN` if an
335+
unauthenticated lookup is rate-limited. Cargo stores the extracted library in
336+
its target tree, so the Windows target cache reuses it. The artifact report
337+
computes SHA256 through .NET directly and does not rely on the `Get-FileHash`
338+
module being available inside the mise-launched Windows PowerShell process.
337339

338340
## Common Fix Patterns
339341

‎.agents/skills/build-openshell-mxc-windows/reference.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ file.
6868
For ARM64, verify the Visual Studio instance contains the ARM64 MSVC tools,
6969
ARM64 Spectre-mitigated libraries, Clang tools, CMake tools, and a Windows SDK.
7070
Clang supplies host-native `libclang.dll` for `bindgen` and `clang-cl.exe` for
71-
ARM64 crypto dependencies such as `aws-lc-sys`. Native builds use the normal
72-
bundled-Z3 CMake path. An x64-to-ARM64 check/build discovers and adds
73-
host-native Ninja to `PATH`, builds bundled Z3 with native MSVC `cl.exe` and
74-
the Visual Studio generator, and lets the crypto crates select `clang-cl`. Use
75-
a short `CARGO_TARGET_DIR` if Windows path-length limits are reached.
71+
ARM64 crypto dependencies such as `aws-lc-sys`. Native and x64-to-ARM64 builds
72+
use the official prebuilt Z3 4.16.0 static library for the target architecture.
73+
An x64-to-ARM64 check/build discovers and adds host-native Ninja to `PATH`,
74+
while the crypto crates select `clang-cl`. Use a short `CARGO_TARGET_DIR` if
75+
Windows path-length limits are reached.
7676

7777
## Unsupported Driver Rules
7878

‎.github/workflows/windows-msvc.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
rust_target: aarch64-pc-windows-msvc
5757
runs-on: ${{ matrix.runner }}
5858
env:
59+
READ_ONLY_GITHUB_TOKEN: ${{ github.token }}
5960
SCCACHE_GHA_ENABLED: "true"
6061
SCCACHE_GHA_VERSION: windows-msvc-${{ matrix.arch }}
6162
SCCACHE_CLIENT_SIDE: "1"
@@ -121,6 +122,7 @@ jobs:
121122
rust_target: aarch64-pc-windows-msvc
122123
runs-on: ${{ matrix.runner }}
123124
env:
125+
READ_ONLY_GITHUB_TOKEN: ${{ github.token }}
124126
SCCACHE_GHA_ENABLED: "true"
125127
SCCACHE_GHA_VERSION: windows-msvc-${{ matrix.arch }}
126128
SCCACHE_CLIENT_SIDE: "1"
@@ -178,6 +180,7 @@ jobs:
178180
rust_target: aarch64-pc-windows-msvc
179181
runs-on: ${{ matrix.runner }}
180182
env:
183+
READ_ONLY_GITHUB_TOKEN: ${{ github.token }}
181184
SCCACHE_GHA_ENABLED: "true"
182185
SCCACHE_GHA_VERSION: windows-msvc-${{ matrix.arch }}
183186
SCCACHE_CLIENT_SIDE: "1"

‎CONTRIBUTING.md‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,19 @@ cargo build -p openshell-prover --features bundled-z3
340340

341341
For x86-64 and ARM64 Windows MSVC builds, use one of these Z3 paths:
342342

343-
- Bundled Z3 (the default for `windows:*` tasks): `z3-sys` builds Z3 from
344-
source and links it into the OpenShell binaries. This keeps the release
345-
executables independent of `libz3.dll` when they are copied to another host.
343+
- Prebuilt Z3 (the default for `windows:*` tasks): `z3-sys` downloads the
344+
pinned Z3 4.16.0 GitHub release for the target architecture on the first
345+
build. Cargo reuses the extracted archive from its target directory. Windows
346+
CI authenticates the GitHub API request with `READ_ONLY_GITHUB_TOKEN` and
347+
preserves the archive in the architecture-specific Cargo target cache. For
348+
cold local builds, you may set `READ_ONLY_GITHUB_TOKEN` to avoid anonymous
349+
GitHub API rate limits.
346350
- System Z3: point `Z3_LIBRARY_PATH_OVERRIDE` at the directory containing the
347-
target-compatible MSVC Z3 library and `Z3_SYS_Z3_HEADER` at the full path to
348-
`z3.h`. The `windows:*` tasks use this path automatically when
349-
`Z3_LIBRARY_PATH_OVERRIDE` is set. Deploy the matching `libz3.dll` with any
350-
binaries built against a dynamic system Z3.
351+
target-compatible MSVC Z3 library and `Z3_SYS_Z3_HEADER` at the full path to `z3.h`.
352+
The `windows:*` tasks use this path automatically when `Z3_LIBRARY_PATH_OVERRIDE`
353+
is set.
354+
- Bundled Z3: for direct Cargo builds, pass `--features bundled-z3` so `z3-sys`
355+
builds Z3 from source.
351356

352357
`openshell-prover` itself has no `bindgen`/`libclang` dependency, so building
353358
just this crate does not require `LIBCLANG_PATH`:
@@ -360,17 +365,17 @@ cargo build -p openshell-prover --target x86_64-pc-windows-msvc --features bundl
360365

361366
To build the full set of Windows binaries, including `openshell-gateway.exe`
362367
and `openshell.exe`, use the `windows:build:x64` mise task instead of a
363-
single-crate `cargo build`. It builds Z3 from source (bundled) by default. A full
364-
build also compiles crates that use `bindgen` (e.g. the MXC driver on Windows),
365-
so it requires `libclang.dll`; if LLVM is not on the default search path, set
366-
`LIBCLANG_PATH` to the directory containing `libclang.dll`:
368+
single-crate `cargo build`. It downloads the pinned prebuilt Z3 release by default. A
369+
full build also compiles crates that use `bindgen` (e.g. the MXC driver on
370+
Windows), so it requires `libclang.dll`; if LLVM is not on the default search
371+
path, set `LIBCLANG_PATH` to the directory containing `libclang.dll`:
367372

368373
```powershell
369374
$env:LIBCLANG_PATH='C:\Program Files\Microsoft Visual Studio\2022\<Edition>\VC\Tools\Llvm\x64\bin'
370375
mise run --skip-tools windows:build:x64
371376
```
372377

373-
To use a local x64 Z3 release instead of the bundled build, set
378+
To use a local x64 Z3 release instead of the prebuilt download, set
374379
`Z3_LIBRARY_PATH_OVERRIDE` and `Z3_SYS_Z3_HEADER` before running the task:
375380

376381
```powershell

‎architecture/windows-msvc-build.md‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ packaging-asset tests; its
110110
cross-platform Python, Markdown, license, and documentation checks still run.
111111
Test tasks require the Rust target architecture to match the Windows host, so
112112
an ARM64 test result is native coverage rather than x64 emulation coverage.
113-
By default it enables bundled Z3 for reproducible Windows builds. `z3-sys`
114-
builds Z3 from source and links it into the release binaries, so copying
115-
`openshell-gateway.exe` and `openshell.exe` does not create an undeclared
116-
`libz3.dll` runtime dependency. When `Z3_LIBRARY_PATH_OVERRIDE` points at a
117-
directory containing `libz3.lib`, the wrapper uses that system Z3 instead and
118-
requires `Z3_SYS_Z3_HEADER` to point at the full path to `z3.h`. Binaries built
119-
against a dynamic system Z3 must be deployed with the matching `libz3.dll`.
113+
By default it enables the `z3-sys` prebuilt-release feature and pins Z3 4.16.0.
114+
On a clean target directory, `z3-sys` downloads the official static library for
115+
the selected Windows architecture instead of compiling Z3 through
116+
CMake/MSBuild. GitHub Actions supplies its read-only workflow token for the
117+
release lookup, and the Cargo target cache preserves the extracted library for
118+
subsequent runs. When `Z3_LIBRARY_PATH_OVERRIDE` points at a directory
119+
containing `libz3.lib`, the wrapper uses that system Z3 instead and requires
120+
`Z3_SYS_Z3_HEADER` to point at the full path to `z3.h`. Local clean builds use
121+
the unauthenticated GitHub API unless `READ_ONLY_GITHUB_TOKEN` is set.
120122

121123
GitHub Actions layers the Cargo target cache with sccache's GitHub Actions
122124
backend. The target cache lets Cargo skip intact dependency builds; sccache
@@ -136,10 +138,10 @@ Spectre-mitigated libraries, host-native Clang tools, CMake tools, and an
136138
ARM64-capable Windows SDK. Clang provides `libclang.dll` for `bindgen` and
137139
`clang-cl.exe` for ARM64 crypto dependencies. During x64-to-ARM64 check/build,
138140
the wrapper discovers and adds the Visual Studio-bundled Ninja to `PATH` for
139-
native dependencies. Bundled Z3 uses native MSVC `cl.exe` with the Visual
140-
Studio generator, while the crypto crates select `clang-cl`. Artifact hashing
141-
uses .NET SHA256 directly because module autoloading in the mise-launched
142-
Windows PowerShell process is not guaranteed.
141+
native dependencies. Z3 uses the official prebuilt ARM64 static library, so it
142+
does not inherit compiler settings from those native dependencies. Artifact
143+
hashing uses .NET SHA256 directly because module autoloading in the
144+
mise-launched Windows PowerShell process is not guaranteed.
143145

144146
The wrapper defaults Cargo compilation to four jobs. Set
145147
`OPENSHELL_WINDOWS_BUILD_JOBS` to a positive integer to override that limit.

‎crates/openshell-gateway/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ telemetry = ["openshell-core/telemetry", "openshell-server/telemetry"]
7373
## `rust:verify:defaults-without-telemetry`.
7474
defaults-without-telemetry = ["in-tree-compute-drivers"]
7575
bundled-z3 = ["openshell-server/bundled-z3"]
76+
prebuilt-z3 = ["openshell-server/prebuilt-z3"]
7677

7778
[lints]
7879
workspace = true

‎tasks/scripts/windows-msvc.ps1‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ $WindowsCargoMutex = [System.Threading.Mutex]::new($false, "Local\OpenShellWindo
5353
$UnsupportedDriverPackageExcludes = "--exclude openshell-driver-docker --exclude openshell-driver-kubernetes --exclude openshell-driver-kubernetes-secrets --exclude openshell-driver-podman --exclude openshell-driver-vault --exclude openshell-driver-vm --exclude openshell-sandbox --exclude openshell-supervisor-process --exclude openshell-vfio"
5454
$WindowsClippyPackageExcludes = $UnsupportedDriverPackageExcludes
5555
$WindowsClippyLintArgs = "-D warnings -A dead-code -A unused-imports -A clippy::unused-async"
56-
$BundledZ3WorkspaceFeatures = "--features openshell-prover/bundled-z3"
57-
$BundledZ3ServerFeatures = "--features openshell-server/bundled-z3,openshell-prover/bundled-z3"
58-
$BundledZ3GatewayFeatures = "--features openshell-gateway/bundled-z3"
59-
$Z3WorkspaceFeatures = $BundledZ3WorkspaceFeatures
60-
$Z3ServerFeatures = $BundledZ3ServerFeatures
61-
$Z3GatewayFeatures = $BundledZ3GatewayFeatures
56+
$PrebuiltZ3WorkspaceFeatures = "--features openshell-prover/prebuilt-z3"
57+
$PrebuiltZ3ServerFeatures = "--features openshell-server/prebuilt-z3,openshell-prover/prebuilt-z3"
58+
$PrebuiltZ3GatewayFeatures = "--features openshell-gateway/prebuilt-z3"
59+
$PrebuiltZ3Version = "4.16.0"
60+
$Z3WorkspaceFeatures = $PrebuiltZ3WorkspaceFeatures
61+
$Z3ServerFeatures = $PrebuiltZ3ServerFeatures
62+
$Z3GatewayFeatures = $PrebuiltZ3GatewayFeatures
6263

6364
function Get-VsInstallRoots {
6465
$programFiles = @(
@@ -354,11 +355,13 @@ function Resolve-Z3HeaderPath([string] $HeaderPath) {
354355

355356
function Configure-Z3 {
356357
if ([string]::IsNullOrWhiteSpace($env:Z3_LIBRARY_PATH_OVERRIDE)) {
357-
Write-Host "==> Z3: bundled"
358+
Write-Host "==> Z3: prebuilt release"
359+
$env:Z3_SYS_Z3_VERSION = $PrebuiltZ3Version
360+
Write-Host " Z3_SYS_Z3_VERSION=$env:Z3_SYS_Z3_VERSION"
358361
return [pscustomobject]@{
359-
WorkspaceFeatures = $BundledZ3WorkspaceFeatures
360-
ServerFeatures = $BundledZ3ServerFeatures
361-
GatewayFeatures = $BundledZ3GatewayFeatures
362+
WorkspaceFeatures = $PrebuiltZ3WorkspaceFeatures
363+
ServerFeatures = $PrebuiltZ3ServerFeatures
364+
GatewayFeatures = $PrebuiltZ3GatewayFeatures
362365
}
363366
}
364367

0 commit comments

Comments
 (0)