Skip to content

Commit 0c608b3

Browse files
vados-cosmonickate-goldenringmkatychev
authored
refactor: language guide architecture (#310)
* refactor(lang/rust): rust language guide This commit heavily refactors the rust language guide, accomplishing a few goals: - Moving from `cargo component` to native rust toolchain - Removing sections with advanced funtionality * refactor: add new sections to contain reworked rust sections * chore(lang/rust): fill out more of runnable component section * chore(lang/rust): add command component section * chore(lang/rust): add old cargo component implementations * refactor(lang/rust): WIT resources guide for rust * refactor(lang/rust): importing guide, simple build guide * fix(lang/rust): remove more references to cargo-component * fix(lang/rust): links * refactor(pl/rust): rework wasi run interface note * refactor(pl/rust): remove warning about reactor component reuse * fix(pl/rust): typos * fix(pl/rust): add missing greet interface for runnable example * refactor(pl/rust): add note about wasi:cli/run standard interop * refactor(pl/rust): discuss runnable command components first * refactor(pl/rust): remove stdout print bug note * refactor(pl/rust): remove unneeded note * refactor(pl/rust): clarify use of bindings * refactor(pl/rust): improve composition ending notes * fix(pl/rust): cargo -> wkg * refactor(lang/js): move advanced sections, rework runnable functions * refactor(lang/rust): add target to cargo build cmd * fix(lang/rust): target wasip1 -> wasip2 * fix(lang/rust): remove unneeded dead_code allow annotation * feat: add generic guides for other languages * chore: update wording on creating runnable components section * refactor(lang/rust): description of reactors vs command * fix(lang/rust): add some rationale for executable libraries * fix: add redirects for moved language-support pages * refactor: improve language around other languages Co-authored-by: Kate Goldenring <kate.goldenring@gmail.com> * refactor: other languages contribution CTA Co-authored-by: Kate Goldenring <kate.goldenring@gmail.com> * fix: remove "not impossible" wording Co-authored-by: Kate Goldenring <kate.goldenring@gmail.com> * fix: wording on the for other-languages.md Co-authored-by: Kate Goldenring <kate.goldenring@gmail.com> * fix: typos Co-authored-by: Mikhail Katychev <mkatych@gmail.com> * refactor: other-languages section for building a simple component --------- Co-authored-by: Kate Goldenring <kate.goldenring@gmail.com> Co-authored-by: Mikhail Katychev <mkatych@gmail.com>
1 parent c6cefb6 commit 0c608b3

File tree

40 files changed

+2240
-1336
lines changed

40 files changed

+2240
-1336
lines changed

.gitattributes

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
# Ensure binary files aren't considered as text
55
*.wasm binary
66

7-
# Genrated code from cargo-component
8-
component-model/examples/tutorial/*/src/bindings.rs linguist-generated
9-
107
# Generated code from JS tutorial
118
component-model/examples/tutorial/jco/package-lock.json linguist-generated
129

13-
Cargo-component.lock linguist-language=toml
14-

.github/workflows/rust.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,20 @@ jobs:
3535
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3636

3737
- name: Install Rust
38-
run: rustup update stable --no-self-update
39-
40-
- uses: taiki-e/cache-cargo-install-action@5c9abe9a3f79d831011df7c47177debbeb320405 # v2.1.2
41-
with:
42-
tool: cargo-component
38+
run: |
39+
rustup update stable --no-self-update
40+
rustup target add wasm32-wasip2
4341
4442
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
4543
with:
4644
shared-key: ${{ hashFiles('${{ matrix.projects.folder }}/Cargo.lock') }}
4745

48-
- name: Cargo bulid the package
46+
- name: Cargo build the package
4947
working-directory: ${{ matrix.projects.folder }}
5048
if: ${{ matrix.projects.type != 'component' }}
5149
run: cargo build
5250

53-
- name: Cargo component build
51+
- name: Cargo build
5452
working-directory: ${{ matrix.projects.folder }}
5553
if: ${{ matrix.projects.type == 'component' }}
56-
run: cargo component build
54+
run: cargo build

component-model/book.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ git-repository-url = "https://github.com/bytecodealliance/component-docs/tree/ma
1010
edit-url-template = "https://github.com/bytecodealliance/component-docs/tree/main/component-model/{path}"
1111
additional-css = ["theme/head.hbs"]
1212

13+
[output.html.fold]
14+
enable = true
15+
level = 1
16+
1317
[output.html.redirect]
1418
"/creating-and-consuming/composing.html" = "/composing-and-distributing/composing.html"
1519
"/creating-and-consuming/distributing.html" = "/composing-and-distributing/distributing.html"
@@ -18,6 +22,15 @@ additional-css = ["theme/head.hbs"]
1822
"/creating-and-consuming.html" = "/language-support.html"
1923
"/runtimes/wasmtime.html" = "/running-components/wasmtime.html"
2024
"/runtimes/jco.html" = "/running-components/jco.html"
25+
"/language-support/csharp.html" = "/language-support/building-a-simple-component/csharp.html"
26+
"/language-support/c.html" = "/language-support/building-a-simple-component/c.html"
27+
"/language-support/go.html" = "/language-support/building-a-simple-component/go.html"
28+
"/language-support/javascript.html" = "/language-support/building-a-simple-component/javascript.html"
29+
"/language-support/moonbit.html" = "/language-support/building-a-simple-component/moonbit.html"
30+
"/language-support/other-languages.html" = "/language-support/building-a-simple-component/other-languages.html"
31+
"/language-support/python.html" = "/language-support/building-a-simple-component/python.html"
32+
"/language-support/rust.html" = "/language-support/building-a-simple-component/rust.html"
33+
"/language-support/wat.html" = "/language-support/building-a-simple-component/wat.html"
2134

2235
[preprocessor.alerts]
2336

component-model/examples/tutorial/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ To expand the exercise to add more components, add another operator world, expan
4242

4343
## Building and running the example
4444

45-
Use [`cargo-component`](https://github.com/bytecodealliance/cargo-component) and [`wac`](https://github.com/bytecodealliance/wac) to build and compose the calculator component.
45+
Use [`wac`](https://github.com/bytecodealliance/wac) to build and compose the calculator component.
4646

4747
```sh
48-
(cd calculator && cargo component build --release)
49-
(cd adder && cargo component build --release)
50-
(cd command && cargo component build --release)
51-
wac plug calculator/target/wasm32-wasip1/release/calculator.wasm --plug adder/target/wasm32-wasip1/release/adder.wasm -o composed.wasm
52-
wac plug command/target/wasm32-wasip1/release/command.wasm --plug composed.wasm -o final.wasm
48+
(cd calculator && cargo build --target=wasm32-wasip2 --release)
49+
(cd adder && cargo build --target=wasm32-wasip2 --release)
50+
(cd command && cargo build --target=wasm32-wasip2 --release)
51+
wac plug calculator/target/wasm32-wasip2/release/calculator.wasm --plug adder/target/wasm32-wasip2/release/adder.wasm -o composed.wasm
52+
wac plug command/target/wasm32-wasip2/release/command.wasm --plug composed.wasm -o final.wasm
5353
```
5454

5555
Now, run the component with Wasmtime:
@@ -67,9 +67,9 @@ wasmtime run final.wasm 1 2 add
6767

6868
```sh
6969
mkdir -p deps/docs
70-
cp adder/target/wasm32-wasip1/release/adder.wasm deps/docs/adder-impl.wasm
71-
cp calculator/target/wasm32-wasip1/release/calculator.wasm deps/docs/calculator-impl.wasm
72-
cp command/target/wasm32-wasip1/release/command.wasm deps/docs/command-impl.wasm
70+
cp adder/target/wasm32-wasip2/release/adder.wasm deps/docs/adder-impl.wasm
71+
cp calculator/target/wasm32-wasip2/release/calculator.wasm deps/docs/calculator-impl.wasm
72+
cp command/target/wasm32-wasip2/release/command.wasm deps/docs/command-impl.wasm
7373
```
7474

7575
Now we are ready to construct a WAC file to define our composition. Ours instantiates our three components, declaring
@@ -84,12 +84,12 @@ package example:composition;
8484
let adder-instance = new docs:adder-impl { };
8585
8686
// Instantiate the calculator-impl component that implements the calculator world.
87-
// In the `new` expression, specify the source of the `add` import to be `adder-instance`'s `add` export.
87+
// In the `new` expression, specify the source of the `add` import to be `adder-instance`'s `add` export.
8888
let calculator-instance = new docs:calculator-impl { add: adder-instance.add };
8989
9090
// Instantiate a command-impl component that implements the app world.
91-
// The command component might import other interfaces, such as WASI interfaces, but we want to leave
92-
// those as imports in the final component, so supply `...` to allow those other imports to remain unresolved.
91+
// The command component might import other interfaces, such as WASI interfaces, but we want to leave
92+
// those as imports in the final component, so supply `...` to allow those other imports to remain unresolved.
9393
// The command's exports (in this case, `wasi:cli/run`) remain unaffected in the resulting instance.
9494
let command-instance = new docs:command-impl { calculate: calculator-instance.calculate,... };
9595
@@ -101,12 +101,12 @@ export command-instance["wasi:cli/run@0.2.0"];
101101
Now, perform your composition by passing the WAC file to `wac compose`.
102102

103103
```sh
104-
wac compose composition.wac -o final.wasm
104+
wac compose composition.wac -o final.wasm
105105
```
106106

107107
> Note, instead of moving all the components to a `deps/docs` directory, you can pass the paths to the components inline
108108
> ```sh
109-
> wac compose --dep docs:adder-impl=./adder/target/wasm32-wasip1/release/adder.wasm --dep docs:calculator-impl=./calculator/target/wasm32-wasip1/release/calculator.wasm --dep docs:command-impl=./command/target/wasm32-wasip1/release/command.wasm -o final.wasm composition.wac
109+
> wac compose --dep docs:adder-impl=./adder/target/wasm32-wasip2/release/adder.wasm --dep docs:calculator-impl=./calculator/target/wasm32-wasip2/release/calculator.wasm --dep docs:command-impl=./command/target/wasm32-wasip2/release/command.wasm -o final.wasm composition.wac
110110
> ```
111111
112112
Run the component with Wasmtime:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "wasm32-wasip2"

0 commit comments

Comments
 (0)