You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: component-model/src/language-support/importing-and-reusing-components/rust.md
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,17 +31,17 @@ world calculator {
31
31
32
32
### Referencing the package to import
33
33
34
-
Because the `docs:adder` package is in a different project, we must first tell `cargo component` how to find it. To do this, add the following to the `Cargo.toml` file:
34
+
Because the `docs:adder` package is in a different project, we must first tell `cargo` how to find it. To do this, we add a
> The path for `docs:adder` is relative to the `wit`_directory_, not to the `world.wit` file.
43
-
>
44
-
> A WIT package may be spread across multiple files in the same directory; `cargo component` will search them all.
42
+
After adding this configuration file, when we run `wkg wit fetch`, `wkg` will assume that the package `docs:adder` can be found
43
+
at the path that is given, and will pull it's contents into the local project under `wit/deps`.
44
+
45
45
46
46
### Calling the import from Rust
47
47
@@ -69,11 +69,16 @@ impl Guest for Component {
69
69
70
70
### Fulfilling the import
71
71
72
-
When you build this using `cargo component build`, the `add` interface remains imported. The calculator has taken a dependency on the `add`_interface_, but has not linked the `adder` implementation of that interface - this is not like referencing the `adder` crate. (Indeed, `calculator` could import the `add` interface even if there was no Rust project implementing the WIT file.) You can see this by running [`wasm-tools component wit`](https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wit-component) to view the calculator's world:
72
+
When you build this using `cargo build`, the `add` interface remains unsatisfied (i.e. imported).
73
+
74
+
The calculator has taken a dependency on the `add`_interface_, but has not linked the `adder` implementation of
75
+
that interface - this is not like referencing the `adder` crate (Indeed, `calculator` could import the `add` interface even if there was no Rust project implementing the WIT file) .
76
+
77
+
You can see this by running [`wasm-tools component wit`](https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wit-component) to view the calculator's world:
73
78
74
79
```
75
80
# Do a release build to prune unused imports (e.g. WASI)
As the import is unfulfilled, the `calculator.wasm` component could not run by itself in its current form. To fulfill the `add` import, so that
89
-
only `calculate` is exported, you would need to [compose the `calculator.wasm` with some `adder.wasm` into a single, self-contained component](../../composing-and-distributing/composing.md).
93
+
As the import is unfulfilled, the `calculator.wasm` component could not run by itself in its current form.
90
94
95
+
To fulfill the `add` import, so that only `calculate` is exported, you would
96
+
need to [compose the `calculator.wasm` with some `adder.wasm` into a single, self-contained component](../../composing-and-distributing/composing.md).
0 commit comments