[MicroVM] Update Nanvix to v0.15.4#362
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Windows MicroVM (NanVix) backend to NanVix 0.15.4, switching execution to NanVix’s warm-start snapshot protocol and updating the on-disk artifact layout and staging layer accordingly.
Changes:
- Update NanVix artifact layout to use
python3.initrd, addbin/(forkernel.elf) andsnapshots/, and refresh pinned versions/checksums. - Generate WHP snapshots at build time (and on-demand at runtime if missing) and invoke
nanvixdusing-snapshot ... -bin-dir ... -- python3.initrd. - Simplify MicroVM staging to produce a single
bootstrap.py(preamble + rewritten user script) and expand unit tests.
Show a summary per file
| File | Description |
|---|---|
| src/wxc/build.rs | Switch to shared helper for copying NanVix artifacts (flat + bin/ + snapshots/) next to wxc-exec.exe. |
| src/wxc_common/src/nanvix_runner.rs | Add snapshot-home resolution, warm-start invocation, and stderr piping/draining. |
| src/wxc_common/src/microvm_staging.rs | Replace two-file staging (.mxc-*) with single bootstrap.py; add extensive new tests. |
| src/wxc_common/Cargo.toml | Add nanvix_common dependency (Windows-only) for shared constants/helpers. |
| src/nanvix_common/src/lib.rs | Introduce new layout constants, snapshot generation helper, and artifact copy helper. |
| src/nanvix_binaries/build.rs | Update download/extract for new layout and generate snapshots at build time. |
| src/nanvix_binaries/versions.json | Bump NanVix release tag and update expected binary list. |
| src/nanvix_binaries/checksums.json | Refresh SHA256 hashes (including kernel.elf). |
| src/Cargo.lock | Add nanvix_common to the lockfile dependency graph. |
Copilot's findings
- Files reviewed: 8/9 changed files
- Comments generated: 6
3d77113 to
a9fdd73
Compare
520de4f to
caa3025
Compare
huzaifa-d
reviewed
May 21, 2026
Updates the Nanvix toolchain from 0.12.529 to 0.15.4 and switches the runner to Nanvix's warm-start snapshot protocol, dropping the explicit guest Python command line in favor of a multi-binary initrd. Binary layout changes: - Replace flat `python3.12` sidecar with a single `python3.initrd` multi-binary archive (daemons + CPython) loaded by Nanvix at warm start. - Move `kernel.elf` into a `bin/` subdirectory next to wxc-exec.exe so that nanvixd can locate it via `-bin-dir` as it now expects. - Add a `snapshots/` subdirectory holding the WHP snapshot pair (`kernel.vmem` + `kernel.whp.cbor`) used to restore VM state directly instead of cold-booting on every execution. - Refresh `versions.json` / `checksums.json` for the new release artifacts. Build-time changes (`nanvix_binaries/build.rs`): - Extend the download/extract path to populate the new `bin/` subdir and verify its checksums alongside the flat binaries. - After download, pre-generate the WHP snapshots locally via a one-shot nanvixd cold boot so even the first runtime execution is warm. - Remove the legacy partial-binary cleanup since the new layout no longer ships those files. Runtime changes (`wxc_common/src/nanvix_runner.rs`): - Introduce a `ResolvedPaths` struct and `resolve_snapshot_home()` that picks `$NANVIX_HOME` → OS-local data path (`%LOCALAPPDATA%\nanvix` or `~/.local/share/nanvix`) → `<exe>` as a fallback. - If no snapshot is present (e.g. fresh install or env override), generate one on demand via cold boot; subsequent runs restore from the snapshot. - Spawn nanvixd with `-snapshot snapshots/kernel.whp.cbor -bin-dir <exe>/bin -ramfs … -mount … -- python3.initrd`, dropping the old `python3.12 -S -B …;PYTHONHOME=/sysroot` guest cmdline since the warm-start protocol auto-executes the initrd entry point. - Pipe nanvixd stderr and drain it before `wait()` to surface guest diagnostics on failure without blocking the child on a full pipe. Staging changes (`wxc_common/src/microvm_staging.rs`): - Drop the separate `.mxc-bootstrap.py` + `.mxc-script.py` pair. The warm-start protocol executes a single `bootstrap.py` automatically, so the staging layer now writes one file consisting of a small `sys.argv` preamble followed by the (path-rewritten) user script. - Update tests for the single-file layout. Shared helpers (`nanvix_common`): - Add `BIN_SUBDIR`, `SNAPSHOTS_SUBDIR`, `BIN_SUBDIR_FILES`, and `SNAPSHOT_FILES` constants describing the new on-disk layout. - Add `generate_snapshot()` (shared by the build script and runtime fallback) and `copy_artifacts_to_target()` (used by `wxc/build.rs` to stage flat binaries, `bin/`, and `snapshots/` next to the output exe). - Add `wxc_common` → `nanvix_common` dependency (Windows-only) and simplify `wxc/build.rs` to delegate to the shared copy helper.
Adds additional unit tests for the microvm staging layer to lock in existing behavior and guard against regressions. No production code changes. New tests in `wxc_common::microvm_staging`: - Path validation: reject `..` traversal components in staged paths (`staging_rejects_path_with_parent_dir_component`). - Mixed RW + RO staging: both subdirectories are created and file contents land at the expected guest-relative locations (`staging_mixed_rw_and_ro_paths`). - Staging overhead heuristic: near-zero overhead for empty stagings and the 30-second cap is honored for oversized inputs (`staging_overhead_ms_scales_with_size`, `staging_overhead_ms_capped_at_30s`). - `preserved_path()` returns `None` when nothing was preserved. - Host→guest path conversion: trailing slashes are stripped and the drive letter is lowercased (`host_path_to_guest_relative_handles_trailing_slash`, `host_path_to_guest_relative_lowercase_drive`). - Script rewriting: escaped backslash literals (`C:\\Users\\…`) are rewritten, and overlapping prefixes are matched longest-first so a shorter mapping cannot partially shadow a longer one (`rewrite_paths_handles_escaped_backslashes`, `rewrite_paths_longer_prefix_first`). - `build_guest_path()` format check for both `rw` and `ro` categories. - Empty user script produces a bootstrap consisting solely of the preamble (`staging_empty_script`). - RW copy-back round-trips modified deep files and newly created files back to the host (`staging_nested_directory_rw_copyback`). - `sweep_orphaned_staging_dirs()` is a no-op on a non-existent root. - Concurrent stagings under the same root get unique directory names (`staging_dir_has_unique_names`).
The "Verify MicroVM binaries" step in the MicroVM E2E workflow still asserted the pre-0.15.4 on-disk layout and would fail (or silently miss files) after a309530, which switched the runner to Nanvix's warm-start snapshot protocol and reorganized the staged artifacts. Align the required-file list with the new layout described by `nanvix_common` (`REQUIRED_BINARIES`, `BIN_SUBDIR_FILES`, `SNAPSHOT_FILES`): - Drop the flat `python3.12` sidecar; replace with `python3.initrd` (the multi-binary initrd loaded by Nanvix at warm start). - Move `kernel.elf` under the new `bin\` subdirectory that nanvixd locates via `-bin-dir`. - Add the WHP snapshot pair under `snapshots\` (`kernel.vmem` and `kernel.whp.cbor`) that `nanvix_binaries/build.rs` now pre-generates so the first runtime execution is warm. Also adjust the `Get-ChildItem -Include` listing to use leaf names (since `-Include` matches against the file name, not a subpath) and print `FullName` so the subdirectory placement is visible in CI logs. No behavior change for the test run itself; this only fixes the verification gate that guards it.
ac55ac9 to
9ad8ba0
Compare
huzaifa-d
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📖 Description
Updates the MicroVM (NanVix) backend to Nanvix 0.15.4 and switches the runner to NanVix's warm-start snapshot protocol, dropping the explicit guest Python command line in favor of a multi-binary
python3.initrd. Cold-boot latency on the hot path drops by restoring a pre-generated WHP snapshot instead of re-booting the guest on every execution. Also expands themicrovm_stagingunit-test coverage to lock in the new single-file bootstrap layout and pre-existing path-rewriting / staging behavior.Binary layout
python3.12sidecar with a singlepython3.initrdmulti-binary archive (daemons + CPython) loaded by NanVix at warm start.kernel.elfinto abin/subdirectory next towxc-exec.exesonanvixdcan locate it via-bin-diras it now expects.snapshots/subdirectory holding the WHP snapshot pair (kernel.vmem+kernel.whp.cbor).versions.json/checksums.jsonfor the new release artifacts.Build-time changes (
nanvix_binaries/build.rs)bin/subdir and verify its checksums alongside the flat binaries.nanvixdcold boot so even the first runtime execution is warm.Runtime changes (
wxc_common/src/nanvix_runner.rs)ResolvedPathsandresolve_snapshot_home()that picks$NANVIX_HOME→ OS-local data path (%LOCALAPPDATA%\nanvixor~/.local/share/nanvix) →<exe>as a fallback.nanvixdwith-snapshot snapshots/kernel.whp.cbor -bin-dir <exe>/bin -ramfs … -mount … -- python3.initrd, dropping the oldpython3.12 -S -B …; PYTHONHOME=/sysrootguest cmdline since warm-start auto-executes the initrd entry point.nanvixdstderr and drain it beforewait()to surface guest diagnostics on failure without blocking the child on a full pipe.Staging changes (
wxc_common/src/microvm_staging.rs).mxc-bootstrap.py+.mxc-script.pypair. The warm-start protocol executes a singlebootstrap.pyautomatically, so the staging layer now writes one file consisting of a smallsys.argvpreamble followed by the (path-rewritten) user script.Shared helpers (
nanvix_common)BIN_SUBDIR,SNAPSHOTS_SUBDIR,BIN_SUBDIR_FILES, andSNAPSHOT_FILESconstants describing the new on-disk layout.generate_snapshot()(shared by the build script and runtime fallback) andcopy_artifacts_to_target()(used bywxc/build.rsto stage flat binaries,bin/, andsnapshots/next to the output exe).wxc_common→nanvix_commondependency (Windows-only) and simplifywxc/build.rsto delegate to the shared copy helper.New
microvm_stagingtests..traversal components in staged paths.preserved_path()returnsNonewhen nothing was preserved.C:\\Users\\…) and matches overlapping prefixes longest-first.build_guest_path()format check for bothrwandrocategories.sweep_orphaned_staging_dirs()is a no-op on a non-existent root.🔗 References
Related docs: docs/nanvix-microvm/nanvix.md, docs/nanvix-microvm/nanvix-integration-plan.md.
🔍 Validation
cargo build --release --features microvmonx86_64-pc-windows-msvc— fetches the 0.15.4 artifacts, verifies checksums, generates the WHP snapshot at build time, and stagesbin/+snapshots/next towxc-exec.exe.cargo test -p wxc_common— new and existingmicrovm_stagingunit tests pass.examples/01_hello_world.jsonand a multi-file RW/RO config execute end-to-end on the warm-start path; cold-boot fallback exercised by deletingsnapshots/and rerunning.$NANVIX_HOMEoverride and the%LOCALAPPDATA%\nanvixdefault both resolve correctly and trigger on-demand snapshot generation when missing.✅ Checklist
📋 Issue Type
Microsoft Reviewers: Open in CodeFlow