Skip to content

Complete the tutorial please #324

@justjoheinz

Description

@justjoheinz

https://component-model.bytecodealliance.org/composing-and-distributing/distributing.html

the last sentence on the page reads:

Now, you can use the language toolchain of your choice to generate bindings and create your component.

That leaves an otherwise very useful tutorial quite incomplete, at least I was happy to find a tutorial which covered the (at least for me) newer tools cargo component and wkg. I finally managed to access wit definitions for wasi:cli and from my own packages using wkg wit fetch. They now live in the wit directory of my project:

wit
├── deps
│   ├── wasi-cli-0.2.8
│   │   └── package.wit
│   ├── wasi-clocks-0.2.8
│   │   └── package.wit
│   ├── wasi-filesystem-0.2.8
│   │   └── package.wit
│   ├── wasi-io-0.2.8
│   │   └── package.wit
│   ├── wasi-random-0.2.8
│   │   └── package.wit
│   ├── wasi-sockets-0.2.8
│   │   └── package.wit
│   └── wasm-common-fibonacci-0.1.0
│       └── package.wit
└── world.wit

Now I somehow need to tell Cargo.toml how to deal with this. So far the only solution I managed to get working is to have a Cargo.toml which looks like:

[package]
name = "fib-cli"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]

[package.metadata.component]
package = "component:fib-cli"

[package.metadata.component.dependencies]

[package.metadata.component.target.dependencies]
"wasm-common:fibonacci" = { path = "wit/deps/wasm-common-fibonacci-0.1.0" }
"wasi:cli" = { path = "wit/deps/wasi-cli-0.2.8" }
"wasi:io" = { path = "wit/deps/wasi-io-0.2.8" }
"wasi:clocks" = { path = "wit/deps/wasi-clocks-0.2.8" }
"wasi:filesystem" = { path = "wit/deps/wasi-filesystem-0.2.8" }
"wasi:sockets" = { path = "wit/deps/wasi-sockets-0.2.8" }
"wasi:random" = { path = "wit/deps/wasi-random-0.2.8" }

this somehow does not look right - why do I have to repeat all the information? I understand that the tooling is evolving, however this still does not seem right. Having an authorative source for the build process on page mentioned above would be excellent. Given that the rust tooling is certainly among the most popular in the WASM world, it would also benefit a lot of people.

I also wonder - the wkg wit build steps builds a wasm file, containing a wit description. Is that of any use for my local build problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions