Stream: git-wasmtime

Topic: wasmtime / PR #9788 Revamp wasi example and related docs


view this post on Zulip Wasmtime GitHub notifications bot (Dec 11 2024 at 17:09):

ifsheldon opened PR #9788 from ifsheldon:revamp-wasi to bytecodealliance:main:

Closes #9777

For now, this is a draft PR because there's a runtime issue in the revamp example. Please see the FIXME in examples/wasi/main.rs. Probably @alexcrichton can help a bit? Thanks!

When the runtime issue is fixed, I will try to revamp more sections in the related doc in following commits.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 11 2024 at 17:12):

ifsheldon edited PR #9788:

Closes #9777

For now, this is a draft PR because there's a runtime issue in the revamp example. Please see the FIXME in examples/wasi/main.rs. There I want to invoke the exported wasi:cli/run@0.2.0 function, which is the main function in examples/wasi/wasm/wasi.rs. Probably @alexcrichton or @fitzgen can help a bit? Thanks!

When the runtime issue is fixed, I will try to revamp more sections in the related doc in following commits.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 12 2024 at 16:45):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 12 2024 at 16:45):

alexcrichton created PR review comment:

I might recommend not using an exact rustc version here or just omitting this entirely. All relatively recent rust toolchains will give an error "this is too old" already so it's probably sufficient to just say "have rust installed" here

view this post on Zulip Wasmtime GitHub notifications bot (Dec 12 2024 at 16:45):

alexcrichton created PR review comment:

For this, would this example help?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 13 2024 at 02:53):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 13 2024 at 02:53):

ifsheldon submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 13 2024 at 02:53):

ifsheldon created PR review comment:

updated

view this post on Zulip Wasmtime GitHub notifications bot (Dec 13 2024 at 02:54):

ifsheldon submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 13 2024 at 02:54):

ifsheldon created PR review comment:

Yes, thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Dec 13 2024 at 02:58):

ifsheldon commented on PR #9788:

But now there comes another issue: this hello-world example is just too specific to wasi:cli, since we used a specific wasmtime_wasi::bindings::sync::Command to run a wasi:cli/command. For a more general component, we need to add another example or at least give a pointer.

BTW, I still don't know why I could not get a Func to execute the run function in wasi:cli/run.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 13 2024 at 17:33):

alexcrichton commented on PR #9788:

Personally I think it's reasonable to start with hello-world like this and then graduate up to other examples. For example this page could link to the bindgen_examples page and that could get expanded with a custom world for example (IIRC there may already be one there?)

BTW, I still don't know why I could not get a Func to execute the run function in wasi:cli/run.

You needed another invocation of get_export. You loaded the exported instance but you'll need to load the exported function of that instance as well.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 12:54):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 12:59):

ifsheldon edited PR #9788:

Closes #9777

For now, this is a draft PR because there's a runtime issue in the revamp example. Please see the FIXME in examples/wasi/main.rs. There I want to invoke the exported wasi:cli/run@0.2.0 function, which is the main function in examples/wasi/wasm/wasi.rs. Probably @alexcrichton or @fitzgen can help a bit? Thanks!

When the runtime issue is fixed, I will try to revamp more sections in the related doc in following commits

Updated:

This PR revamps the examples wasi and wasi-async with latest updates from wasmtime and wasmtime-wasi and uses WASIp2 APIs by default. Related documentation is also updated.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 12:59):

ifsheldon has marked PR #9788 as ready for review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 12:59):

ifsheldon requested dicej for a review on PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 12:59):

ifsheldon requested wasmtime-core-reviewers for a review on PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 12:59):

ifsheldon requested wasmtime-default-reviewers for a review on PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 13:00):

ifsheldon commented on PR #9788:

OK, I think this draft PR seems good to me now, so I turned it into a formal PR.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 13:43):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 13:54):

ifsheldon commented on PR #9788:

You needed another invocation of get_export. You loaded the exported instance but you'll need to load the exported function of that instance as well.

OK, got that. I also added related code in the example to demonstrate how to do that.

BTW, do you know why ComponentNamedList is implemented for tuple (A1,) but not A1? This is bit counter-intuitive when I want to write something like func.typed::<(), Result<(), ()>>(&store), which rustc complains about not implementing ComponentNamedList. I really didn't know how to fix this error until I lookup Implementations on Foreign Types section of ComponentNamedList.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 13:55):

ifsheldon edited a comment on PR #9788:

You needed another invocation of get_export. You loaded the exported instance but you'll need to load the exported function of that instance as well.

OK, got that. I also added related code in the example to demonstrate how to do that.

BTW, do you know why ComponentNamedList is implemented for tuple (A1,) but not A1? Should I file another issue for this? This is bit counter-intuitive when I want to write something like func.typed::<(), Result<(), ()>>(&store), which rustc complains about not implementing ComponentNamedList. I really didn't know how to fix this error until I lookup Implementations on Foreign Types section of ComponentNamedList.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 14 2024 at 14:52):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 15 2024 at 12:39):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 15:41):

alexcrichton submitted PR review:

Thanks!

This is bit counter-intuitive when I want to write something like func.typed::<(), Result<(), ()>>(&store),

This is currently intentional in the sense that it's in theory preferred to use the output of bindgen! where you don't have to deal with this. In that sense the raw component APIs weren't designed to be the most ergonomic and easy-to-use since that's where bindgen! comes in to close the gap.

IIRC there were coherence with that trait impl, but I could be misremembering as well.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 15:41):

alexcrichton created PR review comment:

Nowadays we try to call this "WASIp2", so mind renaming that here?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 15:41):

alexcrichton created PR review comment:

Could the errors be handled here instead of using .unwrap()?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 15:41):

alexcrichton created PR review comment:

Same here as above, it's ok to replace "WASI Preview 1" with "WASIp2"

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 15:41):

alexcrichton created PR review comment:

Another s/WASI Preview 2/WASIp1/

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:29):

ifsheldon submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:29):

ifsheldon created PR review comment:

done

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:29):

ifsheldon submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:29):

ifsheldon created PR review comment:

done

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:30):

ifsheldon submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:30):

ifsheldon created PR review comment:

Not really, because these are options, not results, but I added expect() instead of unwrap()

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:30):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 17:32):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 16 2024 at 21:31):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 17 2024 at 03:03):

ifsheldon commented on PR #9788:

Oops. I digged into examples/wasi/main.c and related c-api crate. It seems c-api crate also needs some renovation.........

For example, c-api exposes this function, which links wasip1 interfaces, but no other functions link wasip2 interfaces.
https://github.com/bytecodealliance/wasmtime/blob/db4bd219fae182cdebd8ea77b1afbd1bef6ea5c0/crates/c-api/src/linker.rs#L111

I think removing preview1 feature from this line and fixing whatever breaks should be enough. This introduces API breaking changes, though.

https://github.com/bytecodealliance/wasmtime/blob/db4bd219fae182cdebd8ea77b1afbd1bef6ea5c0/crates/c-api/Cargo.toml#L36

I'd rather like to skip this error first and open another tracking issue.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 17 2024 at 03:09):

ifsheldon edited a comment on PR #9788:

Oops. CI complains about file not found target/wasm32-wasip2/debug/wasi.wasm, so I guess Makefile also needs to be updated.

Furthermore, I digged into examples/wasi/main.c and related c-api crate. It seems c-api crate also needs some renovation.........

For example, c-api exposes this function, which links wasip1 interfaces, but no other functions link wasip2 interfaces.
https://github.com/bytecodealliance/wasmtime/blob/db4bd219fae182cdebd8ea77b1afbd1bef6ea5c0/crates/c-api/src/linker.rs#L111

I think removing preview1 feature from this line and fixing whatever breaks should be enough. This introduces API breaking changes, though.

https://github.com/bytecodealliance/wasmtime/blob/db4bd219fae182cdebd8ea77b1afbd1bef6ea5c0/crates/c-api/Cargo.toml#L36

I'd rather like to skip this error first and open another tracking issue.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 17 2024 at 03:14):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 17 2024 at 03:15):

ifsheldon edited a comment on PR #9788:

Oops. CI complains about file not found target/wasm32-wasip2/debug/wasi.wasm, so I guess CMakeLists also needs to be updated.

Furthermore, I digged into examples/wasi/main.c and related c-api crate. It seems c-api crate also needs some renovation.........

For example, c-api exposes this function, which links wasip1 interfaces, but no other functions link wasip2 interfaces.
https://github.com/bytecodealliance/wasmtime/blob/db4bd219fae182cdebd8ea77b1afbd1bef6ea5c0/crates/c-api/src/linker.rs#L111

I think removing preview1 feature from this line and fixing whatever breaks should be enough. This introduces API breaking changes, though.

https://github.com/bytecodealliance/wasmtime/blob/db4bd219fae182cdebd8ea77b1afbd1bef6ea5c0/crates/c-api/Cargo.toml#L36

I'd rather like to skip this error first and open another tracking issue.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 18 2024 at 02:36):

ifsheldon commented on PR #9788:

Can you take a look at the CI error Test C-API macos-latest? I think I made a right correction on CMakeList.txt but I don't know what else needs to be fixed.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 18 2024 at 18:52):

alexcrichton commented on PR #9788:

Have you tried running the example locally?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 19 2024 at 15:07):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 19 2024 at 15:11):

ifsheldon commented on PR #9788:

For the C example, inside examples, I ran mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-wasi and then cd ../.. && ./examples/build/wasmtime-wasi and it worked. The C example still runs the old wasip1 module though, as I mentioned c-api crates lacks wasip2 support now.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 19 2024 at 15:18):

ifsheldon edited a comment on PR #9788:

For the C example, inside examples, I ran mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-wasi and then cd ../.. && ./examples/build/wasmtime-wasi and it worked. The C example still runs the old wasip1 module though, as I mentioned c-api crates lacks wasip2 support now. Revamping C wasi example is blocked until #8036 etc is merged.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 19 2024 at 15:20):

ifsheldon edited a comment on PR #9788:

For the C example, inside examples, I ran mkdir build && cd build && cmake .. && cmake --build . --target wasmtime-wasi and then cd ../.. && ./examples/build/wasmtime-wasi and it worked. The C example still runs the old wasip1 module though, as I mentioned c-api crates lacks wasip2 support now. Revamping C wasi example is blocked until #8036 is resolved by #9812 etc.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 19 2024 at 20:46):

dicej submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 19 2024 at 20:46):

dicej created PR review comment:

This [async example code][code2] shows how to use the [wasmtime-wasi][`wasmtime-wasi`] crate to

Here we're talking about a Rust crate rather than a Wasm component.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 19 2024 at 22:20):

alexcrichton commented on PR #9788:

Ah I better understand what was going on now. Instead of replacing the current example which I think is still useful for wasm32-wasip1 targets, could this perhaps rename the prior wasi example to wasip1 and add this new example under wasip2? There then wouldn't be a C example of wasip2 because that's not supported yet.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 13:21):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 13:22):

ifsheldon submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 13:22):

ifsheldon created PR review comment:

yeah, that's a typo due to replacing "module" to "component"

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 13:27):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 14:06):

ifsheldon commented on PR #9788:

OK, I've brought back wasip1 examples.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 16:02):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 17:00):

ifsheldon commented on PR #9788:

This test failure is weird to me. I have cleaned all caches and run the commands in this test manually but I saw no failures.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 18:08):

ifsheldon updated PR #9788.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 20 2024 at 18:11):

ifsheldon edited a comment on PR #9788:

This test failure is weird to me. I have cleaned all caches and run the commands in this test manually on my Mac but I saw no failures.


Last updated: Dec 23 2024 at 13:07 UTC