Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasi adapter preview v2 try #22

Merged
merged 11 commits into from
Jun 28, 2024
25 changes: 25 additions & 0 deletions .github/actions/build-adapter-provider/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Build wasi component adapter provider'
description: 'Build the wasi-preview1-component-adapter provider using the adapter artefacts'

inputs:
run-id:
description: 'run id of the main.yml action that produced the adapter artefacts'
required: true

runs:
using: composite
steps:
- uses: actions/download-artifact@v4
with:
name: bins-wasi-preview1-component-adapter
path: crates/wasi-preview1-component-adapter/provider/artefacts
github-token: ${{ github.token }}
run-id: ${{ inputs.run-id }}

- name: Install required Rust components
shell: bash
run: rustup component add rustfmt clippy

- name: Build and checl the adapter provider
shell: bash
run: ./ci/build-wasi-preview1-component-adapter-provider.sh
18 changes: 18 additions & 0 deletions .github/actions/fetch-run-id/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Fetch run id for commit'
description: 'Fetch the main.yml run id for the current commit'

runs:
using: composite
steps:
- name: Fetch run id
shell: bash
run: |
run_id=$(
gh api -H 'Accept: application/vnd.github+json' \
/repos/${{ github.repository }}/actions/workflows/main.yml/runs\?exclude_pull_requests=true \
| jq '.workflow_runs' \
| jq "map(select(.head_commit.id != \"${{ github.sha }}\"))[0].id" \
)
echo COMMIT_RUN_ID=${run_id} >> "$GITHUB_ENV"
env:
GH_TOKEN: ${{ github.token }}
24 changes: 22 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,26 @@ jobs:
path: target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.*.wasm


# common logic to cancel the entire run if this job fails
- run: gh run cancel ${{ github.run_id }}
if: failure() && github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ github.token }}

build-preview1-component-adapter-provider:
name: Build wasi-preview1-component-adapter-provider
needs: build-preview1-component-adapter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
- uses: ./.github/actions/build-adapter-provider
with:
run-id: ${{ github.run_id }}


# common logic to cancel the entire run if this job fails
- run: gh run cancel ${{ github.run_id }}
if: failure() && github.event_name != 'pull_request'
Expand Down Expand Up @@ -913,7 +933,7 @@ jobs:

verify-publish:
needs: determine
if: github.repository == 'bytecodealliance/wasmtime' && needs.determine.outputs.run-full
if: needs.determine.outputs.run-full
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -1078,6 +1098,7 @@ jobs:
- determine
- miri
- build-preview1-component-adapter
- build-preview1-component-adapter-provider
- build-wasmtime-target-wasm32
- test-min-platform-example
- check_js
Expand Down Expand Up @@ -1115,7 +1136,6 @@ jobs:
&& needs.ci-status.result == 'success'
&& github.event_name == 'push'
&& startsWith(github.ref, 'refs/heads/release-')
&& github.repository == 'bytecodealliance/wasmtime'
steps:
- uses: actions/checkout@v4
with:
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/publish-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@ jobs:
publish:
name: Publish artifacts of build
runs-on: ubuntu-latest
if: github.repository == 'bytecodealliance/wasmtime'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/fetch-run-id
- run: |
sha=${{ github.sha }}
run_id=$(
gh api -H 'Accept: application/vnd.github+json' \
/repos/${{ github.repository }}/actions/workflows/main.yml/runs\?exclude_pull_requests=true \
| jq '.workflow_runs' \
| jq "map(select(.head_commit.id == \"$sha\"))[0].id" \
)
gh run download $run_id
gh run download ${COMMIT_RUN_ID}
ls
find bins-*
env:
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/publish-to-cratesio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:

jobs:
publish:
if: github.repository == 'bytecodealliance/wasmtime'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -20,6 +19,15 @@ jobs:
- run: rustup update stable && rustup default stable
- run: |
rustc scripts/publish.rs
./publish publish
# ./publish publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

# Manifest and publish the wasi-preview1-component-adapter-provider
- uses: ./.github/actions/fetch-run-id
- uses: ./.github/actions/build-adapter-provider
with:
run-id: ${{ env.COMMIT_RUN_ID }}
- run: cargo publish -p wasi-preview1-component-adapter-provider --allow-dirty --dry-run
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ on:

jobs:
release_process:
if: "github.repository == 'bytecodealliance/wasmtime' || !github.event.schedule"
if: "!github.event.schedule"
name: Run the release process
runs-on: ubuntu-latest
steps:
Expand Down
14 changes: 14 additions & 0 deletions ci/build-wasi-preview1-component-adapter-provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -ex

# Manifest the adapter provider into the workspace
cp crates/wasi-preview1-component-adapter/provider/Cargo.toml.in crates/wasi-preview1-component-adapter/provider/Cargo.toml
sed -i '/"crates\/wasi-preview1-component-adapter",/a\ \ "crates\/wasi-preview1-component-adapter\/provider",' Cargo.toml

# Check the adapter provider's code formatting and style
cargo fmt -p wasi-preview1-component-adapter-provider -- --check
cargo check -p wasi-preview1-component-adapter-provider
cargo clippy -p wasi-preview1-component-adapter-provider

# Check that publishing the adapter provider should work
cargo publish -p wasi-preview1-component-adapter-provider --dry-run --allow-dirty
22 changes: 13 additions & 9 deletions ci/build-wasi-preview1-component-adapter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ release="target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm"
$build_adapter
$verify $debug

build() {
input=$1
flavor=$2
$verify $input
name=wasi_snapshot_preview1.$flavor.wasm
dst=$(dirname $input)/$name
wasm-tools metadata add --name "wasi_preview1_component_adapter.$flavor.adapter" $input \
-o $dst
}

# Debug build, command
$build_adapter --no-default-features --features command
$verify $debug

# Release build, command
$build_adapter --release --no-default-features --features command
$verify $release
wasm-tools metadata add --name "wasi_preview1_component_adapter.command.adapter:${VERSION}" $release \
-o target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.command.wasm
build $release command

# Release build, default features (reactor)
$build_adapter --release
$verify $release
wasm-tools metadata add --name "wasi_preview1_component_adapter.reactor.adapter:${VERSION}" $release \
-o target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.reactor.wasm
build $release reactor

# Release build, proxy
$build_adapter --release --no-default-features --features proxy
$verify $release
wasm-tools metadata add --name "wasi_preview1_component_adapter.proxy.adapter:${VERSION}" $release \
-o target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.proxy.wasm
build $release proxy
1 change: 1 addition & 0 deletions crates/wasi-preview1-component-adapter/provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Cargo.toml
19 changes: 19 additions & 0 deletions crates/wasi-preview1-component-adapter/provider/Cargo.toml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "wasi-preview1-component-adapter-provider"
version.workspace = true
authors.workspace = true
description = "Embedded wasi-preview1-component-adapter binaries"
license = "Apache-2.0 WITH LLVM-exception"
repository = "https://github.com/bytecodealliance/wasmtime"
documentation = "https://docs.rs/wasi-preview1-component-adapter-provider/"
categories = ["wasm"]
keywords = ["webassembly", "wasm"]
edition.workspace = true

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/wasi_snapshot_preview1.reactor.wasm
/wasi_snapshot_preview1.command.wasm
/wasi_snapshot_preview1.proxy.wasm
51 changes: 51 additions & 0 deletions crates/wasi-preview1-component-adapter/provider/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! This crate contains the binaries of three WebAssembly modules:
//!
//! - [`WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER`]
//! - [`WASI_SNAPSHOT_PREVIEW1_COMMAND_ADAPTER`]
//! - [`WASI_SNAPSHOT_PREVIEW1_PROXY_ADAPTER`]
//!
//! These three modules bridge the wasip1 ABI to the wasip2 ABI of the component
//! model.
//!
//! They can be given to the [`wit_component::ComponentEncoder::adapter`]
//! method, using the [`WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME`], to translate a
//! module from the historical WASM ABI to the canonical ABI.
//!
//! [`wit_component::ComponentEncoder::adapter`]: https://docs.rs/wit-component/latest/wit_component/struct.ComponentEncoder.html#method.adapter

/// The name of the adapters in this crate, which may be provided to
/// [`wit_component::ComponentEncoder::adapter`].
///
/// [`wit_component::ComponentEncoder::adapter`]: https://docs.rs/wit-component/latest/wit_component/struct.ComponentEncoder.html#method.adapter
pub const WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME: &str = "wasi_snapshot_preview1";

/// The "reactor" adapter provides the default adaptation from preview1 to
/// preview2.
///
/// This adapter implements the [`wasi:cli/imports`] world.
///
/// [`wasi:cli/imports`]: https://github.com/WebAssembly/WASI/blob/01bb90d8b66cbc1d50349aaaab9ac5b143c9c98c/preview2/cli/imports.wit
pub const WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER: &[u8] =
include_bytes!("../artefacts/wasi_snapshot_preview1.reactor.wasm");

/// The "command" adapter extends the ["reactor" adapter] and additionally
/// exports a `run` function entrypoint.
///
/// This adapter implements the [`wasi:cli/command`] world.
///
/// ["reactor" adapter]: WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER
/// [`wasi:cli/command`]: https://github.com/WebAssembly/WASI/blob/01bb90d8b66cbc1d50349aaaab9ac5b143c9c98c/preview2/cli/command.wit
pub const WASI_SNAPSHOT_PREVIEW1_COMMAND_ADAPTER: &[u8] =
include_bytes!("../artefacts/wasi_snapshot_preview1.command.wasm");

/// The "proxy" adapter provides implements a HTTP proxy which is more
/// restricted than the ["reactor" adapter] adapter, as it lacks filesystem,
/// socket, environment, exit, and terminal support, but includes HTTP handlers
/// for incoming and outgoing requests.
///
/// This adapter implements the [`wasi:http/proxy`] world.
///
/// ["reactor" adapter]: WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER
/// [`wasi:http/proxy`]: https://github.com/WebAssembly/WASI/blob/01bb90d8b66cbc1d50349aaaab9ac5b143c9c98c/preview2/http/proxy.wit
pub const WASI_SNAPSHOT_PREVIEW1_PROXY_ADAPTER: &[u8] =
include_bytes!("../artefacts/wasi_snapshot_preview1.proxy.wasm");