Skip to content

Commit ec990da

Browse files
committed
Remove embedded-io dependency for no_std rr
1 parent d8ad8a6 commit ec990da

4 files changed

Lines changed: 39 additions & 36 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wasmtime/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ hashbrown = { workspace = true, features = ["default-hasher"] }
6363
bitflags = { workspace = true }
6464
futures = { workspace = true, features = ["alloc"], optional = true }
6565
bytes = { workspace = true, optional = true }
66-
embedded-io = { version = "0.6.1", features = ["alloc"], optional = true }
6766

6867
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
6968
workspace = true
@@ -428,4 +427,4 @@ debug = [
428427
compile-time-builtins = ['dep:wasm-compose', 'dep:tempfile']
429428

430429
# Enable support for the common base infrastructure of record/replay
431-
rr = ["component-model", "dep:embedded-io"]
430+
rr = ["component-model"]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use events::{
66
RRFuncArgVals, ResultEvent, Validate, common_events, component_events, core_events,
77
marker_events,
88
};
9-
pub use io::{IOError, RecordWriter, ReplayReader};
9+
pub use io::{RecordWriter, ReplayReader};
1010
use serde::{Deserialize, Serialize};
1111
use wasmtime_environ::{EntityIndex, WasmChecksum};
1212

@@ -189,7 +189,7 @@ pub enum ReplayError {
189189
FailedValidation,
190190
IncorrectEventVariant,
191191
InvalidEventPosition,
192-
FailedRead(IOError),
192+
FailedRead(anyhow::Error),
193193
EventError(Box<dyn EventError>),
194194
MissingComponent(WasmChecksum),
195195
MissingModule(WasmChecksum),

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

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,35 @@ use core::any::Any;
33
use postcard;
44
use serde::{Deserialize, Serialize};
55

6-
pub type IOError = postcard::Error;
7-
86
cfg_if::cfg_if! {
97
if #[cfg(feature = "std")] {
108
use std::io::{Write, Seek, Read};
11-
/// An [`Write`] usable for recording in RR
12-
///
13-
/// This supports `no_std`, but must be [Send] and [Sync]
9+
/// A writer for recording in RR.
1410
pub trait RecordWriter: Write + Send + Sync + Any {}
1511
impl<T: Write + Send + Sync + Any> RecordWriter for T {}
1612

17-
/// An [`Read`] usable for replaying in RR
13+
/// A reader for replaying in RR.
1814
pub trait ReplayReader: Read + Seek + Send + Sync {}
1915
impl<T: Read + Seek + Send + Sync> ReplayReader for T {}
2016

2117
} else {
22-
// `no_std` configuration
23-
use embedded_io::{Read, Seek, Write};
18+
use core::{convert::AsRef, iter::Extend};
2419

25-
/// An [`Write`] usable for recording in RR
26-
///
27-
/// This supports `no_std`, but must be [Send] and [Sync]
28-
pub trait RecordWriter: Write + Send + Sync + Any {}
29-
impl<T: Write + Send + Sync + Any> RecordWriter for T {}
20+
/// A writer for recording in RR.
21+
pub trait RecordWriter: Extend<u8> + Send + Sync + Any {}
22+
impl<T: Extend<u8> + Send + Sync + Any> RecordWriter for T {}
3023

31-
/// An [`Read`] usable for replaying in RR
24+
/// A reader for replaying in RR.
3225
///
33-
/// This supports `no_std`, but must be [Send] and [Sync]
34-
pub trait ReplayReader: Read + Seek + Send + Sync {}
35-
impl<T: Read + Seek + Send + Sync> ReplayReader for T {}
26+
/// In `no_std`, types must provide explicit read/seek capabilities
27+
/// to a underlying byte slice through these methods.
28+
pub trait ReplayReader: AsRef<[u8]> + Send + Sync {
29+
/// Advance the reader's internal cursor by `cnt` bytes
30+
fn advance(&mut self, cnt: usize);
31+
/// Seek to an absolute position `pos` in the reader
32+
fn seek(&mut self, pos: usize);
33+
}
34+
3635
}
3736
}
3837

@@ -44,12 +43,13 @@ where
4443
T: Serialize + ?Sized,
4544
W: RecordWriter,
4645
{
47-
cfg_if::cfg_if! {
48-
if #[cfg(feature = "std")] {
49-
postcard::to_io(value, writer)?;
50-
} else {
51-
postcard::to_eio(value, writer)?;
52-
}
46+
#[cfg(feature = "std")]
47+
{
48+
postcard::to_io(value, writer)?;
49+
}
50+
#[cfg(not(feature = "std"))]
51+
{
52+
postcard::to_extend(value, writer)?;
5353
}
5454
Ok(())
5555
}
@@ -58,16 +58,21 @@ where
5858
///
5959
/// Currently uses `postcard` deserializer, with optional scratch
6060
/// buffer to deserialize into
61-
pub(super) fn from_replay_reader<'a, T, R>(reader: R, scratch: &'a mut [u8]) -> Result<T, IOError>
61+
pub(super) fn from_replay_reader<'a, T, R>(reader: &'a mut R, scratch: &'a mut [u8]) -> Result<T>
6262
where
6363
T: Deserialize<'a>,
64-
R: ReplayReader + 'a,
64+
R: ReplayReader,
6565
{
66-
cfg_if::cfg_if! {
67-
if #[cfg(feature = "std")] {
68-
Ok(postcard::from_io((reader, scratch))?.0)
69-
} else {
70-
Ok(postcard::from_eio((reader, scratch))?.0)
71-
}
66+
#[cfg(feature = "std")]
67+
{
68+
Ok(postcard::from_io((reader, scratch))?.0)
69+
}
70+
#[cfg(not(feature = "std"))]
71+
{
72+
let bytes = reader.as_ref();
73+
let original_len = bytes.len();
74+
let (value, new) = postcard::take_from_bytes(bytes)?;
75+
reader.advance(new.len() - original_len);
76+
Ok(value)
7277
}
7378
}

0 commit comments

Comments
 (0)