Skip to content

Commit c4645ab

Browse files
committed
Added temporary CLI support (without async)
1 parent 952627a commit c4645ab

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

crates/wasmtime/src/runtime/rr/core.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,7 @@ impl Drop for ReplayBuffer {
488488
let mut remaining_events = 0;
489489
// Cannot use count() in iterator because IO error may loop indefinitely
490490
while let Some(event) = self.next() {
491-
if let Ok(e) = event {
492-
println!("Remaining event: {:?}", e);
493-
} else {
494-
event.unwrap();
495-
};
491+
event.unwrap();
496492
remaining_events += 1;
497493
}
498494
if remaining_events > 0 {

crates/wasmtime/src/runtime/rr/replay_driver.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use crate::component::{self, Component, Val};
22
#[cfg(feature = "rr-component")]
33
use crate::rr::component_events;
44
use crate::rr::{RREvent, ReplayError, Validate, component_hooks::ReplayLoweringPhase};
5-
use crate::{AsContextMut, Engine, ReplayReader, ReplaySettings, Store};
6-
use crate::{Module, ValRaw, prelude::*};
5+
use crate::{
6+
AsContextMut, Engine, Module, ReplayReader, ReplaySettings, Store, ValRaw, prelude::*,
7+
};
78
use alloc::collections::BTreeMap;
89
use core::mem::MaybeUninit;
910
#[cfg(feature = "rr-component")]

src/commands/replay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub struct ReplayOptions {
2424
pub validate: bool,
2525

2626
/// Size of static buffer needed to deserialized variable-length types like String. This is not
27-
/// not relevant for basic functional recording/replaying, but may be required to replay traces where
28-
/// `validation-metadata` was enabled for recording
27+
/// not important for basic functional recording/replaying, but may be required to replay traces where
28+
/// `validate` was enabled for recording
2929
#[arg(short, long, default_value_t = 64)]
3030
pub deser_buffer_size: usize,
3131
}

src/commands/run.rs

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use std::path::{Path, PathBuf};
1717
use std::sync::{Arc, Mutex};
1818
use std::thread;
1919
use wasi_common::sync::{Dir, TcpListener, WasiCtxBuilder, ambient_authority};
20+
#[cfg(feature = "rr")]
21+
use wasmtime::ReplayEnvironment;
2022
use wasmtime::{Engine, Func, Module, Store, StoreLimits, Val, ValType};
2123
use wasmtime_wasi::{WasiCtxView, WasiView};
2224

@@ -100,7 +102,16 @@ impl RunCommand {
100102
self.run.common.init_logging()?;
101103

102104
let mut config = self.run.common.config(None)?;
105+
#[cfg(not(feature = "rr"))]
103106
config.async_support(true);
107+
#[cfg(feature = "rr")]
108+
if replay_opts.is_some() {
109+
// Replay does not support async yet
110+
config.async_support(false);
111+
config.rr(wasmtime::RRConfig::Replaying);
112+
} else {
113+
config.async_support(true);
114+
}
104115

105116
if self.run.common.wasm.timeout.is_some() {
106117
config.epoch_interruption(true);
@@ -116,11 +127,6 @@ impl RunCommand {
116127
None => {}
117128
}
118129

119-
#[cfg(feature = "rr")]
120-
if replay_opts.is_some() {
121-
config.replaying(true);
122-
}
123-
124130
let engine = Engine::new(&config)?;
125131

126132
// Read the wasm module binary either as `*.wat` or a raw binary.
@@ -167,7 +173,13 @@ impl RunCommand {
167173
};
168174

169175
let mut store = Store::new(&engine, host);
176+
#[cfg(not(feature = "rr"))]
170177
self.populate_with_wasi(&mut linker, &mut store, &main)?;
178+
// For replay, we don't populate WASI
179+
#[cfg(feature = "rr")]
180+
if !replay_opts.is_some() {
181+
self.populate_with_wasi(&mut linker, &mut store, &main)?;
182+
}
171183

172184
store.data_mut().limits = self.run.store_limits();
173185
store.limiter(|t| &mut t.limits);
@@ -180,6 +192,33 @@ impl RunCommand {
180192

181193
#[cfg(feature = "rr")]
182194
{
195+
// If this is a replay run, skip to replay setup and run to completion
196+
//
197+
// Note: Right now, replay doesn't inherit any store settings listed
198+
// above. This will have to change in the future. In general, replays will
199+
// need an "almost exact" superset of the run configurations, but with
200+
// certain different options (e.g. fuel consumption).
201+
if let Some(opts) = replay_opts {
202+
let settings = ReplaySettings {
203+
validate: opts.validate,
204+
deser_buffer_size: opts.deser_buffer_size,
205+
..Default::default()
206+
};
207+
208+
let mut renv = ReplayEnvironment::new(&engine, settings);
209+
match main {
210+
RunTarget::Core(m) => {
211+
renv.add_module(m);
212+
}
213+
RunTarget::Component(c) => {
214+
renv.add_component(c);
215+
}
216+
}
217+
let mut instance = renv.instantiate(BufReader::new(fs::File::open(opts.trace)?))?;
218+
return instance.run_to_completion();
219+
}
220+
221+
// Recording settings for this execution's store
183222
let record = &self.run.common.record;
184223
if let Some(path) = &record.path {
185224
let default_settings = RecordSettings::default();
@@ -197,18 +236,6 @@ impl RunCommand {
197236
store.init_recording(fs::File::create(&path)?, settings)?;
198237
}
199238
}
200-
201-
if let Some(opts) = replay_opts {
202-
let settings = ReplaySettings {
203-
validate: opts.validate,
204-
deser_buffer_size: opts.deser_buffer_size,
205-
..Default::default()
206-
};
207-
store.init_replaying(
208-
BufReader::new(fs::File::open(opts.trace).unwrap()),
209-
settings,
210-
)?;
211-
}
212239
}
213240

214241
// Always run the module asynchronously to ensure that the module can be

0 commit comments

Comments
 (0)