Skip to content

Commit e42191d

Browse files
committed
fix: use wkg and wasm32-wasip2 target directly
Removes soon to be archived cargo-component
1 parent 5c32dfa commit e42191d

File tree

7 files changed

+47
-34
lines changed

7 files changed

+47
-34
lines changed

.github/workflows/publish.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ on:
88

99
env:
1010
IMAGE_NAME: ${{ github.repository }}
11-
CARGO_COMPONENT_VERSION: "0.16.0"
12-
# TODO: These can be removed once https://github.com/bytecodealliance/cargo-component/pull/372 is merged
1311
COMPONENT_NAME: sample-wasi-http-rust
1412
COMPONENT_DESCRIPTION: "A sample WASI HTTP component written in Rust"
1513
COMPONENT_SOURCE: "https://github.com/bytecodealliance/sample-wasi-http-rust"
@@ -67,27 +65,29 @@ jobs:
6765
name: Install build dependencies
6866
continue-on-error: false
6967
run: |
70-
cargo binstall cargo-component --force --version ${{ env.CARGO_COMPONENT_VERSION }}
71-
cargo binstall wkg --force
68+
cargo binstall wkg --force
7269
cargo binstall cargo-auditable cargo-audit
7370
cargo binstall auditable2cdx
7471
72+
- name: Add wasm32-wasip2 target
73+
run: rustup target add wasm32-wasip2
74+
7575
- name: Build the component
76-
run: cargo auditable component build --release
76+
run: cargo auditable build --release --target wasm32-wasip2
7777

7878
- name: Normalize COMPONENT_NAME and Append .wasm
7979
run: echo "COMPONENT_NAME_UNDERSCORED=${COMPONENT_NAME//-/_}.wasm" >> $GITHUB_ENV
8080

8181
- name: Extract the SBOM from the component
8282
if: github.event_name != 'workflow_dispatch'
83-
run: auditable2cdx target/wasm32-wasip1/release/${{ env.COMPONENT_NAME_UNDERSCORED }} >> ${{ env.COMPONENT_NAME }}.spdx.json
83+
run: auditable2cdx target/wasm32-wasip2/release/${{ env.COMPONENT_NAME_UNDERSCORED }} >> ${{ env.COMPONENT_NAME }}.spdx.json
8484

8585
- name: Publish `:<version>` to GitHub Container Registry
8686
if: github.event_name != 'workflow_dispatch'
8787
id: publish_versioned
8888
uses: bytecodealliance/wkg-github-action@v5
8989
with:
90-
file: target/wasm32-wasip1/release/${{ env.COMPONENT_NAME_UNDERSCORED }}
90+
file: target/wasm32-wasip2/release/${{ env.COMPONENT_NAME_UNDERSCORED }}
9191
oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}
9292
version: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
9393
description: ${{ env.COMPONENT_DESCRIPTION }}
@@ -108,7 +108,7 @@ jobs:
108108
id: publish_latest
109109
uses: bytecodealliance/wkg-github-action@v5
110110
with:
111-
file: target/wasm32-wasip1/release/${{ env.COMPONENT_NAME_UNDERSCORED }}
111+
file: target/wasm32-wasip2/release/${{ env.COMPONENT_NAME_UNDERSCORED }}
112112
oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }}
113113
version: latest
114114
description: ${{ env.COMPONENT_DESCRIPTION }}

.github/workflows/test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- name: Add wasm32-wasip2 target
1414
run: rustup target add wasm32-wasip2
15-
- name: Install cargo-binstall
16-
uses: cargo-bins/cargo-binstall@v1.10.15
17-
- name: Install cargo-component
18-
shell: bash
19-
run: cargo binstall cargo-component
2015
- name: Run cargo check
2116
shell: bash
22-
run: cargo component check
17+
run: cargo check --target wasm32-wasip2
2318

2419
check_style:
2520
name: It follows all style conventions
@@ -29,6 +24,6 @@ jobs:
2924
- name: Install wasm32-wasip2 target
3025
run: rustup target add wasm32-wasip2
3126
- name: Run cargo clippy
32-
run: cargo clippy -- -Dwarnings
27+
run: cargo clippy --target wasm32-wasip2 -- -Dwarnings
3328
- name: Run cargo fmt
3429
run: cargo fmt --all -- --check

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/target
1+
/target
2+
/wit/deps

Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ publish = false
77
[lib]
88
crate-type = ["cdylib"]
99

10-
[package.metadata.component]
11-
package = "component:sample-wasi-http-rust"
12-
# This tells cargo-component to use a special adapter, which doesn't depend on
13-
# `get-environment` or other things not present in the proxy world.
14-
proxy = true
15-
1610
[dependencies]
1711
wit-bindgen-rt = { version = "0.41.0", features = ["bitflags"] }
1812
wstd = "0.5.4"

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,29 @@ would prefer to run this locally, you can run the following commands:
3232

3333
```bash
3434
$ curl https://wasmtime.dev/install.sh -sSf | bash # install wasm runtime
35-
$ cargo install cargo-component # install build tooling
3635
$ cargo install wkg # install wasm OCI tooling
3736
```
3837

38+
## Fetching WIT Dependencies
39+
40+
This project uses [wkg][wkg] to manage WIT dependencies. To fetch the required
41+
WIT packages, run:
42+
43+
```bash
44+
$ wkg wit fetch
45+
```
46+
47+
This will download the WIT dependencies specified in the project and populate
48+
the `wit/deps` directory. The `wkg.lock` file tracks the resolved versions.
49+
3950
## Local Development
4051

41-
The HTTP server uses the `wasi:http/proxy` world. You can run it locally in a
42-
`wasmtime` instance by using the following [cargo-component] command:
52+
The HTTP server uses the `wasi:http/proxy` world. You can build and run it
53+
locally using cargo and wasmtime:
4354

44-
```rust
45-
$ cargo component serve
55+
```bash
56+
$ cargo build --release --target wasm32-wasip2 # build the component
57+
$ wasmtime serve -Scli -Shttp target/wasm32-wasip2/release/sample_wasi_http_rust.wasm
4658
```
4759
### Note on Debugging
4860
There are launch and task configuration files if you want to use VSCode for debugging in an IDE; however, if you prefer using GDB or LLDB directly the configuration files should be enough to get you up and running. Note that the [GDB configuration requires an absolute path](https://github.com/bytecodealliance/sample-wasi-http-rust/blob/fe47fc9f6c87d09575f6683a26f9a67e3e71aa26/.vscode/launch.json#L28), so that configuration in VSCode you will need to modify for your computer.
@@ -57,24 +69,18 @@ local [`wasmtime` instance][wasmtime] you can run the following commands:
5769

5870
```bash
5971
$ wkg oci pull ghcr.io/bytecodealliance/sample-wasi-http-rust/sample-wasi-http-rust:latest
60-
$ wasmtime serve sample-wasi-http-rust.wasm
72+
$ wasmtime serve -Scli -Shttp sample-wasi-http-rust.wasm
6173
```
6274

6375
For production workloads however, you may want to use other runtimes or
6476
integrations which provide their own OCI integrations. Deployment will vary
6577
depending on you providers, though at their core they will tend to be variations
6678
on the pull + serve pattern we've shown here.
6779

68-
## See Also
69-
70-
**Hosts**
71-
- [sample-wasi-http-aks-wasmcloud](https://github.com/yoshuawuyts/sample-wasi-http-aks-wasmcloud) - A `wasi:http` example host environment running on AKS using the WasmCloud runtime
72-
7380
## License
7481

7582
Apache-2.0 with LLVM Exception
7683

77-
[cargo-component]: https://github.com/bytecodealliance/cargo-component
7884
[wasm-oci-image]: https://tag-runtime.cncf.io/wgs/wasm/deliverables/wasm-oci-artifact/
7985
[gh-pkg]: https://github.com/bytecodealliance/sample-wasi-http-rust/pkgs/container/sample-wasi-http-rust%2Fsample-wasi-http-rust
8086
[using-arifacts]: #working-with-deployment-artifacts

wit/world.wit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package component:sample-wasi-http-rust;
2+
3+
world sample-wasi-http-rust {
4+
include wasi:http/proxy@0.2.2;
5+
}

wkg.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated.
2+
# It is not intended for manual editing.
3+
version = 1
4+
5+
[[packages]]
6+
name = "wasi:http"
7+
registry = "wasi.dev"
8+
9+
[[packages.versions]]
10+
requirement = "=0.2.2"
11+
version = "0.2.2"
12+
digest = "sha256:a1f129cdf1fde55ec2d4ae8d998c39a7e5cf7544a8bd84a831054ac0d2ac64dd"

0 commit comments

Comments
 (0)