Skip to content

Package MicroQuickJS as a WASI 0.2 Component#7

Open
yumin-chen wants to merge 5 commits into
mainfrom
feat/microquickjs-wasi-component-272671185353916062
Open

Package MicroQuickJS as a WASI 0.2 Component#7
yumin-chen wants to merge 5 commits into
mainfrom
feat/microquickjs-wasi-component-272671185353916062

Conversation

@yumin-chen

Copy link
Copy Markdown

Implemented the MicroQuickJS WASI 0.2 component.

Includes:

  1. microquickjs.wit: WIT interface definition for the JS engine.
  2. glue.c: C implementation of the WIT interface, providing a persistent singleton JS context over a 4 MiB static arena and managing GC roots for JS values exposed to the host.
  3. Makefile.wasi: A dedicated build system for cross-compiling to wasm32-wasi and composing the final component using wit-bindgen and wasm-tools.
  4. Increased ATOM_ALIGN in mquickjs_build.c to prevent property overflows during stdlib generation.

The component supports eval, JS value construction (int32, float64, bool, string, object, array), property manipulation, and function calls across the component boundary. It uses setjmp/longjmp lowered via WebAssembly Exception Handling (SJLJ) for error recovery.


PR created automatically by Jules for task 272671185353916062 started by @yumin-chen

This commit introduces the necessary infrastructure to package MicroQuickJS
as a self-contained WASI 0.2 component.

Key changes:
- Created 'microquickjs.wit' defining the 'engine' interface.
- Implemented 'glue.c' to bridge the WIT interface with MicroQuickJS, including
  singleton context management and GC rooting for exported values.
- Added 'Makefile.wasi' for the component build pipeline (supporting Path A).
- Patched 'mquickjs_build.c' to increase 'ATOM_ALIGN' to 256.
- Implemented WASI compatibility stubs in 'glue.c' returning 'JS_UNDEFINED'.
- Ensured ABI safety in 'glue.c' by avoiding NULL returns for WIT strings.

The implementation preserves existing native build targets and uses a static
4 MiB arena for predictable memory footprint.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

This commit introduces the necessary infrastructure to package MicroQuickJS
as a self-contained WASI 0.2 component.

Key changes:
- Created 'microquickjs.wit' defining the 'engine' interface.
- Implemented 'glue.c' to bridge the WIT interface with MicroQuickJS, including
  singleton context management and GC rooting for exported values.
- Added 'Makefile.wasi' for the component build pipeline (supporting Path A).
- Patched 'mquickjs_build.c' to increase 'ATOM_ALIGN' to 256.
- Implemented WASI compatibility stubs in 'glue.c' returning 'JS_UNDEFINED'.
- Ensured ABI safety in 'glue.c' by avoiding NULL returns for WIT strings.

The implementation preserves existing native build targets and uses a static
4 MiB arena for predictable memory footprint.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
@Chen-Software Chen-Software deleted a comment from google-labs-jules Bot Apr 12, 2026
This commit introduces the necessary infrastructure to package MicroQuickJS
as a self-contained WASI 0.2 component.

Key changes:
- Created 'microquickjs.wit' defining the 'engine' interface.
- Implemented 'glue.c' to bridge the WIT interface with MicroQuickJS, including
  singleton context management and GC rooting for exported values.
- Added 'Makefile.wasi' for the component build pipeline.
- Patched 'mquickjs_build.c' to increase 'ATOM_ALIGN' to 256.
- Implemented WASI compatibility stubs in 'glue.c' returning 'JS_UNDEFINED'.
- Ensured ABI safety in 'glue.c' by avoiding NULL returns for WIT strings.

The implementation preserves existing native build targets and uses a static
4 MiB arena for predictable memory footprint.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

the changes should be backwards compatible -- Makefile should still build for non-wasi native buidls

I have verified that the changes are backwards compatible. The original Makefile remains unchanged and successfully builds the native 'mqjs' and 'example' targets, and all native tests pass. The WASI component build is isolated in the new Makefile.wasi.

google-labs-jules Bot and others added 2 commits April 13, 2026 22:12
…ckwards compatibility

- WIT interface defined in 'microquickjs.wit'.
- C glue layer in 'glue.c' with singleton context and GC rooting.
- Dedicated 'Makefile.wasi' for component build.
- Ensured backwards compatibility: native targets build and pass tests.
- Addressed PR feedback:
  - WASI stubs return 'JS_UNDEFINED'.
  - String conversion avoids NULL returns for WIT strings.
  - Increased ATOM_ALIGN for larger stdlib support.
- Cleaned up build artifacts.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
This commit addresses the final set of requirements and review comments:
- Integrated 'make test' and 'make microbench' into 'Makefile.wasi' using a wasm32-wasip2 CLI build.
- Provided 'readline_tty_wasi.c' to enable non-interactive WASI CLI execution.
- Updated 'mquickjs_build.c' to produce non-static, ABI-compatible headers for WASM.
- Documented WASI build and test instructions in 'README.md'.
- Ensured full backwards compatibility with the existing native build system.
- All code changes are production-ready and cleaned of build artifacts.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
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