Skip to content

Commit

Permalink
Merge pull request #99 from Gentle/wasmtime18
Browse files Browse the repository at this point in the history
Update all dependencies, wasmtime18, replace wasi-cap-std-sync with wasi-common
  • Loading branch information
fitzgen committed Mar 11, 2024
2 parents 1a97792 + 8fa767e commit 750c537
Show file tree
Hide file tree
Showing 15 changed files with 716 additions and 725 deletions.
1,264 changes: 624 additions & 640 deletions Cargo.lock

Large diffs are not rendered by default.

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

[dependencies]
anyhow = "1.0.38"
cap-std = "2.0.0"
env_logger = { version = "0.10", optional = true }
log = "0.4.14"
rayon = "1.5.0"
structopt = { version = "0.3.21", optional = true }
wasi-cap-std-sync = { workspace = true }
wasm-encoder = "0.30.0"
wasmparser = "0.106.0"
anyhow = "1.0.80"
cap-std = "3.0.0"
env_logger = { version = "0.11", optional = true }
log = "0.4.21"
rayon = "1.9.0"
structopt = { version = "0.3.26", optional = true }
wasm-encoder = "0.201.0"
wasmparser = "0.201.0"
wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }
wasi-common = { workspace = true }

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

[workspace.dependencies]
wasmprinter = "0.2.60"
wasmtime = "16"
wasmtime-wasi = "16"
wasi-cap-std-sync = "16"
wasmprinter = "0.201.0"
wasmtime = "18"
wasmtime-wasi = "18"
wasi-common = "18"


[dev-dependencies]
criterion = "0.5.1"
env_logger = "0.10.0"
env_logger = "0.11.3"
wasmprinter = { workspace = true }
wat = "1.0.67"
wat = "1.201.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.4.2"
regex = "1.10.3"

[features]
wizer = []
4 changes: 2 additions & 2 deletions benches/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use criterion::{criterion_group, criterion_main, Criterion};
use std::convert::TryFrom;

fn run_iter(
linker: &wasmtime::Linker<wasmtime_wasi::WasiCtx>,
linker: &wasmtime::Linker<wasi_common::WasiCtx>,
module: &wasmtime::Module,
mut store: &mut wasmtime::Store<wasmtime_wasi::WasiCtx>,
mut store: &mut wasmtime::Store<wasi_common::WasiCtx>,
) {
let instance = linker.instantiate(&mut store, module).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions benches/uap-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.117", features = ["derive"] }
regex = "1.4.2"
serde_yaml = "0.8.14"
serde = { version = "1.0.197", features = ["derive"] }
regex = "1.10.3"
serde_yaml = "0.9.32"

[features]
wizer = []
4 changes: 2 additions & 2 deletions benches/uap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use criterion::{criterion_group, criterion_main, Criterion};
use std::convert::TryFrom;

fn run_iter(
linker: &wasmtime::Linker<wasmtime_wasi::WasiCtx>,
linker: &wasmtime::Linker<wasi_common::WasiCtx>,
module: &wasmtime::Module,
mut store: &mut wasmtime::Store<wasmtime_wasi::WasiCtx>,
mut store: &mut wasmtime::Store<wasi_common::WasiCtx>,
) {
let instance = linker.instantiate(&mut store, module).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ edition = "2018"
cargo-fuzz = true

[dependencies]
env_logger = "0.8.3"
env_logger = "0.11.3"
libfuzzer-sys = "0.4"
log = "0.4.14"
wasm-smith = "0.4.0"
log = "0.4.21"
wasm-smith = "0.201.0"
wasmprinter = { workspace = true }
wasmtime = { workspace = true }

Expand Down
86 changes: 41 additions & 45 deletions fuzz/fuzz_targets/same_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,53 @@

#![no_main]

use libfuzzer_sys::{arbitrary, fuzz_target};
use libfuzzer_sys::{
arbitrary::{Arbitrary, Unstructured},
fuzz_target,
};
use wasm_smith::MemoryOffsetChoices;
use wasmtime::*;

const FUEL: u32 = 1_000;

fuzz_target!(|module: wasm_smith::ConfiguredModule<WasmConfig>| {
fuzz_target!(|data: &[u8]| {
let _ = env_logger::try_init();

let mut module = module;
module.ensure_termination(FUEL);
let mut u = Unstructured::new(data);

let mut config = wasm_smith::Config::arbitrary(&mut u).unwrap();
config.max_memories = 10;

// We want small memories that are quick to compare, but we also want to
// allow memories to grow so we can shake out any memory-growth-related
// bugs, so we choose `2` instead of `1`.
config.max_memory32_pages = 2;
config.max_memory64_pages = 2;

// Always generate at least one function that we can hopefully use as an
// initialization function.
config.min_funcs = 1;

config.max_funcs = 10;

// Always at least one export, hopefully a function we can use as an
// initialization routine.
config.min_exports = 1;

config.max_exports = 10;

// Always use an offset immediate that is within the memory's minimum
// size. This should make trapping on loads/stores a little less
// frequent.
config.memory_offset_choices = MemoryOffsetChoices(1, 0, 0);

config.reference_types_enabled = false;
config.bulk_memory_enabled = false;

let Ok(mut module) = wasm_smith::Module::new(config, &mut u) else {
return;
};
module.ensure_termination(FUEL).unwrap();
let wasm = module.to_bytes();

if log::log_enabled!(log::Level::Debug) {
Expand Down Expand Up @@ -185,44 +222,3 @@ fn assert_val_eq(a: &Val, b: &Val) {
_ => panic!("{:?} != {:?}", a, b),
}
}

#[derive(Clone, Default, Debug)]
struct WasmConfig;

impl<'a> arbitrary::Arbitrary<'a> for WasmConfig {
fn arbitrary(_: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(WasmConfig)
}
}

impl wasm_smith::Config for WasmConfig {
fn max_memories(&self) -> usize {
10
}

fn max_memory_pages(&self) -> u32 {
// We want small memories that are quick to compare, but we also want to
// allow memories to grow so we can shake out any memory-growth-related
// bugs, so we choose `2` instead of `1`.
2
}

fn min_funcs(&self) -> usize {
// Always generate at least one function that we can hopefully use as an
// initialization function.
1
}

fn min_exports(&self) -> usize {
// Always at least one export, hopefully a function we can use as an
// initialization routine.
1
}

fn memory_offset_choices(&self) -> (u32, u32, u32) {
// Always use an offset immediate that is within the memory's minimum
// size. This should make trapping on loads/stores a little less
// frequent.
(1, 0, 0)
}
}
2 changes: 1 addition & 1 deletion src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Module {
}

/// Push a new type into this module's types space.
pub fn push_type<'a>(self, cx: &mut ModuleContext<'a>, ty: wasmparser::Type) {
pub fn push_type<'a>(self, cx: &mut ModuleContext<'a>, ty: wasmparser::CompositeType) {
let types_space = match &cx.arena[self.id] {
ModuleInfo::Defined(d) => &d.types,
};
Expand Down
11 changes: 8 additions & 3 deletions src/info/types_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ impl TypesInterner {
///
/// If the type has already been inserted and assigned an id before, then
/// that entry and its id are reused.
pub fn insert_wasmparser(&mut self, ty: wasmparser::Type, _types_space: &[TypeId]) -> TypeId {
pub fn insert_wasmparser(
&mut self,
ty: wasmparser::CompositeType,
_types_space: &[TypeId],
) -> TypeId {
match ty {
wasmparser::Type::Func(func_ty) => self.insert(Type::Func(func_ty)),
wasmparser::Type::Array(_) => todo!(),
wasmparser::CompositeType::Func(func_ty) => self.insert(Type::Func(func_ty)),
wasmparser::CompositeType::Array(_) => todo!(),
wasmparser::CompositeType::Struct(_) => todo!(),
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use std::path::PathBuf;
use std::rc::Rc;
#[cfg(feature = "structopt")]
use structopt::StructOpt;
use wasi_common::WasiCtx;
use wasmtime::{Engine, Extern};
use wasmtime_wasi::WasiCtx;
use wasmtime_wasi::WasiCtxBuilder;

const DEFAULT_INHERIT_STDIO: bool = true;
const DEFAULT_INHERIT_ENV: bool = false;
Expand Down Expand Up @@ -636,6 +637,8 @@ impl Wizer {
saturating_float_to_int: true,
sign_extension: true,
floats: true,
component_model_values: false,
component_model_nested_names: false,

// Proposals that we support.
multi_memory: self.wasm_multi_memory.unwrap_or(DEFAULT_WASM_MULTI_MEMORY),
Expand Down Expand Up @@ -764,7 +767,7 @@ impl Wizer {
return Ok(None);
}

let mut ctx = wasi_cap_std_sync::WasiCtxBuilder::new();
let mut ctx = WasiCtxBuilder::new();
if self.inherit_stdio.unwrap_or(DEFAULT_INHERIT_STDIO) {
ctx.inherit_stdio();
}
Expand Down
13 changes: 8 additions & 5 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ fn type_section<'a>(

// Parse out types, as we will need them later when processing
// instance imports.
for ty in types {
match ty? {
ty @ wasmparser::Type::Func(_) => {
module.push_type(cx, ty);
for group in types {
for ty in group?.into_types() {
match ty.composite_type {
ty @ wasmparser::CompositeType::Func(_) => {
module.push_type(cx, ty);
}
wasmparser::CompositeType::Array(_) => todo!(),
wasmparser::CompositeType::Struct(_) => todo!(),
}
wasmparser::Type::Array(_) => todo!(),
}
}

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 = wasi_cap_std_sync::WasiCtxBuilder::new().build();
let wasi_ctx = wasmtime_wasi::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.4.2"
regex = "1.10.3"
2 changes: 1 addition & 1 deletion 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 = wasi_cap_std_sync::WasiCtxBuilder::new().build();
let wasi_ctx = wasmtime_wasi::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

0 comments on commit 750c537

Please sign in to comment.