Skip to content

Commit a809649

Browse files
Update rust guide and tutorial examples to use registries for WITs
Signed-off-by: Kate Goldenring <[email protected]>
1 parent 33c3ac7 commit a809649

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated by cargo-component.
2+
# It is not intended for manual editing.
3+
version = 1
4+
5+
[[package]]
6+
name = "docs:adder"
7+
registry = "ghcr.io/bytecodealliance"
8+
9+
[[package.version]]
10+
requirement = "^0.1.0"
11+
version = "0.1.0"
12+
digest = "sha256:d4cb950366f8756821c401ec496ad43b35ffb0df3b2e757eb6aa3c1fa30d38c2"

component-model/examples/tutorial/adder/Cargo.toml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ wit-bindgen-rt = { version = "0.37.0", features = ["bitflags"] }
99
[lib]
1010
crate-type = ["cdylib"]
1111

12-
[package.metadata.component]
13-
package = "docs:adder"
14-
15-
[package.metadata.component.dependencies]
16-
1712
[package.metadata.component.target]
18-
path = "../wit/adder"
19-
world = "adder"
13+
package = "docs:adder"
14+
version = "0.1.0"
15+
registry = "ghcr.io/bytecodealliance"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated by cargo-component.
2+
# It is not intended for manual editing.
3+
version = 1
4+
5+
[[package]]
6+
name = "docs:calculator"
7+
registry = "ghcr.io/bytecodealliance"
8+
9+
[[package.version]]
10+
requirement = "^0.1.0"
11+
version = "0.1.0"
12+
digest = "sha256:c76216435b03e235615b16c17e80fdef5ffa90f5fea4a1138cfaaa978a0fb347"

component-model/examples/tutorial/calculator/Cargo.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ wit-bindgen-rt = { version = "0.24.0", features = ["bitflags"] }
99
[lib]
1010
crate-type = ["cdylib"]
1111

12-
[package.metadata.component]
13-
package = "docs:calculator"
14-
15-
[package.metadata.component.target.dependencies]
16-
"docs:adder" = { path = "../wit/adder" } # directory containing the WIT package
17-
1812
[package.metadata.component.target]
19-
path = "../wit/calculator"
20-
world = "calculator"
21-
22-
[package.metadata.component.dependencies]
13+
package = "docs:calculator"
14+
version = "0.1.0"
15+
registry = "ghcr.io/bytecodealliance"

component-model/src/language-support/rust.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,17 @@ cargo component new add --lib && cd add
3535

3636
## 3. Adding the WIT world
3737

38-
We now need to change our generated `wit/world.wit` to match `docs:adder`:
39-
```wit
40-
{{#include ../../examples/tutorial/wit/adder/world.wit}}
41-
```
42-
43-
The `package.metadata.component` section of our `Cargo.toml` should be changed
44-
to the following:
38+
Now, that we have a template generated for our app, we can use [`cargo-component`'s registries support](https://github.com/bytecodealliance/cargo-component/blob/main/docs/design/registries.md#component-registries) to fetch the `docs:adder` package and generate bindings for our component. Modify the `package` section of our `Cargo.toml` to only contain the following target definition:
4539

4640
```toml
47-
[package.metadata.component]
41+
[package.metadata.component.target]
4842
package = "docs:adder"
43+
version = "0.1.0"
44+
registry = "ghcr.io/bytecodealliance"
4945
```
5046

47+
This tells `cargo-component` to fetch the world from `ghcr.io/bytecodealliance/docs/adder:0.1.0`.
48+
5149
## 4. Generating bindings
5250

5351
Now that we've updated our `world.wit` and `Cargo.toml`, we can re-generate
@@ -110,7 +108,7 @@ package docs:[email protected] {
110108
### Running a Component
111109

112110
To verify that our component works, lets run it from a Rust application that knows how to run a
113-
component targeting the [`adder` world](#adding-the-wit-world).
111+
component targeting the [`adder` world](#3-adding-the-wit-world).
114112

115113
The application uses [`wasmtime`](https://github.com/bytecodealliance/wasmtime) crates to generate
116114
Rust bindings, bring in WASI worlds, and execute the component.

0 commit comments

Comments
 (0)