Stream: general

Topic: Wit to wasm metadata


view this post on Zulip Paul Scheduikat (Feb 06 2024 at 11:33):

package example:add;

interface add {
    add: func(a: u32, b: u32) -> u32;
}

world adder {
    export add;
}

world anotheradder {
    export add;
}

I have the following .wit file, now when I compile the adder component with cargo component why isn't the wit metadata (the world and package name) included in the component?

$ wasm-tools component wit target/wasm32-wasi/release/adder.wasm
package root:component;

world root {
  export example:add/add;
}

I think it should instead be:

package example:add;

world adder {
  export example:add/add;
}

view this post on Zulip Paul Scheduikat (Feb 06 2024 at 11:38):

This would make it easier to verify if a component targets a world, because right now I have to.

$ wasm-tools component targets -w adder ./wit/world.wit target/wasm32-wasi/release/adder.wasm

It would be a lot easier to just be able to:

$ wasm-tools component targets ./wit/world.wit target/wasm32-wasi/release/adder.wasm

Maybe wasm-tools could even be helpful and output that the component targets the adder world.

view this post on Zulip Paul Scheduikat (Feb 06 2024 at 13:06):

Also maybe comments of the wit file can be retained in the component for documentation

view this post on Zulip Alex Crichton (Feb 06 2024 at 15:42):

the name of a world and the origin of its package is lost when you create a component, only the provenance of interface items is retained. The wasm-tools component wit subcommand effectively synthesizes the strings "root" and "component" there in package root:component; and world root. In that sense you won't be able to retain world adder or world anotheradder. There's various reasons for this I can expand on if you're interested as well.

As for documentation, that'd be nice to have! The WIT-to-wasm-encoded-WIT preserves comments, but we currently don't preserve comments when a component itself is created. That seems like a good idea though! If you're up for it mind opening an issue?

view this post on Zulip Paul Scheduikat (Feb 06 2024 at 16:28):

The issue would need to be opened for cargo component right?

view this post on Zulip Paul Scheduikat (Feb 06 2024 at 16:31):

If those synthetic names are needed for some implementation/ specification reason, can the original world and package maybe be included as metadata in the binary which is then used by tools like "targets".

view this post on Zulip Paul Scheduikat (Feb 06 2024 at 16:45):

Something like this

;; rootFromWorld=adder
;; rootFromPackage=example:add

view this post on Zulip Paul Scheduikat (Feb 06 2024 at 17:06):

https://github.com/bytecodealliance/cargo-component/issues/229

Comments from the wit file are already, copied to the bindings.rs file. These should also be contained in the final component, so that wasm-tools component wit can provide some useful documentation...

view this post on Zulip Alex Crichton (Feb 06 2024 at 19:34):

Oh sorry this'd probably be an issue for the wasm-tools repo, but we can take it from here! Thanks!

view this post on Zulip Alex Crichton (Feb 06 2024 at 19:34):

(busy day for me)

view this post on Zulip Pat Hickey (Feb 06 2024 at 19:40):

i caught this on github before zulip but https://github.com/WebAssembly/component-model/issues/213 is the CM spec issue about this

This has been discussed. Formally, creating an issue for it. Currently, we lose comments / docs from Wit text formats when compiling to the binary Wasm component file format. This is especially an ...

view this post on Zulip Pat Hickey (Feb 06 2024 at 19:41):

agree that an issue for implementing it would need to be on BytecodeAlliance/wasm-tools


Last updated: Nov 22 2024 at 16:03 UTC