various `wit-dylib` API tweaks by dicej · Pull Request #2362 · bytecodealliance/wasm-tools

@dicej

I've recently ported `componentize-py` to use `wit-dylib` instead of its own
Wasm code generator and found it useful to tweak the `wit-dylib` APIs a bit.

The main idea here is to give `componentize-py` (and any similar build tool)
access to the metadata generated by `wit-dylib` _before_ the guest runs, as well
as match the types in that metadata up with the `wit_parser::TypeId`s from the
input world.  That allows the build tool to generate high-level binding code
ahead of time and later match it up with the metadata at runtime.

Specifically, this commit does the following:

- Add a `wit_dylib::create_with_metadata` function which returns both the generated module and the `Metadata` object produced for it.
- Add `id: TypeId` fields to all the "WIT type types" so that they can be matched up with the corresponding `wit-parser` types
- Add `index` methods to the `wit-dylib-ffi` wrapper types, allowing the interpreter to determine where the instance appears in its respective array
- Split the metadata `Function` type into separate `ImportFunction` and `ExportFunction` types, each with its own array in the `Wit` structure.  Imported and exported functions are used very differently by interpreters; separating them makes them easier to deal with.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

alexcrichton

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>

Merged via the queue into bytecodealliance:main with commit 65e5924

Oct 23, 2025

34 checks passed

@dicej dicej deleted the wit-dylib-api-tweaks branch

October 23, 2025 21:20

dicej added a commit to dicej/wasm-tools that referenced this pull request

Oct 23, 2025

@dicej dicej mentioned this pull request

Oct 23, 2025

dicej added a commit to dicej/wasm-tools that referenced this pull request

Oct 23, 2025

github-merge-queue bot pushed a commit that referenced this pull request

Oct 23, 2025
I forgot to do this as part of #2362 🤦

Signed-off-by: Joel Dice <joel.dice@fermyon.com>