Skip to content
Merged
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
43 changes: 43 additions & 0 deletions .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: 'Install Rust toolchain'
description: 'Install a rust toolchain'

inputs:
toolchain:
description: 'Default toolchan to install'
required: false
default: 'stable'

runs:
using: composite
steps:
- name: Install Rust
shell: bash
id: select
run: |
# Determine MSRV as N in `1.N.0` by looking at the `rust-version`
# located in the root `Cargo.toml`.
msrv=$(grep 'rust-version.*1' Cargo.toml | sed 's/.*\.\([0-9]*\)\..*/\1/')

if [ "${{ inputs.toolchain }}" = "msrv" ]; then
echo "version=1.$msrv.0" >> "$GITHUB_OUTPUT"
else
echo "version=${{ inputs.toolchain }}" >> "$GITHUB_OUTPUT"
fi

- name: Install Rust
shell: bash
run: |
rustup set profile minimal
rustup update "${{ steps.select.outputs.version }}" --no-self-update
rustup default "${{ steps.select.outputs.version }}"

# Save disk space by avoiding incremental compilation. Also turn down
# debuginfo from 2 to 0 to help save disk space.
cat >> "$GITHUB_ENV" <<EOF
CARGO_INCREMENTAL=0
CARGO_PROFILE_DEV_DEBUG=0
CARGO_PROFILE_TEST_DEBUG=0
EOF

# Deny warnings on CI to keep our code warning-free as it lands in-tree.
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"
91 changes: 56 additions & 35 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
name: CI
on: [push, pull_request]

# Cancel any in-flight jobs for the same PR/branch so there's only one active
# at a time
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Test
test_wasip2:
name: Test WASIp2 on ${{ matrix.rust }}
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }} && rustup component add rustfmt
- run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
- run: cargo build --workspace
- run: cargo build --workspace --no-default-features
- run: cargo build --workspace --target wasm32-wasip1
- run: cargo build --workspace --target wasm32-wasip1 --no-default-features
- run: cargo test --workspace --doc
- uses: actions/checkout@v5
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ matrix.rust }}
- run: rustup target add wasm32-wasip2 wasm32-unknown-unknown
- name: Install Wasmtime
uses: bytecodealliance/actions/wasmtime/setup@v1
with:
Expand All @@ -26,52 +28,71 @@ jobs:
uses: bytecodealliance/actions/wasm-tools/setup@v1
with:
version: "1.224.0"
- run: curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v30.0.2/wasi_snapshot_preview1.command.wasm

- run: cargo build --examples --target wasm32-wasip1 --no-default-features
- run: cargo build -p wasip2 --examples --target wasm32-wasip2 --no-default-features
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/hello-world-no_std.wasm
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/cli_command_no_std.wasm

- run: wasm-tools component new ./target/wasm32-wasip1/debug/examples/hello-world-no_std.wasm --adapt ./wasi_snapshot_preview1.command.wasm -o component.wasm
- run: wasmtime run component.wasm
- run: cargo build -p wasip2 --examples --target wasm32-wasip2
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/hello-world.wasm
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/cli_command.wasm

- run: cargo build --examples --target wasm32-unknown-unknown --no-default-features

- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/cli_command_no_std.wasm -o component.wasm
- run: wasmtime run component.wasm

- run: cargo build -p wasip2 --examples --target wasm32-unknown-unknown --no-default-features
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy_no_std.wasm -o component.wasm
- run: wasm-tools component targets wit component.wasm -w wasi:http/proxy

- run: cargo build --examples --target wasm32-wasip1

- run: wasm-tools component new ./target/wasm32-wasip1/debug/examples/hello-world.wasm --adapt ./wasi_snapshot_preview1.command.wasm -o component.wasm
- run: wasmtime run component.wasm
- run: cargo build -p wasip2 --examples --target wasm32-unknown-unknown
- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy.wasm -o component.wasm
- run: wasm-tools component targets wit component.wasm -w wasi:http/proxy

- run: cargo build --examples --target wasm32-unknown-unknown
- run: cargo build -p wasi-ext --examples --target wasm32-wasip2 --features rand
- run: wasmtime run ./target/wasm32-wasip2/debug/examples/rand.wasm

- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/cli_command.wasm -o component.wasm
- run: wasmtime run component.wasm
build:
name: Build ${{ matrix.crate }} on ${{ matrix.rust }}
runs-on: ubuntu-latest
strategy:
matrix:
rust: [msrv, stable, beta, nightly]
crate: [wasi, wasip1, wasip2]
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ matrix.rust }}
- run: rustup target add wasm32-wasip1 wasm32-wasip2

- run: wasm-tools component new ./target/wasm32-unknown-unknown/debug/examples/http_proxy.wasm -o component.wasm
- run: wasm-tools component targets wit component.wasm -w wasi:http/proxy
- run: cargo build -p ${{ matrix.crate }}
- run: cargo build -p ${{ matrix.crate }} --target wasm32-wasip1
- run: cargo build -p ${{ matrix.crate }} --target wasm32-wasip2

- run: cargo build --examples --workspace --target wasm32-wasip1 --features rand
- run: cargo build --no-default-features -p ${{ matrix.crate }}
- run: cargo build --no-default-features -p ${{ matrix.crate }} --target wasm32-wasip1
- run: cargo build --no-default-features -p ${{ matrix.crate }} --target wasm32-wasip2

- run: wasm-tools component new ./target/wasm32-wasip1/debug/examples/rand.wasm --adapt ./wasi_snapshot_preview1.command.wasm -o component.wasm
- run: wasmtime run component.wasm
- run: cargo test -p ${{ matrix.crate }} --doc

generate:
name: Ensure generated code up-to-date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable
- uses: actions/checkout@v5
- uses: ./.github/actions/install-rust
# Re-vendor all WIT files and ensure that they're all up-to-date by ensuring
# that there's no git changes.
- name: Re-vendor WIT
run: |
./ci/vendor-wit.sh
git diff --exit-code
- run: cargo install wit-bindgen-cli@0.45.0 --locked
- run: |
version=0.45.0

mkdir wit-bindgen
cd wit-bindgen
curl -o wit-bindgen.tar.gz -L https://github.com/bytecodealliance/wit-bindgen/releases/download/v$version/wit-bindgen-$version-x86_64-linux.tar.gz
tar xf wit-bindgen.tar.gz
echo "PATH=$PATH:`pwd`/wit-bindgen-$version-x86_64-linux" >> $GITHUB_ENV
working-directory: ${{ runner.tool_cache }}
- run: ./ci/regenerate.sh
- run: git diff --exit-code
Empty file removed .gitmodules
Empty file.
23 changes: 11 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "wasi"
version = "0.14.4+wasi-0.2.4"
authors = ["The Cranelift Project Developers"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Bytecode Alliance"? "Alex Crichton"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nowadays Cargo/crates.io basically ignore this field and it's not even generated by default, and AFAIK the recommendation is to remove it so I went ahead and cleaned it up here

description = "WASI API bindings for Rust"
categories = ["no-std", "wasm"]
keywords = ["webassembly", "wasm"]
Expand All @@ -10,32 +9,32 @@ documentation = "https://docs.rs/wasi"
license.workspace = true
edition.workspace = true
repository.workspace = true
rust-version.workspace = true

[workspace.package]
edition = "2021"
license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT"
repository = "https://github.com/bytecodealliance/wasi-rs"
rust-version = "1.82.0"

[workspace.dependencies]
rand = { version = "0.8.5", default-features = false }
wasi = { version = "0.14", path = ".", default-features = false }
wasi = { version = "0.14.4", path = ".", default-features = false }
wasip1 = { version = "1.0.0", path = "crates/wasip1", default-features = false }
wasip2 = { version = "1.0.0", path = "crates/wasip2", default-features = false }
core = { version = "1.0", package = "rustc-std-workspace-core" }
alloc = { version = "1.0", package = "rustc-std-workspace-alloc" }

[workspace]
members = ["./crates/*"]

[dependencies]
wit-bindgen = { version = "0.45.0", default-features = false }

# When built as part of libstd
core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" }
alloc = { version = "1.0", optional = true, package = "rustc-std-workspace-alloc" }
wasip2 = { workspace = true }

[features]
default = ["std", "bitflags"]
std = []
bitflags = ["wit-bindgen/bitflags"]
# Unstable feature to support being a libstd dependency
rustc-dep-of-std = ["core", "alloc", "wit-bindgen/rustc-dep-of-std"]
default = ["wasip2/default"]
std = ["wasip2/std"]
bitflags = ["wasip2/bitflags"]

[[example]]
name = "cli-command-no_std"
Expand Down
Loading