Skip to content

Commit d60efc9

Browse files
committed
Optionally compile wasmtime-bench-api with wasi-nn and wasi-crypto
This adds the ability to add feature flags (e.g. `--features wasi-nn`) when compiling `wasmtime-bench-api` to allow benchmarking Wasmtime with WASI proposals included. Note that due to rust-lang/cargo#5364, these features are only available: - in the `crates/bench-api` directory, e.g. `pushd crates/bench-api; cargo build --features wasi-crypto` - or from the top-level project directory using `-Zpackage-features`, e.g. `OPENVINO_INSTALL_DIR=/opt/intel/openvino cargo +nightly build -p wasmtime-bench-api -Zpackage-features --features wasi-nn`
1 parent 98d3e68 commit d60efc9

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bench-api/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ anyhow = "1.0"
1919
shuffling-allocator = { version = "1.1.1", optional = true }
2020
wasmtime = { path = "../wasmtime", default-features = false }
2121
wasmtime-wasi = { path = "../wasi" }
22+
wasmtime-wasi-crypto = { path = "../wasi-crypto", optional = true }
23+
wasmtime-wasi-nn = { path = "../wasi-nn", optional = true }
2224
wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync" }
2325
cap-std = "0.13"
2426

@@ -27,3 +29,6 @@ wat = "1.0"
2729

2830
[features]
2931
default = ["shuffling-allocator"]
32+
wasi-crypto = ["wasmtime-wasi-crypto"]
33+
wasi-nn = ["wasmtime-wasi-nn"]
34+

crates/bench-api/src/lib.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,34 @@ impl BenchState {
223223
cx = cx.env("WASM_BENCH_USE_SMALL_WORKLOAD", &val)?;
224224
}
225225

226-
let cx = cx.build()?;
227-
let wasi = Wasi::new(&store, cx);
228-
wasi.add_to_linker(&mut linker)?;
226+
Wasi::new(linker.store(), cx.build()?).add_to_linker(&mut linker)?;
227+
228+
#[cfg(feature = "wasi-nn")]
229+
{
230+
use std::cell::RefCell;
231+
use std::rc::Rc;
232+
use wasmtime_wasi_nn::{WasiNn, WasiNnCtx};
233+
234+
let wasi_nn = WasiNn::new(linker.store(), Rc::new(RefCell::new(WasiNnCtx::new()?)));
235+
wasi_nn.add_to_linker(&mut linker)?;
236+
}
237+
238+
#[cfg(feature = "wasi-crypto")]
239+
{
240+
use std::cell::RefCell;
241+
use std::rc::Rc;
242+
use wasmtime_wasi_crypto::{
243+
WasiCryptoAsymmetricCommon, WasiCryptoCommon, WasiCryptoCtx, WasiCryptoSignatures,
244+
WasiCryptoSymmetric,
245+
};
246+
247+
let cx_crypto = Rc::new(RefCell::new(WasiCryptoCtx::new()));
248+
WasiCryptoCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
249+
WasiCryptoAsymmetricCommon::new(linker.store(), cx_crypto.clone())
250+
.add_to_linker(linker)?;
251+
WasiCryptoSignatures::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
252+
WasiCryptoSymmetric::new(linker.store(), cx_crypto).add_to_linker(linker)?;
253+
}
229254

230255
Ok(Self {
231256
engine,

0 commit comments

Comments
 (0)