Skip to content

Commit

Permalink
Fix build of wasmtime-wasi-bench (#6999)
Browse files Browse the repository at this point in the history
Looks like this wasn't built on CI since it wasn't tested. Flag it as
testable which should build it on CI which should catch future errors
like this.
  • Loading branch information
alexcrichton committed Sep 12, 2023
1 parent aaa5dc0 commit d0d21bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion crates/bench-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ publish = false
[lib]
name = "wasmtime_bench_api"
crate-type = ["cdylib"]
test = false
doctest = false

[dependencies]
Expand Down
17 changes: 10 additions & 7 deletions crates/bench-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,30 +305,30 @@ pub extern "C" fn wasm_bench_create(
.with_context(|| format!("failed to create {}", stdout_path.display()))?;
let stdout = cap_std::fs::File::from_std(stdout);
let stdout = wasi_cap_std_sync::file::File::from_cap_std(stdout);
cx = cx.stdout(Box::new(stdout));
cx.stdout(Box::new(stdout));

let stderr = std::fs::File::create(&stderr_path)
.with_context(|| format!("failed to create {}", stderr_path.display()))?;
let stderr = cap_std::fs::File::from_std(stderr);
let stderr = wasi_cap_std_sync::file::File::from_cap_std(stderr);
cx = cx.stderr(Box::new(stderr));
cx.stderr(Box::new(stderr));

if let Some(stdin_path) = &stdin_path {
let stdin = std::fs::File::open(stdin_path)
.with_context(|| format!("failed to open {}", stdin_path.display()))?;
let stdin = cap_std::fs::File::from_std(stdin);
let stdin = wasi_cap_std_sync::file::File::from_cap_std(stdin);
cx = cx.stdin(Box::new(stdin));
cx.stdin(Box::new(stdin));
}

// Allow access to the working directory so that the benchmark can read
// its input workload(s).
cx = cx.preopened_dir(working_dir.try_clone()?, ".")?;
cx.preopened_dir(working_dir.try_clone()?, ".")?;

// Pass this env var along so that the benchmark program can use smaller
// input workload(s) if it has them and that has been requested.
if let Ok(val) = env::var("WASM_BENCH_USE_SMALL_WORKLOAD") {
cx = cx.env("WASM_BENCH_USE_SMALL_WORKLOAD", &val)?;
cx.env("WASM_BENCH_USE_SMALL_WORKLOAD", &val)?;
}

Ok(cx.build())
Expand Down Expand Up @@ -467,7 +467,7 @@ impl BenchState {

#[cfg(feature = "wasi-nn")]
if wasi_modules.wasi_nn {
wasmtime_wasi_nn::add_to_linker(&mut linker, |cx| &mut cx.wasi_nn)?;
wasmtime_wasi_nn::witx::add_to_linker(&mut linker, |cx| &mut cx.wasi_nn)?;
}

Ok(Self {
Expand Down Expand Up @@ -509,7 +509,10 @@ impl BenchState {
let host = HostState {
wasi: (self.make_wasi_cx)().context("failed to create a WASI context")?,
#[cfg(feature = "wasi-nn")]
wasi_nn: wasmtime_wasi_nn::WasiNnCtx::new()?,
wasi_nn: {
let (backends, registry) = wasmtime_wasi_nn::preload(&[])?;
wasmtime_wasi_nn::WasiNnCtx::new(backends, registry)
},
};

// NB: Start measuring instantiation time *after* we've created the WASI
Expand Down

0 comments on commit d0d21bc

Please sign in to comment.