Skip to content

Commit dc7a322

Browse files
authored
Make serde an optional dependency in wasmtime-core (#12739) (#12752)
cg_clif does not need serde, yet it was previously pulled in by Cranelift through the dependency on wasmtime-core.
1 parent d8e213f commit dc7a322

6 files changed

Lines changed: 13 additions & 7 deletions

File tree

crates/core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ version.workspace = true
1313
anyhow = { workspace = true, optional = true }
1414
hashbrown = { workspace = true, features = ["default-hasher"] }
1515
libm = { workspace = true }
16-
serde = { workspace = true }
16+
serde = { workspace = true, optional = true }
1717

1818
[lints]
1919
workspace = true
@@ -26,3 +26,4 @@ backtrace = ["std"]
2626
# Enable the `From<Error> for anyhow::Error` implementation and
2727
# `Error::from_anyhow` constructor.
2828
anyhow = ["dep:anyhow"]
29+
serde = ["dep:serde"]

crates/core/src/alloc/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl From<inner::String> for TryString {
6767
}
6868
}
6969

70+
#[cfg(feature = "serde")]
7071
impl serde::ser::Serialize for TryString {
7172
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
7273
where
@@ -76,6 +77,7 @@ impl serde::ser::Serialize for TryString {
7677
}
7778
}
7879

80+
#[cfg(feature = "serde")]
7981
impl<'de> serde::de::Deserialize<'de> for TryString {
8082
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
8183
where

crates/core/src/alloc/vec.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ use crate::error::OutOfMemory;
33
use core::borrow::Borrow;
44
use core::{
55
cmp::Ordering,
6-
fmt,
7-
marker::PhantomData,
8-
mem,
6+
fmt, mem,
97
num::NonZeroUsize,
108
ops::{Deref, DerefMut, Index, IndexMut},
119
slice::SliceIndex,
1210
};
11+
#[cfg(feature = "serde")]
1312
use serde::ser::SerializeSeq;
1413
use std_alloc::alloc::Layout;
1514
use std_alloc::boxed::Box;
@@ -389,6 +388,7 @@ impl<T> From<Box<[T]>> for Vec<T> {
389388
}
390389
}
391390

391+
#[cfg(feature = "serde")]
392392
impl<T> serde::ser::Serialize for Vec<T>
393393
where
394394
T: serde::ser::Serialize,
@@ -405,6 +405,7 @@ where
405405
}
406406
}
407407

408+
#[cfg(feature = "serde")]
408409
impl<'de, T> serde::de::Deserialize<'de> for Vec<T>
409410
where
410411
T: serde::de::Deserialize<'de>,
@@ -413,6 +414,8 @@ where
413414
where
414415
D: serde::Deserializer<'de>,
415416
{
417+
use core::marker::PhantomData;
418+
416419
struct Visitor<T>(PhantomData<fn() -> Vec<T>>);
417420

418421
impl<'de, T> serde::de::Visitor<'de> for Visitor<T>

crates/environ/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ target-lexicon = { workspace = true }
3737
wasm-encoder = { workspace = true, optional = true }
3838
wasmprinter = { workspace = true, optional = true }
3939
wasmtime-component-util = { workspace = true, optional = true }
40-
wasmtime-core = { workspace = true }
40+
wasmtime-core = { workspace = true, features = ['serde'] }
4141
semver = { workspace = true, optional = true, features = ['serde'] }
4242
smallvec = { workspace = true, features = ['serde'] }
4343
sha2 = { workspace = true }

crates/fuzzing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ wasmparser = { workspace = true }
2828
wasmprinter = { workspace = true }
2929
wasmtime-wast = { workspace = true, features = ['component-model'] }
3030
wasmtime = { workspace = true, features = ['default', 'winch'] }
31-
wasmtime-core = { workspace = true, features = ['backtrace'] }
31+
wasmtime-core = { workspace = true, features = ['backtrace', 'serde'] }
3232
wasm-encoder = { workspace = true }
3333
wasm-smith = { workspace = true, features = ['serde'] }
3434
wasm-mutate = { workspace = true }

crates/wasmtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ wasmtime-component-macro = { workspace = true, optional = true }
2929
wasmtime-component-util = { workspace = true, optional = true }
3030
wasmtime-versioned-export-macros = { workspace = true }
3131
wasmtime-wmemcheck = { workspace = true, optional = true }
32-
wasmtime-core = { workspace = true }
32+
wasmtime-core = { workspace = true, features = ['serde'] }
3333
pulley-interpreter = { workspace = true }
3434
target-lexicon = { workspace = true }
3535
wasmparser = { workspace = true }

0 commit comments

Comments
 (0)