Skip to content

Conversation

@dicej
Copy link
Collaborator

@dicej dicej commented Oct 23, 2025

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::TypeIds 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.

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>
@dicej dicej requested a review from alexcrichton October 23, 2025 20:20
@dicej dicej requested a review from a team as a code owner October 23, 2025 20:20
dicej added 3 commits October 23, 2025 14:46
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>
@dicej dicej enabled auto-merge October 23, 2025 21:00
@dicej dicej added this pull request to the merge queue Oct 23, 2025
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
I forgot to do this as part of bytecodealliance#2362 🤦

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@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
I forgot to do this as part of bytecodealliance#2362 🤦

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
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>
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.

2 participants