cargo-component
cargo-component copied to clipboard
How to describe dependencies on local packages with relative path
Hello developers,
I'm trying to understand Component Model with cargo-component. To that end I have tried to create a simple example, but I have the following error and would like to discuss it if you allow me to do it here.
$ cargo component build --release
error: failed to create a target world for package `comp2` (/workspaces/wasm-component-example/comp2/Cargo.toml)
Caused by:
0: failed to decode component dependency `newgyu:comp1`
1: dependency is not a WebAssembly component
cargo-component version is here.
$ cargo component --version
cargo-component-component 0.1.0 (6af088a 2023-08-16 wasi:2750b73)
My example and what I expect
https://github.com/NewGyu/wasm-component-example
There are two packages, then each package has a world.
-
newgyu:comp1/random-generator
-
rand
func is exported.
-
-
newgyu:comp2/hello
-
hello-world
func is exported, and that depends onrand
func that is provided bynewgyu:comp1
.
-
Directory structures
$ tree -L 2.
.
├── comp1
│ ├── Cargo.toml
│ ├── src
│ │ └── lib.rs
│ └── wit
│ └── world.wit
├── comp2
│ ├── Cargo.toml
│ ├── src
│ │ └── lib.rs
│ └── wit
│ └── world.wit
Code
comp2
comp2
is specifying a dependency on comp1
as local package reference.
[package]
name = "comp2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "newgyu:comp2"
[package.metadata.component.target]
path = "wit"
[package.metadata.component.dependencies]
"newgyu:comp1" = { path = "../comp1/wit/world.wit" }
comp1
comp1
could be built with cargo component build --release
. The followings have been built.
- target/bindings/comp1/target.wasm
- target/bindings/comp1/world
- target/wasm32-wasi/release/comp1.wasm
[package]
name = "comp1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "newgyu:comp1"
[package.metadata.component.target]
path = "wit"
world = "random-generator"
[package.metadata.component.dependencies]
Points I would like to ask about
- Is it correct tow to describe dependencies on local packages with relative path ?
- Is the dependency type handled as
Wit
when described as above ?- Why does
into_component_world
respond error? - Should I explicitly specify
Wasm
as the dependency type? How to specify that in Cargo.toml?
- Why does
https://github.com/bytecodealliance/cargo-component/blob/3f36696db9c39785886b0766b2b81f83cbc3d29e/crates/core/src/registry.rs#L394-L402