From e42191dccea55db35ea4e4734f2b4404a683b3c4 Mon Sep 17 00:00:00 2001 From: Bailey Hayes Date: Fri, 23 Jan 2026 14:45:54 -0500 Subject: [PATCH] fix: use wkg and wasm32-wasip2 target directly Removes soon to be archived cargo-component --- .github/workflows/publish.yml | 16 ++++++++-------- .github/workflows/test.yml | 9 ++------- .gitignore | 3 ++- Cargo.toml | 6 ------ README.md | 30 ++++++++++++++++++------------ wit/world.wit | 5 +++++ wkg.lock | 12 ++++++++++++ 7 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 wit/world.wit create mode 100644 wkg.lock diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ae071dc..04d518a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,8 +8,6 @@ on: env: IMAGE_NAME: ${{ github.repository }} - CARGO_COMPONENT_VERSION: "0.16.0" - # TODO: These can be removed once https://github.com/bytecodealliance/cargo-component/pull/372 is merged COMPONENT_NAME: sample-wasi-http-rust COMPONENT_DESCRIPTION: "A sample WASI HTTP component written in Rust" COMPONENT_SOURCE: "https://github.com/bytecodealliance/sample-wasi-http-rust" @@ -67,27 +65,29 @@ jobs: name: Install build dependencies continue-on-error: false run: | - cargo binstall cargo-component --force --version ${{ env.CARGO_COMPONENT_VERSION }} - cargo binstall wkg --force + cargo binstall wkg --force cargo binstall cargo-auditable cargo-audit cargo binstall auditable2cdx + - name: Add wasm32-wasip2 target + run: rustup target add wasm32-wasip2 + - name: Build the component - run: cargo auditable component build --release + run: cargo auditable build --release --target wasm32-wasip2 - name: Normalize COMPONENT_NAME and Append .wasm run: echo "COMPONENT_NAME_UNDERSCORED=${COMPONENT_NAME//-/_}.wasm" >> $GITHUB_ENV - name: Extract the SBOM from the component if: github.event_name != 'workflow_dispatch' - run: auditable2cdx target/wasm32-wasip1/release/${{ env.COMPONENT_NAME_UNDERSCORED }} >> ${{ env.COMPONENT_NAME }}.spdx.json + run: auditable2cdx target/wasm32-wasip2/release/${{ env.COMPONENT_NAME_UNDERSCORED }} >> ${{ env.COMPONENT_NAME }}.spdx.json - name: Publish `:` to GitHub Container Registry if: github.event_name != 'workflow_dispatch' id: publish_versioned uses: bytecodealliance/wkg-github-action@v5 with: - file: target/wasm32-wasip1/release/${{ env.COMPONENT_NAME_UNDERSCORED }} + file: target/wasm32-wasip2/release/${{ env.COMPONENT_NAME_UNDERSCORED }} oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }} version: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} description: ${{ env.COMPONENT_DESCRIPTION }} @@ -108,7 +108,7 @@ jobs: id: publish_latest uses: bytecodealliance/wkg-github-action@v5 with: - file: target/wasm32-wasip1/release/${{ env.COMPONENT_NAME_UNDERSCORED }} + file: target/wasm32-wasip2/release/${{ env.COMPONENT_NAME_UNDERSCORED }} oci-reference-without-tag: ghcr.io/${{ env.IMAGE_NAME }}/${{ env.COMPONENT_NAME }} version: latest description: ${{ env.COMPONENT_DESCRIPTION }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3459efc..d3ccf5f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,14 +12,9 @@ jobs: - uses: actions/checkout@v4 - name: Add wasm32-wasip2 target run: rustup target add wasm32-wasip2 - - name: Install cargo-binstall - uses: cargo-bins/cargo-binstall@v1.10.15 - - name: Install cargo-component - shell: bash - run: cargo binstall cargo-component - name: Run cargo check shell: bash - run: cargo component check + run: cargo check --target wasm32-wasip2 check_style: name: It follows all style conventions @@ -29,6 +24,6 @@ jobs: - name: Install wasm32-wasip2 target run: rustup target add wasm32-wasip2 - name: Run cargo clippy - run: cargo clippy -- -Dwarnings + run: cargo clippy --target wasm32-wasip2 -- -Dwarnings - name: Run cargo fmt run: cargo fmt --all -- --check diff --git a/.gitignore b/.gitignore index c41cc9e..9211caa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/target \ No newline at end of file +/target +/wit/deps \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b7f1081..0a946ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,6 @@ publish = false [lib] crate-type = ["cdylib"] -[package.metadata.component] -package = "component:sample-wasi-http-rust" -# This tells cargo-component to use a special adapter, which doesn't depend on -# `get-environment` or other things not present in the proxy world. -proxy = true - [dependencies] wit-bindgen-rt = { version = "0.41.0", features = ["bitflags"] } wstd = "0.5.4" diff --git a/README.md b/README.md index 9aae99e..4ae418d 100644 --- a/README.md +++ b/README.md @@ -32,17 +32,29 @@ would prefer to run this locally, you can run the following commands: ```bash $ curl https://wasmtime.dev/install.sh -sSf | bash # install wasm runtime -$ cargo install cargo-component # install build tooling $ cargo install wkg # install wasm OCI tooling ``` +## Fetching WIT Dependencies + +This project uses [wkg][wkg] to manage WIT dependencies. To fetch the required +WIT packages, run: + +```bash +$ wkg wit fetch +``` + +This will download the WIT dependencies specified in the project and populate +the `wit/deps` directory. The `wkg.lock` file tracks the resolved versions. + ## Local Development -The HTTP server uses the `wasi:http/proxy` world. You can run it locally in a -`wasmtime` instance by using the following [cargo-component] command: +The HTTP server uses the `wasi:http/proxy` world. You can build and run it +locally using cargo and wasmtime: -```rust -$ cargo component serve +```bash +$ cargo build --release --target wasm32-wasip2 # build the component +$ wasmtime serve -Scli -Shttp target/wasm32-wasip2/release/sample_wasi_http_rust.wasm ``` ### Note on Debugging 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,7 +69,7 @@ local [`wasmtime` instance][wasmtime] you can run the following commands: ```bash $ wkg oci pull ghcr.io/bytecodealliance/sample-wasi-http-rust/sample-wasi-http-rust:latest -$ wasmtime serve sample-wasi-http-rust.wasm +$ wasmtime serve -Scli -Shttp sample-wasi-http-rust.wasm ``` For production workloads however, you may want to use other runtimes or @@ -65,16 +77,10 @@ integrations which provide their own OCI integrations. Deployment will vary depending on you providers, though at their core they will tend to be variations on the pull + serve pattern we've shown here. -## See Also - -**Hosts** -- [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 - ## License Apache-2.0 with LLVM Exception -[cargo-component]: https://github.com/bytecodealliance/cargo-component [wasm-oci-image]: https://tag-runtime.cncf.io/wgs/wasm/deliverables/wasm-oci-artifact/ [gh-pkg]: https://github.com/bytecodealliance/sample-wasi-http-rust/pkgs/container/sample-wasi-http-rust%2Fsample-wasi-http-rust [using-arifacts]: #working-with-deployment-artifacts diff --git a/wit/world.wit b/wit/world.wit new file mode 100644 index 0000000..2bd7d01 --- /dev/null +++ b/wit/world.wit @@ -0,0 +1,5 @@ +package component:sample-wasi-http-rust; + +world sample-wasi-http-rust { + include wasi:http/proxy@0.2.2; +} diff --git a/wkg.lock b/wkg.lock new file mode 100644 index 0000000..3210499 --- /dev/null +++ b/wkg.lock @@ -0,0 +1,12 @@ +# This file is automatically generated. +# It is not intended for manual editing. +version = 1 + +[[packages]] +name = "wasi:http" +registry = "wasi.dev" + +[[packages.versions]] +requirement = "=0.2.2" +version = "0.2.2" +digest = "sha256:a1f129cdf1fde55ec2d4ae8d998c39a7e5cf7544a8bd84a831054ac0d2ac64dd"