Stream: general

Topic: ✔ `cargo component build` throws error after upgrade to v...


view this post on Zulip Christoph Brewing (Nov 22 2023 at 14:11):

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.

view this post on Zulip Lann Martin (Nov 22 2023 at 14:19):

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.

view this post on Zulip Alex Crichton (Nov 22 2023 at 16:35):

cc @Peter Huene

view this post on Zulip Peter Huene (Nov 22 2023 at 16:36):

Try running cargo component upgrade --no-install

view this post on Zulip Peter Huene (Nov 22 2023 at 16:38):

The bindings crate version in Cargo.toml is out of date such that they didn't agree on the bindings file

view this post on Zulip Peter Huene (Nov 22 2023 at 16:40):

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

view this post on Zulip Christoph Brewing (Nov 23 2023 at 07:34):

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?

view this post on Zulip Christoph Brewing (Nov 23 2023 at 20:51):

@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).

view this post on Zulip Peter Huene (Nov 23 2023 at 20:54):

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

view this post on Zulip Peter Huene (Nov 23 2023 at 20:56):

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

view this post on Zulip Peter Huene (Nov 23 2023 at 20:56):

If it's not working for you, ensure the dependency is also at 0.5.0

view this post on Zulip Christoph Brewing (Nov 24 2023 at 06:56):

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!

view this post on Zulip Christoph Brewing (Nov 24 2023 at 06:56):

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?

A Cargo subcommand for creating WebAssembly components based on the component model proposal. - GitHub - bytecodealliance/cargo-component: A Cargo subcommand for creating WebAssembly components bas...

view this post on Zulip Peter Huene (Nov 24 2023 at 08:06):

Yes, the macro arguments changed to settings of the same name under the package.metadata.component.bindings table in Cargo.toml

view this post on Zulip Peter Huene (Nov 24 2023 at 08:07):

Sorry for the less-than-smooth upgrade process

view this post on Zulip Christoph Brewing (Nov 24 2023 at 14:22):

Nevermind, I am back in the game, using the most recent dependencies!

view this post on Zulip Notification Bot (Nov 24 2023 at 14:22):

Christoph Brewing has marked this topic as resolved.


Last updated: Nov 22 2024 at 17:03 UTC