Skip to content

native-wasmtime: Rust/wasmtime + wgpu reference backend#1

Open
Milky2018 wants to merge 2 commits intomainfrom
feat/native-wasmtime-backend
Open

native-wasmtime: Rust/wasmtime + wgpu reference backend#1
Milky2018 wants to merge 2 commits intomainfrom
feat/native-wasmtime-backend

Conversation

@Milky2018
Copy link
Collaborator

This adds a second native runtime backend implemented in Rust (Cargo), intended as a side-by-side reference implementation alongside the existing MoonBit/wasmoon runtime.

Changes:

  • New crate: mgstudio-runtime/native-wasmtime (wasmtime + winit + wgpu)
  • mgstudio-cli: add --backend wasmtime (default remains wasmoon)
  • mgstudio-cli: auto-build/run the Rust runtime (with overrides via MGSTUDIO_WASMTIME_RUNTIME and MGSTUDIO_WASMTIME_CARGO_TARGET)
  • Docs: usage + Apple Silicon notes

Notes:

  • On macOS arm64 (Apple Silicon), some wasm-gc carts may currently trigger a Cranelift AArch64 panic during compilation. A practical workaround is building the runtime for x86_64-apple-darwin and running under Rosetta.

@Milky2018
Copy link
Collaborator Author

Milky2018 commented Feb 2, 2026

Thanks for putting this together — having a reference Wasmtime/WGPU backend is useful for comparison.

However, I don’t think this PR is in a mergeable state for the main branch right now, mainly because it’s out of sync with the current direction of the repo:

  1. Outdated vs current SDK + moon.game.json design
  • Current main uses moon.game.json.sdkroot + CLI-built assets overlay and stages mgstudio-runtime-web.js from the SDK.
  • This PR’s mgstudio-cli/main/cmd_run.mbt relies on cfg.native_wgpu_lib (no longer exists) and introduces auto-discovery/build logic for the Rust runtime (searching upward for Cargo.toml). That conflicts with the “single source of truth” config approach.
  1. Introduces a second native runtime implemented in Rust (new toolchain + separate exe)
  • The repo currently focuses on a MoonBit native runtime (wasmoon JIT) and an SDK packaging story for darwin-arm64.
  • Adding a Rust runtime (plus Cargo.lock and a large amount of Rust code) significantly increases maintenance/CI scope. If we want this long-term, it probably belongs in a separate repo or behind an explicit experimental gate.
  1. Rebase required
  • As a single commit against an older base, it would effectively revert/remove multiple recent changes on main (SDK scripts/workflows, credits/licensing updates, etc.) when merged.

If you’d like to continue with this backend, I’d suggest:

  • Rebase onto the latest main first.
  • Remove repo-root auto-discovery/build behavior (no implicit upward search). The CLI should use moon.game.json.sdkroot only.
  • Decide whether the Rust runtime is (a) a separate optional component/repo, or (b) an experimental backend not shipped in the default SDK.
  • Add an explicit licensing/credits plan for the Rust dependency tree (wasmtime/wgpu/winit/etc.) if we plan to distribute binaries.

Given the above, my recommendation is: do not merge as-is; either convert to draft and rework, or move this backend to a separate experimental repository.

Adds a reference native runtime implemented in Rust (wasmtime + wgpu + winit), and wires mgstudio-cli --backend wasmtime to build/run it.
Rebase follow-up: remove repo-root auto-discovery/build for the wasmtime backend; prefer a runtime shipped in the SDK bin/ and allow explicit override via MGSTUDIO_WASMTIME_RUNTIME. Also update docs + add a third-party notices plan.
@Milky2018 Milky2018 force-pushed the feat/native-wasmtime-backend branch from abf5f97 to df4535b Compare February 2, 2026 08:22
@Milky2018
Copy link
Collaborator Author

Addressed the concerns from the review:

  • Rebased onto latest main.
  • Updated mgstudio-cli/main/cmd_run.mbt to match the current SDK + assets overlay flow (uses resolve_sdk_layout + staged overlay assets).
  • Removed repo-root auto-discovery and implicit cargo build behavior for the wasmtime backend.
    • CLI now looks for <sdkroot>/bin/mgstudio-runtime-native-wasmtime (optional/experimental), or you can explicitly set MGSTUDIO_WASMTIME_RUNTIME=/abs/path/to/mgstudio-runtime-native-wasmtime.
  • Updated CLI docs + runtime README accordingly, and added a concrete note/plan for third-party notices if we ever ship this runtime in an SDK (mgstudio-runtime/native-wasmtime/THIRD_PARTY_NOTICES.md).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant