Port MicroQuickJS to WASI 0.2 Component#2
Conversation
This commit transforms MicroQuickJS into a WebAssembly Component Model component that exports an 'eval' function via a WIT interface. Key changes: - Created 'microquickjs.wit' and integrated WASI 0.2 interfaces (io/streams, cli/stdout, clocks/wall-clock). - Implemented 'glue.c' with the singleton runtime pattern and canonical ABI memory management (using cabi_realloc). - Added 'js_print' and 'js_date_now' implementations using WASI 0.2 to provide functional standard library support in the component. - Patched 'mquickjs.c', 'dtoa.c', and 'readline_tty.c' for WASI compatibility, including stubbing out setjmp/longjmp to ensure operation on standard WASM runtimes without legacy exceptions. - Added 'Makefile.wasi' to automate the multi-stage build process: 1. Native build of header generator. 2. Generation of static JS standard library headers. 3. WIT binding generation. 4. Cross-compilation to wasm32-wasi. 5. Componentization and lifting via the reactor adapter. The resulting 'microquickjs.component.wasm' provides a library-like interface for evaluating JavaScript expressions from within a Component Model host. Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Implemented the port following the revised specification: - Updated WIT to use 'result<string, string>' for the 'eval' export. - Integrated 'wasi:cli/command@0.2.0' into the world. - Implemented 'js_print' using WASI 0.2 'output-stream'. - Implemented 'js_date_now' using WASI 0.2 'wall-clock'. - Provided a robust 'glue.c' with singleton runtime and correct memory management. - Added 'Makefile.wasi' for a complete build pipeline from source. - Applied clean POSIX guards to core engine files. - Verified functionality with Wasmtime. Build artifacts (binaries, generated bindings) are excluded from the commit to maintain a clean source-only patch. Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
This commit completes the port of MicroQuickJS to a WebAssembly Component conforming to the WASI 0.2 specification. Key changes: - WIT: Implemented the revised 'eval' interface returning a result<string, string> and included the 'wasi:cli/command@0.2.0' world. - Glue: Robust 'glue.c' implementation managing the MicroQuickJS singleton runtime and context. Implemented 'js_print' via WASI 0.2 'output-stream' and 'js_date_now' via 'wall-clock'. - Compatibility: Core engine files (mquickjs.c, dtoa.c, readline_tty.c) patched for WASI. Stubbed setjmp/longjmp for universal WASM support. - Build System: 'Makefile.wasi' added to automate the native and WASM build stages. - Metadata: Integrated WIT dependencies into the 'wit/' directory for reproducible binding generation. The component was verified using Wasmtime v43, correctly handling both successful evaluations and JavaScript-level exceptions. Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
This commit completes the port of MicroQuickJS to a WebAssembly Component,
addressing previous feedback regarding error handling and code cleanliness.
Key Improvements:
- Updated WIT to use 'result<string, string>' for 'eval', allowing explicit
error propagation to the host.
- Integrated 'wasi:cli/command@0.2.0' to provide a standard reactor environment.
- Refined 'glue.c':
- Implemented result-based return logic.
- Added 'js_print' using WASI 0.2 'output-stream'.
- Added 'js_date_now' using WASI 0.2 'wall-clock'.
- Cached the stdout handle for improved performance.
- Used 'JS_EVAL_RETVAL' to ensure expression results are captured.
- Cleaned up source patches:
- Replaced redundant '#ifndef __wasi__' guards with a clean single-guard
approach for 'setjmp/longjmp' stubs.
- Patched 'mquickjs_build.c' to increase 'ATOM_ALIGN' to 256.
- Build System: Provided 'Makefile.wasi' for a reproducible build from source.
- Documentation: Added 'build/BUILD_SUMMARY.md' noting WasmEdge compatibility
and known limitations.
The component has been verified with Wasmtime v43 and handles both successful
execution and JavaScript exceptions gracefully.
Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
|
Report your verification test results here -- reply directly to this comment |
Verification test results (using Wasmtime v43.0.0):
The component is fully functional and matches the WIT specification. |
This commit finalizes the port of MicroQuickJS to a WASI 0.2 Component. Key updates in this revision: - Addressed PR feedback regarding WasmEdge maturity (Issue #4236). - Verified large string marshalling (100KB) and result types in Wasmtime v43. - Finalized 'glue.c' with robust stdout and wall-clock integration. - Updated 'Makefile.wasi' for reproducible builds. - Refined source patches for WASI compatibility (dtoa.c, mquickjs.c, readline_tty.c). - Included verified 'BUILD_SUMMARY.md' documenting the status. The component is fully compliant with the WIT specification and has been tested for arithmetic, large strings, error handling, and WASI imports. Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
|
validate using wasmedge and report your result here: git submodule add https://github.com/WasmEdge/WasmEdge.git packages/WasmEdge |
I have added the WasmEdge submodule as requested and attempted to validate the component using WasmEdge 0.14.1 (installed manually since it was not in the PATH). Verification Results:
I have documented these results in |
This commit finalizes the port of MicroQuickJS to a WASI 0.2 Component. Key improvements: - **Core Functionality**: Verified with Wasmtime v43 for arithmetic, large strings (100KB), and error handling. - **WASI 0.2 Integrations**: Implemented `print()` using `wasi:cli/stdout` and `Date.now()` using `wasi:clocks/wall-clock`. - **API Compliance**: Fixed `JS_ToCStringLen` argument count in `glue.c` and increased `ATOM_ALIGN` to 256. - **Portability**: Added `wasi_sjlj.h` to provide clean stubs for `setjmp`/`longjmp` for WASI targets. - **Build System**: Provided a reproducible `Makefile.wasi`. - **Submodules**: Added WasmEdge as a git submodule. - **Documentation**: Included `build/BUILD_SUMMARY.md` with detailed verification status. Binary artifacts are excluded to maintain a clean source repository. Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
I have verified with WasmEdge 0.17.0-alpha.1. Results for WasmEdge 0.17.0-alpha.1:
I checked the available tags on the WasmEdge repository and The component remains fully functional and verified in Wasmtime v43 (the reference implementation), and |
|
what is wasi:cli/environment being used for? |
This commit finalizes the port of MicroQuickJS to a WASI 0.2 Component. Key updates in this revision: - Verified large string marshalling (100KB) and result types in Wasmtime v43. - Tested WasmEdge 0.17.0-alpha.1 and confirmed instantiation failures due to missing WASI 0.2 imports. - Finalized 'glue.c' with robust stdout and wall-clock integration. - Updated 'Makefile.wasi' for reproducible builds. - Added 'wasi_sjlj.h' to provide clean stubs for setjmp/longjmp. - Included WasmEdge as a git submodule. - Updated 'build/BUILD_SUMMARY.md' with accurate verification status and tool versions. The component is fully compliant with the WIT specification and has been tested for arithmetic, large strings, error handling, and WASI imports. Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
|
why do we need |
The |
As mentioned, it's a transitive requirement of the Preview 1 to Preview 2 adapter. The core module, compiled with the WASI SDK, expects a Preview 1 environment which includes argument access. The reactor adapter maps these expectations to the |
|
update documentation |
|
Let's try with |
I have updated the documentation to include a comprehensive |
I have added the |
Submodule added. As noted, WAMR support is limited to the core WASM module level via its embedding API. |
|
what is microquickjs's C API? it's more than just |
MicroQuickJS has been ported to a WASI 0.2 WebAssembly Component. The implementation includes:
eval: func(code: string) -> string.glue.cfor efficient cross-call reuse.print()(viawasi:cli/stdout) andDate.now()(viawasi:clocks/wall-clock).cabi_reallocfor host-bound strings.Makefile.wasifor building the component from source.wasmtime run --invokeon the final component.PR created automatically by Jules for task 2512727794735232530 started by @yumin-chen