Skip to content

Commit d0bcaca

Browse files
committed
fix(windows): restore ARM64 Ninja discovery
Signed-off-by: Akber Raza <[email protected]>
1 parent 327af7b commit d0bcaca

4 files changed

Lines changed: 61 additions & 20 deletions

File tree

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The lane targets a Windows host with Visual Studio Build Tools and rustup.
117117
| 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. |
118118
| 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`. |
119119
| 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 `ring` and `aws-lc-sys`. On ARM64, the wrapper uses `VC\Tools\Llvm\Arm64\bin`. |
120-
| Visual C++ CMake tools | `vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.CMake.Project -property installationPath` | Required for bundled Z3. The x64-to-ARM64 path uses CMake's Visual Studio ARM64 generator with native MSVC `cl.exe` so Z3 does not inherit the crypto crates' `clang-cl` requirement. |
120+
| Visual C++ CMake tools | `vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.CMake.Project -property installationPath` | Provides CMake and Ninja. The x64-to-ARM64 path adds Ninja to `PATH` for native dependencies but keeps bundled Z3 on CMake's Visual Studio ARM64 generator with native MSVC `cl.exe`. |
121121
| Windows SDK | `where.exe rc.exe` from a Developer PowerShell | Install an SDK containing target libraries and ARM64 tools. |
122122
| 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. |
123123
| mise | `mise --version` | Used as a task runner only. |
@@ -137,7 +137,7 @@ from this skill.
137137
| `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. |
138138
| `Z3_LIBRARY_PATH_OVERRIDE` | unset | Directory containing an x64 system `libz3.lib`; not valid for ARM64. |
139139
| `Z3_SYS_Z3_HEADER` | unset | Full `z3.h` path required with a system Z3 library. |
140-
| `Z3_SYS_BUNDLED_DIR_OVERRIDE` | pinned cached source | Existing Z3 source tree containing `src/api/z3.h`. |
140+
| `Z3_SYS_BUNDLED_DIR_OVERRIDE` | pinned source cached under `CARGO_TARGET_DIR` when explicit, otherwise `%LOCALAPPDATA%\OpenShell\cache\z3` | Use an existing Z3 source tree containing `src/api/z3.h`; otherwise the wrapper fetches the pinned revision through Git and sets this automatically. |
141141
| `RUSTC_WRAPPER` | cleared by wrapper | The wrapper clears inherited values because `--skip-tools` does not provision `sccache`. |
142142

143143
Legacy fork variables such as `OPENSHELL_UPSTREAM`,
@@ -192,11 +192,11 @@ order:
192192
7. Artifact reporting.
193193

194194
The ARM64 check/build steps in this x64-host contract are cross-builds. The
195-
wrapper adds host-native LLVM to `PATH`, requires the ARM64 compiler and
196-
Spectre-mitigated libraries, lets ARM64 crypto crates select `clang-cl`, and
197-
keeps bundled Z3 on native MSVC `cl.exe` with CMake's Visual Studio ARM64
198-
generator. Do not substitute Ninja: `z3-sys 0.10.9` passes the MSBuild-only
199-
`-m` argument.
195+
wrapper discovers and adds host-native LLVM and Ninja to `PATH`, requires the
196+
ARM64 compiler and Spectre-mitigated libraries, lets ARM64 crypto crates select
197+
`clang-cl`, and keeps bundled Z3 on native MSVC `cl.exe` with CMake's Visual
198+
Studio ARM64 generator. Z3 does not use Ninja because `z3-sys 0.10.9` passes
199+
the MSBuild-only `-m` argument.
200200

201201
On ARM64 hosts, validate the native ARM64 check, build, and test path. The
202202
wrapper rejects test targets that do not match the host architecture, so x64
@@ -292,7 +292,14 @@ Useful log files:
292292
The first bundled-Z3 check or test can spend several minutes in CMake/MSBuild
293293
without much console output because Cargo output is redirected to the log. Look
294294
for native `MSBuild.exe` workers before treating the process as stalled. The
295-
artifact report computes SHA256 through .NET directly and does not rely on the
295+
wrapper fetches the pinned Z3 source through Git before Cargo starts. It caches
296+
under an explicitly configured `CARGO_TARGET_DIR`, or under the current user's
297+
local application data directory when Cargo uses its default target tree.
298+
Concurrent commands publish the validated source through an atomic directory
299+
rename, so x64 and ARM64 validation can share the cache safely. The wrapper does
300+
not rely on the rate-limited GitHub Contents API used by `z3-sys`. A failed
301+
fetch reports the partial checkout path for diagnosis. The artifact report
302+
computes SHA256 through .NET directly and does not rely on the
296303
`Get-FileHash` module being available inside the mise-launched Windows
297304
PowerShell process.
298305

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ For ARM64, verify the Visual Studio instance contains the ARM64 MSVC tools,
6868
ARM64 Spectre-mitigated libraries, Clang tools, CMake tools, and a Windows SDK.
6969
Clang supplies host-native `libclang.dll` for `bindgen` and `clang-cl.exe` for
7070
ARM64 crypto dependencies such as `ring` and `aws-lc-sys`. Native ARM64 uses
71-
the normal bundled-Z3 CMake path. An x64-to-ARM64 check/build uses CMake's
72-
Visual Studio ARM64 generator with native MSVC `cl.exe` for bundled Z3 while
73-
the crypto crates select `clang-cl`. Do not substitute Ninja: `z3-sys 0.10.9`
74-
passes the MSBuild-only `-m` argument. Use a short `CARGO_TARGET_DIR` if
75-
Windows path-length limits are reached.
71+
the normal bundled-Z3 CMake path. An x64-to-ARM64 check/build discovers and
72+
adds host-native Ninja to `PATH`, while the crypto crates select `clang-cl`.
73+
Bundled Z3 uses CMake's Visual Studio ARM64 generator with native MSVC `cl.exe`
74+
because `z3-sys 0.10.9` passes the MSBuild-only `-m` argument. Use a short
75+
`CARGO_TARGET_DIR` if Windows path-length limits are reached.
7676

7777
## Unsupported Driver Rules
7878

@@ -164,7 +164,7 @@ Likely causes:
164164

165165
- Native dependency does not support `aarch64-pc-windows-msvc`.
166166
- ARM64 MSVC or Spectre-mitigated libraries are missing.
167-
- Host-native `clang-cl` or CMake is missing during an x64-to-ARM64 build.
167+
- Host-native `clang-cl`, Ninja, or CMake is missing during an x64-to-ARM64 build.
168168
- `CL` or `_CL_` injects a global MSVC option such as `/MP4` into `clang-cl`.
169169
- Build script assumes x64 tools.
170170
- Inline assembly or prebuilt artifact lacks ARM64 handling.

‎architecture/windows-msvc-build.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ ARM64 validation requires the Visual Studio ARM64 MSVC tools, ARM64
9595
Spectre-mitigated libraries, host-native Clang tools, CMake tools, and an
9696
ARM64-capable Windows SDK. Clang provides `libclang.dll` for `bindgen` and
9797
`clang-cl.exe` for ARM64 crypto dependencies. During x64-to-ARM64 check/build,
98-
the wrapper lets `cmake-rs` select the Visual Studio ARM64 generator with native
99-
MSVC `cl.exe` for bundled Z3 so the Z3 build does not inherit the crypto crates'
100-
compiler requirement. The Visual Studio generator is also compatible with the
101-
MSBuild `-m` argument emitted by `z3-sys`; Ninja is not. Artifact hashing uses
102-
.NET SHA256 directly because module autoloading in the mise-launched Windows
103-
PowerShell process is not guaranteed.
98+
the wrapper discovers and adds the Visual Studio-bundled Ninja to `PATH` for
99+
native dependencies. It lets `cmake-rs` select the Visual Studio ARM64
100+
generator with native MSVC `cl.exe` for bundled Z3 so the Z3 build does not
101+
inherit the crypto crates' compiler requirement. Z3 stays on the Visual Studio
102+
generator because `z3-sys` emits an MSBuild-only `-m` argument that Ninja
103+
rejects. Artifact hashing uses .NET SHA256 directly because module autoloading
104+
in the mise-launched Windows PowerShell process is not guaranteed.
104105

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

‎tasks/scripts/windows-msvc.ps1‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,35 @@ function Resolve-LibclangPath {
257257
throw "Could not find libclang.dll. Install Visual Studio C++ Clang tools, or set LIBCLANG_PATH to the directory containing libclang.dll."
258258
}
259259

260+
function Resolve-NinjaPath {
261+
$fromPath = Get-Command ninja.exe -ErrorAction SilentlyContinue
262+
if ($fromPath) {
263+
return $fromPath.Source
264+
}
265+
266+
$programFilesX86 = [Environment]::GetEnvironmentVariable("ProgramFiles(x86)")
267+
if ($programFilesX86) {
268+
$vswhere = Join-Path $programFilesX86 "Microsoft Visual Studio\Installer\vswhere.exe"
269+
} else {
270+
$vswhere = $null
271+
}
272+
if ($vswhere -and (Test-Path $vswhere)) {
273+
$found = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.CMake.Project -find "Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe" | Select-Object -First 1
274+
if ($found -and (Test-Path $found -PathType Leaf)) {
275+
return (Resolve-Path $found).Path
276+
}
277+
}
278+
279+
foreach ($installRoot in Get-VsInstallRoots) {
280+
$candidate = Join-Path $installRoot "Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe"
281+
if (Test-Path $candidate -PathType Leaf) {
282+
return (Resolve-Path $candidate).Path
283+
}
284+
}
285+
286+
throw "Could not find ninja.exe. Install Microsoft.VisualStudio.Component.VC.CMake.Project."
287+
}
288+
260289
function Add-PathEntry([string] $Directory) {
261290
if (($env:PATH -split ";") -notcontains $Directory) {
262291
$env:PATH = "$Directory;$env:PATH"
@@ -274,8 +303,12 @@ function Configure-Arm64CrossBuild([string[]] $RustTargets) {
274303
}
275304
Add-PathEntry $env:LIBCLANG_PATH
276305

306+
$ninja = Resolve-NinjaPath
307+
Add-PathEntry (Split-Path -Parent $ninja)
308+
277309
Write-Host "==> ARM64 cross-build toolchain"
278310
Write-Host " clang-cl: $clangCl"
311+
Write-Host " ninja: $ninja"
279312
Write-Host " Z3: MSVC cl.exe with the Visual Studio generator"
280313
}
281314

0 commit comments

Comments
 (0)