I had a running project building a cargo component with cargo component build
(v0.1.0). After an upgrade to v0.5.0, I get a diffuse error:
$ cargo component build --release
Compiling <myproject> v0.1.0 (/<myproject>)
error: failed to read target file `/<myproject>/target/bindings/<myproject>/target.wasm`: No such file or directory (os error 2)
did you forget to run `cargo component build`? (https://github.com/bytecodealliance/cargo-component)
--> src/lib.rs:29:1
|
29 | cargo_component_bindings::generate!({ implementor: Decoder });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `cargo_component_bindings::generate` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `bindings`
--> src/lib.rs:30:5
|
30 | use bindings::exports::decoder::api::decode::Guest;
| ^^^^^^^^ use of undeclared crate or module `bindings`
For some reason, it is searching for a target.wasm. I do not use such a file in my project and, the contrary, was hoping that the command would generate a nice .wasm
file for me.
Thank you very much for any hint.
I'm not the most knowledgeable about cargo-component, but typically cargo component build
will generate a target/bindings/[..]/bindings.rs
file. It seems very odd that it would be looking for a .wasm
there.
cc @Peter Huene
Try running cargo component upgrade --no-install
The bindings crate version in Cargo.toml
is out of date such that they didn't agree on the bindings file
For a few versions, it generated an encoded target world (.wasm) that was fed to wit-bindgen
to generate the bindings directly from the macro expansion; it now generates the bindings ahead of time like it used to
Either I misunderstood or it does not work: the command you propose does not provide any feedback and does not change the situation.
$ cargo component upgrade --no-install
$
Additionally, I uninstalled cargo-component
and installed it anew. The result is the same. Am I supposed to change anything in my project?
@Peter Huene Does that behavior reflect what you expected?
The way how I discovered the problem was that I created a Github Action to build my project. It installs cargo component
and currently takes the latest version available. However, the build pipeline shows the same error as the local build (after having update cargo component
locally).
Are you running the command in the workspace? At a minimum we should improve the feedback to report that it didn't find a workspace to upgrade
Is it supposed to automatically update your cargo-component-bindings
dependency in any Cargo.toml
found in your workspace to a compatible version to the CLI
If it's not working for you, ensure the dependency is also at 0.5.0
Absolutely ... it was not (0.5.0): I still had cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
and that caused the confusion - sorry for that. Thank you very much!
Can you perhaps give me a last hint: previously I had a structure like
cargo_component_bindings::generate!({ implementor: Decoder });
use bindings::Guest;
// [..]
struct Decoder;
impl Guest for Decoder {
// [..]
}
This does not build anymore. I have to remove the {implementor: Decoder}
and rename Decoder --> Component in order for it to build, as you describe it here. Is there still a way to give Component
a different name?
Yes, the macro arguments changed to settings of the same name under the package.metadata.component.bindings
table in Cargo.toml
Sorry for the less-than-smooth upgrade process
Nevermind, I am back in the game, using the most recent dependencies!
Christoph Brewing has marked this topic as resolved.
Last updated: Dec 23 2024 at 12:05 UTC