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

Update dependencies, wasmtime-19, remove wasmtime-wasi #101

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
929 changes: 316 additions & 613 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ name = "uap"
harness = false

[dependencies]
anyhow = "1.0.80"
anyhow = "1.0.81"
cap-std = "3.0.0"
env_logger = { version = "0.11", optional = true }
log = "0.4.21"
rayon = "1.9.0"
rayon = "1.10.0"
structopt = { version = "0.3.26", optional = true }
wasm-encoder = "0.201.0"
wasmparser = "0.201.0"
wasm-encoder = "0.202.0"
wasmparser = "0.202.0"
wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }
wasi-common = { workspace = true }

# Enable this dependency to get messages with WAT disassemblies when certain
Expand All @@ -46,17 +45,16 @@ workspace = true
optional = true

[workspace.dependencies]
wasmprinter = "0.201.0"
wasmtime = "18"
wasmtime-wasi = "18"
wasi-common = "18"
wasmprinter = "0.202.0"
wasmtime = "19"
wasi-common = "19"


[dev-dependencies]
criterion = "0.5.1"
env_logger = "0.11.3"
wasmprinter = { workspace = true }
wat = "1.201.0"
wat = "1.202.0"

[workspace]
members = [
Expand Down
2 changes: 1 addition & 1 deletion benches/regex-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
regex = "1.10.3"
regex = "1.10.4"

[features]
wizer = []
8 changes: 4 additions & 4 deletions benches/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ fn bench_regex(c: &mut Criterion) {
let mut group = c.benchmark_group("regex");
group.bench_function("control", |b| {
let engine = wasmtime::Engine::default();
let wasi = wasmtime_wasi::WasiCtxBuilder::new().build();
let wasi = wasi_common::sync::WasiCtxBuilder::new().build();
let mut store = wasmtime::Store::new(&engine, wasi);
let module =
wasmtime::Module::new(store.engine(), &include_bytes!("regex_bench.control.wasm"))
.unwrap();
let mut linker = wasmtime::Linker::new(&engine);
wasmtime_wasi::sync::add_to_linker(&mut linker, |s| s).unwrap();
wasi_common::sync::add_to_linker(&mut linker, |s| s).unwrap();

b.iter(|| run_iter(&linker, &module, &mut store));
});
group.bench_function("wizer", |b| {
let engine = wasmtime::Engine::default();
let wasi = wasmtime_wasi::WasiCtxBuilder::new().build();
let wasi = wasi_common::sync::WasiCtxBuilder::new().build();
let mut store = wasmtime::Store::new(&engine, wasi);
let module =
wasmtime::Module::new(store.engine(), &include_bytes!("regex_bench.control.wasm"))
.unwrap();
let mut linker = wasmtime::Linker::new(&engine);
wasmtime_wasi::sync::add_to_linker(&mut linker, |s| s).unwrap();
wasi_common::sync::add_to_linker(&mut linker, |s| s).unwrap();

b.iter(|| run_iter(&linker, &module, &mut store));
});
Expand Down
4 changes: 2 additions & 2 deletions benches/uap-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ crate-type = ["cdylib"]

[dependencies]
serde = { version = "1.0.197", features = ["derive"] }
regex = "1.10.3"
serde_yaml = "0.9.32"
regex = "1.10.4"
serde_yaml = "0.9.34"

[features]
wizer = []
8 changes: 4 additions & 4 deletions benches/uap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ fn bench_uap(c: &mut Criterion) {
let mut group = c.benchmark_group("uap");
group.bench_function("control", |b| {
let engine = wasmtime::Engine::default();
let wasi = wasmtime_wasi::WasiCtxBuilder::new().build();
let wasi = wasi_common::sync::WasiCtxBuilder::new().build();
let mut store = wasmtime::Store::new(&engine, wasi);
let module =
wasmtime::Module::new(store.engine(), &include_bytes!("uap_bench.control.wasm"))
.unwrap();
let mut linker = wasmtime::Linker::new(&engine);
wasmtime_wasi::sync::add_to_linker(&mut linker, |s| s).unwrap();
wasi_common::sync::add_to_linker(&mut linker, |s| s).unwrap();

b.iter(|| run_iter(&linker, &module, &mut store));
});
group.bench_function("wizer", |b| {
let engine = wasmtime::Engine::default();
let wasi = wasmtime_wasi::WasiCtxBuilder::new().build();
let wasi = wasi_common::sync::WasiCtxBuilder::new().build();
let mut store = wasmtime::Store::new(&engine, wasi);
let module =
wasmtime::Module::new(store.engine(), &include_bytes!("uap_bench.wizer.wasm")).unwrap();
let mut linker = wasmtime::Linker::new(&engine);
wasmtime_wasi::sync::add_to_linker(&mut linker, |s| s).unwrap();
wasi_common::sync::add_to_linker(&mut linker, |s| s).unwrap();

b.iter(|| run_iter(&linker, &module, &mut store));
});
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cargo-fuzz = true
env_logger = "0.11.3"
libfuzzer-sys = "0.4"
log = "0.4.21"
wasm-smith = "0.201.0"
wasm-smith = "0.202.0"
wasmprinter = { workspace = true }
wasmtime = { workspace = true }

Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/same_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ fuzz_target!(|data: &[u8]| {
// Instantiate the snapshot and call the main function.
let snapshot_instance = Instance::new(&mut store, &snapshot_module, &[]).unwrap();
let snapshot_main_func = snapshot_instance.get_func(&mut store, main_func).unwrap();
let main_args = wizer::dummy::dummy_values(snapshot_main_func.ty(&store).params());
let main_args =
wizer::dummy::dummy_values(snapshot_main_func.ty(&store).params()).unwrap();
let mut snapshot_result =
vec![wasmtime::Val::I32(0); snapshot_main_func.ty(&store).results().len()];
let snapshot_call_result =
Expand Down
26 changes: 19 additions & 7 deletions src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,32 @@ pub fn dummy_func(store: &mut crate::Store, ty: FuncType, name: &str) -> Func {

/// Construct a dummy value for the given value type.
#[cfg(fuzzing)]
pub fn dummy_value(val_ty: ValType) -> Val {
match val_ty {
pub fn dummy_value(val_ty: ValType) -> Result<Val> {
Ok(match val_ty {
ValType::I32 => Val::I32(0),
ValType::I64 => Val::I64(0),
ValType::F32 => Val::F32(0),
ValType::F64 => Val::F64(0),
ValType::V128 => Val::V128(0.into()),
ValType::ExternRef => Val::ExternRef(None),
ValType::FuncRef => Val::FuncRef(None),
}
ValType::Ref(ref_type) => {
if !ref_type.is_nullable() {
anyhow::bail!("cannot create a dummy value for a non-nullable reference type");
}
if ref_type.matches(&RefType::EXTERNREF) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check whether ref_type.is_nullable() and return an error here ("cannot create a dummy value for a non-nullable reference type") if so? This will require making a few of these dummy_foo functions return Result<Foo>s.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this the intended change?

Val::ExternRef(None)
} else if ref_type.matches(&RefType::FUNCREF) {
Val::FuncRef(None)
} else if ref_type.matches(&RefType::NULLFUNCREF) {
Val::FuncRef(None)
} else {
panic!("Unknown RefType {:?}", ref_type);
}
}
})
}

/// Construct a sequence of dummy values for the given types.
#[cfg(fuzzing)]
pub fn dummy_values(val_tys: impl IntoIterator<Item = ValType>) -> Vec<Val> {
val_tys.into_iter().map(dummy_value).collect()
pub fn dummy_values(val_tys: impl IntoIterator<Item = ValType>) -> Result<Vec<Val>> {
val_tys.into_iter().map(|ty| dummy_value(ty)).collect()
}
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod snapshot;
mod stack_ext;
mod translate;

use wasi_common::sync::WasiCtxBuilder;
/// Re-export wasmtime so users can align with our version. This is
/// especially useful when providing a custom Linker.
pub use wasmtime;
Expand All @@ -31,7 +32,6 @@ use std::rc::Rc;
use structopt::StructOpt;
use wasi_common::WasiCtx;
use wasmtime::{Engine, Extern};
use wasmtime_wasi::WasiCtxBuilder;

const DEFAULT_INHERIT_STDIO: bool = true;
const DEFAULT_INHERIT_ENV: bool = false;
Expand Down Expand Up @@ -776,9 +776,9 @@ impl Wizer {
}
for dir in &self.dirs {
log::debug!("Preopening directory: {}", dir.display());
let preopened = wasmtime_wasi::sync::Dir::open_ambient_dir(
let preopened = wasi_common::sync::Dir::open_ambient_dir(
dir,
wasmtime_wasi::sync::ambient_authority(),
wasi_common::sync::ambient_authority(),
)
.with_context(|| format!("failed to open directory: {}", dir.display()))?;
ctx.preopened_dir(preopened, dir)?;
Expand All @@ -789,9 +789,9 @@ impl Wizer {
guest_dir.display(),
host_dir.display()
);
let preopened = wasmtime_wasi::sync::Dir::open_ambient_dir(
let preopened = wasi_common::sync::Dir::open_ambient_dir(
host_dir,
wasmtime_wasi::sync::ambient_authority(),
wasi_common::sync::ambient_authority(),
)
.with_context(|| format!("failed to open directory: {}", host_dir.display()))?;
ctx.preopened_dir(preopened, guest_dir)?;
Expand Down Expand Up @@ -834,7 +834,7 @@ impl Wizer {
};

if self.allow_wasi {
wasmtime_wasi::add_to_linker(&mut linker, |ctx: &mut Option<WasiCtx>| {
wasi_common::sync::add_to_linker(&mut linker, |ctx: &mut Option<WasiCtx>| {
ctx.as_mut().unwrap()
})?;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/make_linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn run_wasm(args: &[wasmtime::Val], expected: i32, wasm: &[u8]) -> Result<()> {
config.wasm_multi_value(true);

let engine = wasmtime::Engine::new(&config)?;
let wasi_ctx = wasmtime_wasi::WasiCtxBuilder::new().build();
let wasi_ctx = wasi_common::sync::WasiCtxBuilder::new().build();
let mut store = wasmtime::Store::new(&engine, wasi_ctx);
let module =
wasmtime::Module::new(store.engine(), wasm).context("Wasm test case failed to compile")?;
Expand Down
2 changes: 1 addition & 1 deletion tests/regex-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
regex = "1.10.3"
regex = "1.10.4"
4 changes: 2 additions & 2 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn wizen_and_run_wasm(
config.wasm_multi_value(true);

let engine = wasmtime::Engine::new(&config)?;
let wasi_ctx = wasmtime_wasi::WasiCtxBuilder::new().build();
let wasi_ctx = wasi_common::sync::WasiCtxBuilder::new().build();
let mut store = wasmtime::Store::new(&engine, wasi_ctx);
let module =
wasmtime::Module::new(store.engine(), wasm).context("Wasm test case failed to compile")?;
Expand All @@ -61,7 +61,7 @@ fn wizen_and_run_wasm(
.define_name(&mut store, "f", thunk)?
.define(&mut store, "x", "f", thunk)?;

wasmtime_wasi::add_to_linker(&mut linker, |wasi| wasi)?;
wasi_common::sync::add_to_linker(&mut linker, |wasi| wasi)?;

let instance = linker.instantiate(&mut store, &module)?;

Expand Down
Loading