I just filed #236 - not sure if I'm possibly holding it wrong? If there's anything I could do to help fix this please let me know - I wouldn't mind having an issue I could fix to contribute to cargo-component
!
I've added some context to the issue; there is a bug relating to building examples and cargo-component
's bindings doesn't appear compatible with the latest wit-bindgen due to some breaking changes in runtime types; i can do a release of cargo-component
to update it.
I believe I ran into the same (or very similar issue) where cargo component new
gave me a project which depended on wit-bindgen 0.19.1 which would fail to compile since the bindings were generated by 0.18. Shouldn't the version generated for the Cargo.toml be matched with the version used by cargo-component
?
generally it doesn't have to, as changes to the runtime types/functions are less frequently than the bindings generation
if we were to fix it so that this doesn't happen again, i'd love to move in the direction of not having a user's Cargo.toml
reference wit-bindgen
at all
I wrote up some longer form thoughts but I agree that wit-bindgen
should not have to match in cargo component
as that'll create a lot of usability headaches (like this) in the future
removing the wit-bindgen
dep entirely might be kind of hard though
it would also prevent such problems where users use the wit-bindgen rust
CLI and reference a mismatched wit-bindgen
in their Cargo.toml
if we could define cabi_realloc
in a reasonable way I think we could delete the crate entirely
modulo bitflags!
I suppose
in the mean time, i'll update the wit-bindgen
dependency of cargo-component
, fix componentization to not require [package.metadata.component]
(i.e. key off of the custom section), and fix examples (and other target crate-types) not being treated as bins when they should be for the purpose of adapter selection
you know maybe this can be the wasm32-wasip2
target in Rust
it's got cabi_realloc
built-in for us
then wit-bindgen
doesn't have to do anything
ok yeah I'm gonna go change wit-bindgen
to rely on nothing from the crate but macro things and cabi_realloc
hmm; the logic for componentization should be either 1) the [package.metadata.component]
section is present, as the module might not have a component type in the case of default "bin" components that don't use bindings and expect a preview1 command adapter for fn main
or 2) the module has a component-type
CS
that sounds reasonable to me yeah
although the custom section only needs to have component-type
as a prefix
right
it seems that the default bin project does include empty bindings with an "empty" component type, so it works even without a [package.metadata.component]
section, so never mind
just the custom section presence should work
oh nice
I've implemented https://github.com/bytecodealliance/wit-bindgen/pull/868 for everything except cabi_realloc
Now that a new version of cargo-component
has been published; does that also mean that we need to publish a new version of the wasi
crate with the updated bindings?
I was just trying out the new release of cargo-component
, and am getting this error:
Error: failed to run main module `/Users/yosh/Code/wasm-http-tools/target/wasm32-wasi/debug/examples/main.wasm`
Caused by:
0: import `wasi:http/types@0.2.0` has the wrong type
1: instance export `fields` has the wrong type
2: expected resource found nothing
This looks like WIT imports, but all my imports are going through the wasi
crate. So I suspect it's probably something there?
Oh lol, now seeing https://github.com/bytecodealliance/wasi/pull/80 is up
Yeah okay, that would make sense!
Is that error perhaps a missing -S http
flag to wasmtime run
?
(by default the CLI doesn't give access to wasi-http)
oh lol, yeah that would probably do it :sweat_smile:
I definitely forgot the flag
Oh strange, if I do:
cargo component run --example main -- -S http=y
I still get the same error
I mean; now that I'm realizing we still need to bump the wasi
crate to the latest wasm-bindgen
output it makes sense to me that it fails
Curious how it's that error though
I don't know whether that command passes the -S
flag to wasmtime or the wasm binary itself, but I would guess the latter
(others might know for sure though)
In theory wasi I don't think should need an update, but I haven't checked on that in a bit
In another example, this compiled correctly for me:
cargo component run -- -S nn=y # Run our app
maybe there's something different when paired with --example
?
Alex Crichton said:
In theory wasi I don't think should need an update, but I haven't checked on that in a bit
oh I see!
haha, yeah don't worry about debugging this right now over Zulip
I'll spend a bit more time poking at it to see what is causing the failure
If I can't figure it out I'll bring back something more detailed
(appreciate the help though!)
The args passed after --
are for the guest program and not the runner. You may use CARGO_TARGET_WASM32_WASI_RUNNER
to set the runner to use or target.wasm32-wasi.runner
in .cargo/config.toml
although it appears we may not be respecting CARGO_TARGET_WASM32_WASI_RUNNER
like we should be
.cargo/config.toml
should work though
oh never mind, the cargo-config
crate handles sourcing from the environment variable for us
both should work
if you set CARGO_COMPONENT_LOG=debug
, you'll see output for the runner it ends up spawning
Last updated: Nov 25 2024 at 19:03 UTC