cargo-component icon indicating copy to clipboard operation
cargo-component copied to clipboard

Confusion around component dependencies and target dependencies

Open rylev opened this issue 1 year ago • 4 comments

For a second time, I've found myself in a debugging session ultimately due to me confusing component dependencies and target dependencies. I was confused why a local wit package would not fully resolve a dependency when I listed that dependency under package.metadata.component.dependencies only to realize I needed to put it under package.metadata.component.target.dependencies. It would be wonderful if the error messages were more descriptive when failing to resolve dependencies about where such configuration needs to live.

I'm happy to start making error messages more verbose, but I'd love to get your feedback on what the right level of detail is here.

rylev avatar Feb 26 '24 19:02 rylev

Thanks @rylev for opening the issue!

I'm completely open to suggestions that improve the error messages and reduces the confusion between these two lists of dependencies.

Do you have examples of current errors that you'd like improved?

peterhuene avatar Feb 28 '24 01:02 peterhuene

This produces a similar error to the one referenced in #239 but the cause is difference. While the error in that other issue stemmed from the wit incorrectly referring to a package with no version despite there being a versioned package with the same name in scope, this error message comes from package.metadata.component.target.dependencies not pointing to a dependency:

error: failed to create a target world for package `my-package` (/my-package/Cargo.toml)

Caused by:
    0: failed to merge target dependency `wasi:http`
    1: package not found
            --> /my-package/./wit/deps/http/types.wit:6:7
             |
           6 |   use wasi:clocks/[email protected].{duration};

Once I realized that I needed to list the dependency under package.metadata.component.target.dependencies and not package.metadata.component.dependencies, everything worked.

The core of this confusion was me not having a good understanding of the difference between target dependencies and component dependencies. The error message doesn't give any clear indication here for what I should be looking out for.

rylev avatar Mar 04 '24 12:03 rylev

I also ran into this and couldn't figure out what was wrong, only found the solution through this issue.

kayhhh avatar Mar 04 '24 17:03 kayhhh

Adding some examples that show the differences between package.metadata.component.target.dependencies and package.metadata.component.dependencies would be really nice. I have modified the example in the tutorial where each component is made into a separate package (https://github.com/minghuaw/wasm-component-tutorial) which shows how package.metadata.component.target.dependencies is used.

minghuaw avatar Mar 13 '24 17:03 minghuaw