Stream: general

Topic: Wasm Components and WasmGC


view this post on Zulip Lucas Ávila (Nov 03 2023 at 15:21):

Do you know if there is a runtime or mechanism to test Components that use Wasm GC? I'm building a toy compiler that targets both and I'd like to test the output.
Latest Firefox and Chrome support WasmGC, but no components.
The reference interpreter https://github.com/WebAssembly/gc/tree/main/interpreter supports GC but no components.
https://github.com/bytecodealliance/wasm-tools and wasmtime lacks support for GC.

I know there is work in progress to support WasmGC on wasm-tools and wasmtime, but I'm asking here because you might know an alternative for the short term.

Thanks in advance :)

Low level tooling for WebAssembly in Rust. Contribute to bytecodealliance/wasm-tools development by creating an account on GitHub.

view this post on Zulip Joel Dice (Nov 03 2023 at 15:25):

jco supports components in web browsers (including Firefox and Chrome). I haven't tried using WasmGC in a component myself, though -- I'll be interested to hear how it goes.

JavaScript tooling for working with WebAssembly Components - GitHub - bytecodealliance/jco: JavaScript tooling for working with WebAssembly Components

view this post on Zulip Joel Dice (Nov 03 2023 at 15:26):

But yeah, if wasm-tools won't be able to help you create such a component, you may be stuck.

view this post on Zulip Alex Crichton (Nov 03 2023 at 16:02):

I'm also not aware of anything for in the short term unfortunately. The component-related tooling I know of all goes through wasm-tools so that's required to get updated first.

view this post on Zulip Slava Kuzmich (Nov 19 2023 at 19:45):

I would love to try wasm-tools with Wasm GC modules produced by Kotlin toolchain. I'm seeing some progress in GC support and wondering if there is a place to track its readiness?

view this post on Zulip Alex Crichton (Nov 20 2023 at 03:01):

currently we don't have a tracking issue or location for all the various bits of work, fitzgen (currently on vacation) is doing most of the work at the moment and would know best

view this post on Zulip Slava Kuzmich (Jan 03 2024 at 17:35):

The main branch of wasm-tools is now able to parse some of the WasmGC modules produced by Kotlin toolchain :tada: . Thanks fitzgen!

I'm trying to set up a full pipeline for experimenting with Components and WASI Preview2, while using some library code that currently uses Preview1 reactor ABI, and without built-in Component support in compiler. Does the following sequence make sense?

  1. (optional) wit-bindgen: world.wit -> bindings.kt
  2. Compiler: *.kt -> core.wasm
  3. (optional) wasm-tools component embed --encoding=utf16 world.wit core.wasm -o core.wasm
  4. wasm-tools component new --adapt wasi_snapshot_preview1.reactor.wasm core.wasm -o component.wasm
  5. jco transpile component.wasm -o out-dir
  6. Run out-dir in Node.js

At the step 4 I had troubles with wasm-tools component new not validating modules with wasm exceptions and GC. I hacked WasmFeatures::default() to return WasmFeatures::all() to unblock myself locally and it worked! Would it make sense to add an CLI flag to skip validation or enable non-default features?

I also tried to hack GC support into jco transpile and got bumped by assertion failed: ty.is_final in wasmtime-environ. I didn't know jco used wasmtime under the hood.

view this post on Zulip Pat Hickey (Jan 03 2024 at 18:08):

yes, jco uses wasmtime-environ as the implementation of the algorithm that parses components into modules and a description of how to instantiate them

view this post on Zulip Pat Hickey (Jan 03 2024 at 18:09):

theres no wasmtime present at runtime, its just used for code generation

view this post on Zulip Alex Crichton (Jan 03 2024 at 18:32):

Would it make sense to add an CLI flag to skip validation or enable non-default features?

Good find! I think it makes sense to use ::all() there

view this post on Zulip Slava Kuzmich (Apr 18 2024 at 11:18):

We use a trick to test components with WasmGC and jco. First, to make jco happy, we give jco transpile a component with a "stub" of the core wasm module, using Wasm 1.0 imports and unreachable-bodied exports, but no GC. Then, we swap out this transpiled stub with a real WasmGC core module and run it in Node.js. You can find the setup here: https://github.com/skuzmich/kotlin-wasm-cm-experiments

Experiments with running Kotlin/Wasm with Component Model - skuzmich/kotlin-wasm-cm-experiments

Last updated: Nov 22 2024 at 16:03 UTC