Skip to content
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
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ gc-drc = ["gc", "wasmtime/gc-drc", "wasmtime-cli-flags/gc-drc"]
gc-null = ["gc", "wasmtime/gc-null", "wasmtime-cli-flags/gc-null"]
pulley = ["wasmtime-cli-flags/pulley"]
stack-switching = ["wasmtime/stack-switching", "wasmtime-cli-flags/stack-switching"]
rr = ["wasmtime/rr", "wasmtime-cli-flags/rr"]
rr-component = ["rr", "wasmtime/rr-component"]
rr-validate = ["rr", "wasmtime/rr-validate", "wasmtime-cli-flags/rr-validate"]

# CLI subcommands for the `wasmtime` executable. See `wasmtime $cmd --help`
# for more information on each subcommand.
Expand Down
2 changes: 2 additions & 0 deletions crates/cli-flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ threads = ["wasmtime/threads"]
memory-protection-keys = ["wasmtime/memory-protection-keys"]
pulley = ["wasmtime/pulley"]
stack-switching = ["wasmtime/stack-switching"]
rr = ["wasmtime/rr"]
rr-validate = ["wasmtime/rr-validate"]
81 changes: 81 additions & 0 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,25 @@ wasmtime_option_group! {
}
}

wasmtime_option_group! {
#[derive(PartialEq, Clone, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct RecordOptions {
/// Filesystem endpoint to store the recorded execution trace
pub path: Option<String>,
/// Include (optional) signatures to facilitate validation checks during replay
/// (see `wasmtime replay` for details).
pub validation_metadata: Option<bool>,
/// Window size of internal buffering for record events (large windows offer more opportunities
/// for coalescing events at the cost of memory usage).
pub event_window_size: Option<usize>,
}

enum Record {
...
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct WasiNnGraph {
pub format: String,
Expand Down Expand Up @@ -534,6 +553,18 @@ pub struct CommonOptions {
#[serde(skip)]
wasi_raw: Vec<opt::CommaSeparated<Wasi>>,

/// Options to enable and configure execution recording, `-R help` to see all.
///
/// Generates of a serialized trace of the Wasm module execution that captures all
/// non-determinism observable by the module. This trace can subsequently be
/// re-executed in a determinstic, embedding-agnostic manner (see the `wasmtime replay` command).
///
/// Note: Minimal configs for deterministic Wasm semantics will be
/// enforced during recording by default (NaN canonicalization, deterministic relaxed SIMD)
#[arg(short = 'R', long = "record", value_name = "KEY[=VAL[,..]]")]
#[serde(skip)]
record_raw: Vec<opt::CommaSeparated<Record>>,

// These fields are filled in by the `configure` method below via the
// options parsed from the CLI above. This is what the CLI should use.
#[arg(skip)]
Expand All @@ -560,6 +591,10 @@ pub struct CommonOptions {
#[serde(rename = "wasi", default)]
pub wasi: WasiOptions,

#[arg(skip)]
#[serde(rename = "record", default)]
pub record: RecordOptions,

/// The target triple; default is the host triple
#[arg(long, value_name = "TARGET")]
#[serde(skip)]
Expand Down Expand Up @@ -606,12 +641,14 @@ impl CommonOptions {
debug_raw: Vec::new(),
wasm_raw: Vec::new(),
wasi_raw: Vec::new(),
record_raw: Vec::new(),
configured: true,
opts: Default::default(),
codegen: Default::default(),
debug: Default::default(),
wasm: Default::default(),
wasi: Default::default(),
record: Default::default(),
target: None,
config: None,
}
Expand All @@ -629,12 +666,14 @@ impl CommonOptions {
self.debug = toml_options.debug;
self.wasm = toml_options.wasm;
self.wasi = toml_options.wasi;
self.record = toml_options.record;
}
self.opts.configure_with(&self.opts_raw);
self.codegen.configure_with(&self.codegen_raw);
self.debug.configure_with(&self.debug_raw);
self.wasm.configure_with(&self.wasm_raw);
self.wasi.configure_with(&self.wasi_raw);
self.record.configure_with(&self.record_raw);
Ok(())
}

Expand Down Expand Up @@ -979,6 +1018,35 @@ impl CommonOptions {
true => err,
}

let record = &self.record;
match_feature! {
["rr" : record.path.clone()]
path => {
use std::{io::BufWriter, sync::Arc};
use wasmtime::{RecordConfig, RecordSettings};
let default_settings = RecordSettings::default();
match_feature! {
["rr-validate": record.validation_metadata]
_v => (),
_ => err,
}
config.enable_record(RecordConfig {
writer_initializer: Arc::new(move || {
Box::new(BufWriter::new(fs::File::create(&path).unwrap()))
}),
settings: RecordSettings {
add_validation: record
.validation_metadata
.unwrap_or(default_settings.add_validation),
event_window_size: record
.event_window_size
.unwrap_or(default_settings.event_window_size),
},
})?
},
_ => err,
}

Ok(config)
}

Expand Down Expand Up @@ -1093,6 +1161,7 @@ mod tests {
[debug]
[wasm]
[wasi]
[record]
"#;
let mut common_options: CommonOptions = toml::from_str(basic_toml).unwrap();
common_options.config(None).unwrap();
Expand Down Expand Up @@ -1214,6 +1283,8 @@ impl fmt::Display for CommonOptions {
wasm,
wasi_raw,
wasi,
record_raw,
record,
configured,
target,
config,
Expand All @@ -1230,13 +1301,15 @@ impl fmt::Display for CommonOptions {
let wasi_flags;
let wasm_flags;
let debug_flags;
let record_flags;

if *configured {
codegen_flags = codegen.to_options();
debug_flags = debug.to_options();
wasi_flags = wasi.to_options();
wasm_flags = wasm.to_options();
opts_flags = opts.to_options();
record_flags = record.to_options();
} else {
codegen_flags = codegen_raw
.iter()
Expand All @@ -1247,6 +1320,11 @@ impl fmt::Display for CommonOptions {
wasi_flags = wasi_raw.iter().flat_map(|t| t.0.iter()).cloned().collect();
wasm_flags = wasm_raw.iter().flat_map(|t| t.0.iter()).cloned().collect();
opts_flags = opts_raw.iter().flat_map(|t| t.0.iter()).cloned().collect();
record_flags = record_raw
.iter()
.flat_map(|t| t.0.iter())
.cloned()
.collect();
}

for flag in codegen_flags {
Expand All @@ -1264,6 +1342,9 @@ impl fmt::Display for CommonOptions {
for flag in debug_flags {
write!(f, "-D{flag} ")?;
}
for flag in record_flags {
write!(f, "-R{flag} ")?;
}

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions crates/environ/src/component/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct ComponentArtifacts {
pub types: ComponentTypes,
/// Serialized metadata about all included core wasm modules.
pub static_modules: PrimaryMap<StaticModuleIndex, CompiledModuleInfo>,
/// A SHA-256 checksum of the source Wasm binary from which the component was compiled
pub checksum: [u8; 32],
}

/// Runtime state that a component retains to support its operation.
Expand Down
12 changes: 12 additions & 0 deletions crates/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ hashbrown = { workspace = true, features = ["default-hasher"] }
bitflags = { workspace = true }
futures = { workspace = true, features = ["alloc"], optional = true }
bytes = { workspace = true, optional = true }
embedded-io = { version = "0.6.1", features = ["alloc"], optional = true }
sha2 = { version = "0.10.2", default-features = false }

[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
workspace = true
Expand Down Expand Up @@ -402,3 +404,13 @@ component-model-async-bytes = [
"component-model-async",
"dep:bytes",
]

# Enables support for record/replay for components
rr-component = ["component-model", "rr"]
# Enable support for the common base infrastructure of record/replay
# By default, this supports core wasm `rr`. For components, enable `rr-component`
rr = ["dep:embedded-io"]

# Enables record/replay with support for additional validation signatures/checks.
rr-validate = ["rr"]

3 changes: 3 additions & 0 deletions crates/wasmtime/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use crate::Engine;
use crate::hash_map::HashMap;
use crate::hash_set::HashSet;
use crate::prelude::*;
#[cfg(feature = "component-model")]
use sha2::{Digest, Sha256};
use std::{
any::Any,
borrow::Cow,
Expand Down Expand Up @@ -208,6 +210,7 @@ pub(crate) fn build_component_artifacts<T: FinishedObject>(
ty,
types,
static_modules: compilation_artifacts.modules,
checksum: Sha256::digest(binary).into(),
};
object.serialize_info(&artifacts);

Expand Down
Loading