A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
wasmtime-wizer: make rayon optional (#12313)
Gentle7981473fb03c
diff --git a/.github/workflows/main.yml b/.github/workflows/main.ymlindex bcb81550b2..75583d9154 100644--- a/.github/workflows/main.yml+++ b/.github/workflows/main.yml@@ -431,6 +431,7 @@ jobs:-p wasmtime-wizer --no-default-features --features wasmtime-p wasmtime-wizer --no-default-features --features wasmprinter-p wasmtime-wizer --no-default-features --features component-model+ -p wasmtime-wizer --no-default-features --features rayon-p wasmtime-wizer --no-default-features --all-featuresruns-on: ubuntu-lateststeps:diff --git a/crates/wizer/Cargo.toml b/crates/wizer/Cargo.tomlindex 1caee3dd6d..36d3f75cb1 100644--- a/crates/wizer/Cargo.toml+++ b/crates/wizer/Cargo.toml@@ -26,7 +26,7 @@ harness = false[dependencies]log = { workspace = true }-rayon = { workspace = true }+rayon = { workspace = true, optional = true }clap = { workspace = true, optional = true }wasm-encoder = { workspace = true, features = ['wasmparser'] }wasmparser = { workspace = true, features = ['validate', 'features'] }@@ -43,6 +43,10 @@ wasmtime-wasi = { workspace = true, features = ["p1"] }tokio = { workspace = true, features = ['macros'] }[features]+default = ["rayon"]+# Enables parallel snapshotting.+# Needs to be disabled if compiling wizer to single-threaded targets like wasm32-unknown-unknown+rayon = ["dep:rayon"]# Enable this dependency to get messages with WAT disassemblies when certain# internal panics occur.wasmprinter = ['dep:wasmprinter']diff --git a/crates/wizer/src/lib.rs b/crates/wizer/src/lib.rsindex 9bc27df3c3..b1a6028091 100644--- a/crates/wizer/src/lib.rs+++ b/crates/wizer/src/lib.rs@@ -19,6 +19,8 @@ pub use wasmtime::*;mod component;#[cfg(feature = "component-model")]pub use component::*;+#[cfg(not(feature = "rayon"))]+mod rayoff;pub use crate::info::ModuleContext;pub use crate::snapshot::SnapshotVal;diff --git a/crates/wizer/src/rayoff.rs b/crates/wizer/src/rayoff.rsnew file mode 100644index 0000000000..42b4a0923f--- /dev/null+++ b/crates/wizer/src/rayoff.rs@@ -0,0 +1,36 @@+use std::ops::Range;++pub trait ParallelIterator: Iterator {}++impl<T: Iterator> ParallelIterator for T {}++pub trait IntoParallelIterator {+ type Item;+ type Iter: Iterator<Item = Self::Item> + ParallelIterator;++ fn into_par_iter(self) -> Self::Iter;+}++impl IntoParallelIterator for Range<usize> {+ type Item = usize;+ type Iter = Range<usize>;++ fn into_par_iter(self) -> Self::Iter {+ self+ }+}++pub trait ParallelExtend<T> {+ fn par_extend<I>(&mut self, par_iter: I)+ where+ I: IntoIterator<Item = T>;+}++impl<T> ParallelExtend<T> for Vec<T> {+ fn par_extend<I>(&mut self, par_iter: I)+ where+ I: IntoIterator<Item = T>,+ {+ self.extend(par_iter);+ }+}diff --git a/crates/wizer/src/snapshot.rs b/crates/wizer/src/snapshot.rsindex ecebec9c4f..a2761ca115 100644--- a/crates/wizer/src/snapshot.rs+++ b/crates/wizer/src/snapshot.rs@@ -1,5 +1,8 @@use crate::InstanceState;use crate::info::ModuleContext;+#[cfg(not(feature = "rayon"))]+use crate::rayoff::{IntoParallelIterator, ParallelExtend};+#[cfg(feature = "rayon")]use rayon::iter::{IntoParallelIterator, ParallelExtend, ParallelIterator};use std::convert::TryFrom;use std::ops::Range;