From e9afaebe0cdf76c03644262f06165aa90f0713ea Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 29 May 2025 15:29:16 -0700 Subject: [PATCH 1/4] Remove WITX bindings generation code As pointed out in #105, the scripts to regenerate the bindings code no longer work. At this point, after #104, it makes more sense to remove the old WITX code and just use `wit-bindgen`. --- rust/Cargo.lock | 4 +- rust/README.md | 11 ---- rust/scripts/regenerate-bindings-from-witx.sh | 50 ------------------- 3 files changed, 2 insertions(+), 63 deletions(-) delete mode 100755 rust/scripts/regenerate-bindings-from-witx.sh diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 1ed646d..e2f9a14 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anyhow" @@ -177,7 +177,7 @@ checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "wasi-nn" -version = "25.0.2" +version = "0.7.0" dependencies = [ "wit-bindgen", ] diff --git a/rust/README.md b/rust/README.md index 00e0a31..f52f64d 100644 --- a/rust/README.md +++ b/rust/README.md @@ -45,17 +45,6 @@ functionality from WebAssembly. To build this crate from source, use: `cargo build --target wasm32-wasi`. -### Generation - -This crate contains code ([`src/generated.rs`](src/generated.rs)) generated by -[`witx-bindgen`](https://github.com/bytecodealliance/wasi/tree/main/crates/witx-bindgen). To -regenerate this code, run the following script: - -```console -$ scripts/regenerate-bindings-from-witx.sh -``` - - ### Examples The [examples] demonstrate how to use wasi-nn from a Rust program. diff --git a/rust/scripts/regenerate-bindings-from-witx.sh b/rust/scripts/regenerate-bindings-from-witx.sh deleted file mode 100755 index 93affd0..0000000 --- a/rust/scripts/regenerate-bindings-from-witx.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -set -e - -# This script regenerates the Rust bindings for the wasi-nn specification. It has several steps: -# 1. retrieve and build `witx-bindgen` -# 2. retrieve the wasi-nn specification as WITX -# 3. use the WITX file to overwrite the `src/generated.rs` file -# -# Usage: $ regenerate-bindings-from-witx.sh -# -# The following environment variables can be overriden from the command line. Note that `*_REVISION` -# variables accept a commit hash, a branch, a tag, etc. -WITX_BINDGEN_REPOSITORY=${WITX_BINDGEN_REPOSITORY:-https://github.com/bytecodealliance/wasi} -WITX_BINDGEN_REVISION=${WITX_BINDGEN_REVISION:-main} -WASI_NN_RAW_URL=${WASI_NN_RAW_URL:-https://raw.githubusercontent.com/WebAssembly/wasi-nn} -WASI_NN_REVISION=${WASI_NN_REVISION:-main} - -echo "=== Retrieve and build 'witx-bindgen' ===" -TMP_DIR=$(mktemp -d /tmp/regenerate-bindings.XXXXXX) -pushd $TMP_DIR -# This block attempts to retrieve the least amount of Git history while allowing the user to pick -# any revision. -git init -git remote add origin ${WITX_BINDGEN_REPOSITORY} -git fetch --depth 1 origin ${WITX_BINDGEN_REVISION} -git checkout FETCH_HEAD -git submodule update --init --depth 1 -cargo build --release -p witx-bindgen -popd - -echo -echo "=== Retrieve the wasi-nn specification as WITX ===" -curl ${WASI_NN_RAW_URL}/${WASI_NN_REVISION}/wasi-nn.witx --output ${TMP_DIR}/wasi-nn.witx - -echo -echo "=== Overwrite the 'src/generated.rs' file ===" -# From https://stackoverflow.com/a/246128. -SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) -GENERATED_RS=$(realpath ${SCRIPT_DIR}/../src/generated.rs) -${TMP_DIR}/target/release/witx-bindgen ${TMP_DIR}/wasi-nn.witx > ${GENERATED_RS} -# Also, here we fix up an issue in which `witx-bindgen` does not generate correct lifetimes; see -# https://github.com/bytecodealliance/wasi/issues/65. -sed -i "s/pub struct Tensor {/pub struct Tensor<'a> {/" ${GENERATED_RS} -sed -i "s/pub dimensions: TensorDimensions<'_>,/pub dimensions: TensorDimensions<'a>,/" ${GENERATED_RS} -sed -i "s/pub data: TensorData<'_>,/pub data: TensorData<'a>,/" ${GENERATED_RS} -sed -i "s/GraphBuilder<'_>/GraphBuilder<'a>/" ${GENERATED_RS} - - -# Clean up -rm -rf $TMP_DIR From 413307061149894ccbde4b50dc0af00d4bd794b8 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 29 May 2025 15:35:04 -0700 Subject: [PATCH 2/4] Use `wasm32-wasip1` instead of `wasm32-wasi` Eventually this should all just use `wasm32-wasip2` but that can come later. --- .github/workflows/main.yaml | 14 +++++++------- build.sh | 6 +++--- image2tensor/Cargo.toml | 2 +- image2tensor/README.md | 2 +- rust/Cargo.toml | 2 +- rust/README.md | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index eaabfbb..1edf8b3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -21,7 +21,7 @@ jobs: - name: Build Wasmtime + wasi-nn run: | - rustup target add wasm32-wasi + rustup target add wasm32-wasip1 rustup target add wasm32-unknown-unknown git clone https://github.com/bytecodealliance/wasmtime --branch v16.0.0 --depth 1 --recursive cd wasmtime @@ -52,13 +52,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: rustup target add wasm32-wasi + - run: rustup target add wasm32-wasip1 - name: Run tests on native architecture working-directory: rust run: cargo test - - name: Build on wasm32-wasi + - name: Build on wasm32-wasip1 working-directory: rust - run: cargo build --target=wasm32-wasi + run: cargo build --target=wasm32-wasip1 - name: Check dry-run publish to crates.io working-directory: rust run: cargo publish --dry-run @@ -68,10 +68,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: rustup target add wasm32-wasi - - name: Build for wasm32-wasi + - run: rustup target add wasm32-wasip1 + - name: Build for wasm32-wasip1 working-directory: image2tensor - run: cargo build --target=wasm32-wasi + run: cargo build --target=wasm32-wasip1 - name: Check dry-run publish to crates.io working-directory: image2tensor run: cargo publish --dry-run diff --git a/build.sh b/build.sh index 358dd60..bc968db 100755 --- a/build.sh +++ b/build.sh @@ -24,13 +24,13 @@ else echo "The first argument: $1" FIXTURE=https://github.com/intel/openvino-rs/raw/main/crates/openvino/tests/fixtures/mobilenet pushd $WASI_NN_DIR/rust/ - cargo build --release --target=wasm32-wasi + cargo build --release --target=wasm32-wasip1 mkdir -p $WASI_NN_DIR/rust/examples/classification-example/build RUST_BUILD_DIR=$(realpath $WASI_NN_DIR/rust/examples/classification-example/build/) cp -rn examples/images $RUST_BUILD_DIR pushd examples/classification-example - cargo build --release --target=wasm32-wasi - cp target/wasm32-wasi/release/wasi-nn-example.wasm $RUST_BUILD_DIR + cargo build --release --target=wasm32-wasip1 + cp target/wasm32-wasip1/release/wasi-nn-example.wasm $RUST_BUILD_DIR pushd build wget --no-clobber --directory-prefix=$RUST_BUILD_DIR $FIXTURE/mobilenet.bin wget --no-clobber --directory-prefix=$RUST_BUILD_DIR $FIXTURE/mobilenet.xml diff --git a/image2tensor/Cargo.toml b/image2tensor/Cargo.toml index 4a50294..72f9717 100644 --- a/image2tensor/Cargo.toml +++ b/image2tensor/Cargo.toml @@ -28,4 +28,4 @@ image = { version = "0.24", default-features = false, features = [ ] } [package.metadata.docs.rs] -targets = ["wasm32-wasi"] +targets = ["wasm32-wasip1"] diff --git a/image2tensor/README.md b/image2tensor/README.md index 54068f6..4816963 100644 --- a/image2tensor/README.md +++ b/image2tensor/README.md @@ -16,7 +16,7 @@ primarily for the `wasm32-wasi` target. ### Build ```console -$ cargo build --target wasm32-wasi +$ cargo build --target wasm32-wasip1 ``` ### Examples diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f9553f6..45ac318 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -15,7 +15,7 @@ publish = true exclude = ["examples", "scripts", "Cargo.lock"] [package.metadata.docs.rs] -targets = ["wasm32-wasi"] +targets = ["wasm32-wasip1"] [dependencies] wit-bindgen = "0.22" diff --git a/rust/README.md b/rust/README.md index f52f64d..3166972 100644 --- a/rust/README.md +++ b/rust/README.md @@ -32,7 +32,7 @@ functionality from WebAssembly. 3. Compile the application to WebAssembly: ```shell script - cargo build --target=wasm32-wasi + cargo build --target=wasm32-wasip1 ``` 4. Run the generated WebAssembly in a runtime supporting [wasi-nn], e.g., [Wasmtime]. @@ -42,7 +42,7 @@ functionality from WebAssembly. ### Build -To build this crate from source, use: `cargo build --target wasm32-wasi`. +To build this crate from source, use: `cargo build --target wasm32-wasip1`. ### Examples From b3f9d58ace3c8edff0158529c8be99f284c38a4a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 29 May 2025 15:38:40 -0700 Subject: [PATCH 3/4] ci: update ubuntu runner image --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1edf8b3..0184acc 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -11,7 +11,7 @@ env: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From f6cba2a20168edb62a8eb002b4b02eceb5de62b2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 29 May 2025 15:47:45 -0700 Subject: [PATCH 4/4] ci: update `install-openvino-action` --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0184acc..ba14656 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -17,7 +17,7 @@ jobs: # Install OpenVINO - name: Install OpenVINO - uses: abrown/install-openvino-action@v8 + uses: abrown/install-openvino-action@v9 - name: Build Wasmtime + wasi-nn run: |