port bench-api

This commit is contained in:
Pat Hickey
2021-01-29 13:25:06 -08:00
parent 8b285ec2e7
commit d5fdd835ab
3 changed files with 9 additions and 7 deletions

3
Cargo.lock generated
View File

@@ -3224,8 +3224,9 @@ name = "wasmtime-bench-api"
version = "0.19.0" version = "0.19.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cap-std",
"shuffling-allocator", "shuffling-allocator",
"wasi-common", "wasi-cap-std-sync",
"wasmtime", "wasmtime",
"wasmtime-wasi", "wasmtime-wasi",
"wat", "wat",

View File

@@ -19,7 +19,8 @@ anyhow = "1.0"
shuffling-allocator = { version = "1.1.1", optional = true } shuffling-allocator = { version = "1.1.1", optional = true }
wasmtime = { path = "../wasmtime", default-features = false } wasmtime = { path = "../wasmtime", default-features = false }
wasmtime-wasi = { path = "../wasi" } wasmtime-wasi = { path = "../wasi" }
wasi-common = { path = "../wasi-common" } wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync" }
cap-std = "0.12"
[dev-dependencies] [dev-dependencies]
wat = "1.0" wat = "1.0"

View File

@@ -83,7 +83,7 @@ use std::env;
use std::os::raw::{c_int, c_void}; use std::os::raw::{c_int, c_void};
use std::path::Path; use std::path::Path;
use std::slice; use std::slice;
use wasi_common::WasiCtxBuilder; use wasi_cap_std_sync::WasiCtxBuilder;
use wasmtime::{Config, Engine, Instance, Linker, Module, Store}; use wasmtime::{Config, Engine, Instance, Linker, Module, Store};
use wasmtime_wasi::Wasi; use wasmtime_wasi::Wasi;
@@ -211,16 +211,16 @@ impl BenchState {
// Create a WASI environment. // Create a WASI environment.
let mut cx = WasiCtxBuilder::new(); let mut cx = WasiCtxBuilder::new();
cx.inherit_stdio(); cx = cx.inherit_stdio();
// Allow access to the working directory so that the benchmark can read // Allow access to the working directory so that the benchmark can read
// its input workload(s). // its input workload(s).
let working_dir = wasi_common::preopen_dir(working_dir) let working_dir = unsafe { cap_std::fs::Dir::open_ambient_dir(working_dir) }
.context("failed to preopen the working directory")?; .context("failed to preopen the working directory")?;
cx.preopened_dir(working_dir, "."); cx = cx.preopened_dir(working_dir, ".")?;
// Pass this env var along so that the benchmark program can use smaller // 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. // input workload(s) if it has them and that has been requested.
if let Ok(val) = env::var("WASM_BENCH_USE_SMALL_WORKLOAD") { if let Ok(val) = env::var("WASM_BENCH_USE_SMALL_WORKLOAD") {
cx.env("WASM_BENCH_USE_SMALL_WORKLOAD", &val); cx = cx.env("WASM_BENCH_USE_SMALL_WORKLOAD", &val)?;
} }
let cx = cx.build()?; let cx = cx.build()?;