Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 `:<version>` 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 }}
Expand All @@ -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 }}
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
- 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
Expand All @@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/target
/wit/deps
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -57,24 +69,18 @@ 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
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**
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was 50/50 on removing but it feels a little out of place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when we have 3+ these references will be great to add back

- [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
Expand Down
5 changes: 5 additions & 0 deletions wit/world.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package component:sample-wasi-http-rust;

world sample-wasi-http-rust {
include wasi:http/[email protected];
}
12 changes: 12 additions & 0 deletions wkg.lock
Original file line number Diff line number Diff line change
@@ -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"