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.
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 exportedwasi:cli/run@0.2.0
function, which is the main function inexamples/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.
alexcrichton submitted PR review.
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
alexcrichton created PR review comment:
For this, would this example help?
ifsheldon updated PR #9788.
ifsheldon submitted PR review.
ifsheldon created PR review comment:
updated
ifsheldon submitted PR review.
ifsheldon created PR review comment:
Yes, thanks!
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 awasi: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 therun
function inwasi:cli/run
.
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.
ifsheldon updated PR #9788.
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 inexamples/wasi/main.rs
. There I want to invoke the exportedwasi:cli/run@0.2.0
function, which is the main function inexamples/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 commitsUpdated:
This PR revamps the examples
wasi
andwasi-async
with latest updates fromwasmtime
andwasmtime-wasi
and uses WASIp2 APIs by default. Related documentation is also updated.
ifsheldon has marked PR #9788 as ready for review.
ifsheldon requested dicej for a review on PR #9788.
ifsheldon requested wasmtime-core-reviewers for a review on PR #9788.
ifsheldon requested wasmtime-default-reviewers for a review on PR #9788.
ifsheldon commented on PR #9788:
OK, I think this draft PR seems good to me now, so I turned it into a formal PR.
ifsheldon updated PR #9788.
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 notA1
? This is bit counter-intuitive when I want to write something likefunc.typed::<(), Result<(), ()>>(&store)
, whichrustc
complains about not implementingComponentNamedList
. I really didn't know how to fix this error until I lookupImplementations on Foreign Types
section ofComponentNamedList
.
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 notA1
? Should I file another issue for this? This is bit counter-intuitive when I want to write something likefunc.typed::<(), Result<(), ()>>(&store)
, whichrustc
complains about not implementingComponentNamedList
. I really didn't know how to fix this error until I lookupImplementations on Foreign Types
section ofComponentNamedList
.
ifsheldon updated PR #9788.
ifsheldon updated PR #9788.
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 wherebindgen!
comes in to close the gap.IIRC there were coherence with that trait impl, but I could be misremembering as well.
alexcrichton created PR review comment:
Nowadays we try to call this "WASIp2", so mind renaming that here?
alexcrichton created PR review comment:
Could the errors be handled here instead of using
.unwrap()
?
alexcrichton created PR review comment:
Same here as above, it's ok to replace "WASI Preview 1" with "WASIp2"
alexcrichton created PR review comment:
Another
s/WASI Preview 2/WASIp1/
ifsheldon submitted PR review.
ifsheldon created PR review comment:
done
ifsheldon submitted PR review.
ifsheldon created PR review comment:
done
ifsheldon submitted PR review.
ifsheldon created PR review comment:
Not really, because these are options, not results, but I added
expect()
instead ofunwrap()
ifsheldon updated PR #9788.
ifsheldon updated PR #9788.
alexcrichton submitted PR review.
ifsheldon commented on PR #9788:
Oops. I digged into
examples/wasi/main.c
and relatedc-api
crate. It seemsc-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#L111I think removing
preview1
feature from this line and fixing whatever breaks should be enough. This introduces API breaking changes, though.I'd rather like to skip this error first and open another tracking issue.
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 relatedc-api
crate. It seemsc-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#L111I think removing
preview1
feature from this line and fixing whatever breaks should be enough. This introduces API breaking changes, though.I'd rather like to skip this error first and open another tracking issue.
ifsheldon updated PR #9788.
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 relatedc-api
crate. It seemsc-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#L111I think removing
preview1
feature from this line and fixing whatever breaks should be enough. This introduces API breaking changes, though.I'd rather like to skip this error first and open another tracking issue.
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.
alexcrichton commented on PR #9788:
Have you tried running the example locally?
ifsheldon updated PR #9788.
ifsheldon commented on PR #9788:
For the C example, inside
examples
, I ranmkdir build && cd build && cmake .. && cmake --build . --target wasmtime-wasi
and thencd ../.. && ./examples/build/wasmtime-wasi
and it worked. The C example still runs the old wasip1 module though, as I mentionedc-api
crates lacks wasip2 support now.
ifsheldon edited a comment on PR #9788:
For the C example, inside
examples
, I ranmkdir build && cd build && cmake .. && cmake --build . --target wasmtime-wasi
and thencd ../.. && ./examples/build/wasmtime-wasi
and it worked. The C example still runs the old wasip1 module though, as I mentionedc-api
crates lacks wasip2 support now. Revamping C wasi example is blocked until #8036 etc is merged.
ifsheldon edited a comment on PR #9788:
For the C example, inside
examples
, I ranmkdir build && cd build && cmake .. && cmake --build . --target wasmtime-wasi
and thencd ../.. && ./examples/build/wasmtime-wasi
and it worked. The C example still runs the old wasip1 module though, as I mentionedc-api
crates lacks wasip2 support now. Revamping C wasi example is blocked until #8036 is resolved by #9812 etc.
dicej submitted PR review.
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.
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.
ifsheldon updated PR #9788.
ifsheldon submitted PR review.
ifsheldon created PR review comment:
yeah, that's a typo due to replacing "module" to "component"
ifsheldon updated PR #9788.
ifsheldon commented on PR #9788:
OK, I've brought back wasip1 examples.
alexcrichton submitted PR review.
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.
ifsheldon updated PR #9788.
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