1 of 5

Adding core module “build targets” for WIT

June 13, 2024

WASI SG

2 of 5

Motivation

  • Support adding new wasip2 (and beyond) functionality to existing core engines
    • Adding core imports is easier than implementing the whole component model
    • Some use cases only want one core module (and a working producer toolchain)
    • Let’s minimize the effort to transition from wasip1 to wasip2
      • Complementing the major effort already (see: wasip1-to-p2 adapter)
  • As discussed in (lots of places, including):
    • https://github.com/WebAssembly/WASI/issues/595

3 of 5

Idea

  • Add a core module “build target” to Preview 2

parse+resolve

(component� (import “wasi:filesystem/types” (instance …))

)

(module� (import “wasi:filesystem/types” “descriptor.read”� (func (param i32 i64 i64 i32))

)

Canonical ABI

<:

<:

wasi-sdk --target=wasm32-wasip2-module

wasi-sdk --target=wasm32-wasip2-component

.c

.c

.c

clang

.o.wasm

.o.wasm

.o.wasm

core�module

wasm-ld

component

wasm-�component-ld

wasm-tools�component�new

^^ both official Preview 2 “targets”

or: GOOS=wasip2 -buildmode=module|component

Access to full component-model feature set:

  • Shared-everything dynamic linking (e.g., cpython)
  • Shared-nothing cross-language reuse
  • Tweak the ABI: latin1+utf16, gc, custom realloc, …

Easy to add to existing core wasm engines�or if you don’t benefit from components

package wasi:cli;

world command {

import wasi:filesystem/types;

}

component�runtime

supports

core-only�runtime

supports

(basic plan since day 1)

Can add additional module build targets�(e.g. wasm64-wasip2-module)

4 of 5

What about…

  • Avoiding cabi_realloc
    • We can address this problem orthogonally.
    • Rough idea (generalizing CM/#304):
      • resource file-descriptor {� read: func(length: u64, offset: u64) -> result<list<u8; ..length>,error-code>;�}
      • (func (param $fd i32) (param $length i64) (param $offset i64) (param $outp i32))
  • “wasit2” (idea in GitHub comment)
    • Renamed and split into two orthogonal tasks
      • “define a core module target” (wasm32-wasip2-module)
      • “provide a way to avoid cabi_realloc” (list<u8; ..n>)

5 of 5

Next steps

  • Working on new BuildTargets.md in: