How to describe dependencies on local packages with relative path

未关闭
#120 10 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
文档
描述清晰度
需要澄清
活跃度
停滞
技术栈
rust, wasm
领域
build-system, cli

调研方向

从 crates/core/src/registry.rs 的第394-402行附近开始,并使用链接的 wasm-component-example 仓库重现报告的命令。跟踪相对依赖项是如何被解释的,并记录受支持的 Cargo.toml 形式和预期的依赖项类型,包括成功完成时应呈现的结果。

由索引模型根据 Issue 内容生成。

描述

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

image

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 on rand func that is provided by newgyu: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?

https://github.com/bytecodealliance/cargo-component/blob/3f36696db9c39785886b0766b2b81f83cbc3d29e/crates/core/src/registry.rs#L394-L402

主要语言
Rust
星标
593
派生
68
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bytecodealliance/cargo-component 的其他 Issue

查看 bytecodealliance/cargo-component 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。