Skip to content

Commit

Permalink
Fix build for wasm32/64-unknown-unknown without std (#1528)
Browse files Browse the repository at this point in the history
* adjust to no_std build

* disable default features of serde_json

* cargo fmt & clippy

* fix review remarks
  • Loading branch information
gshep authored Feb 15, 2024
1 parent 6f42ed5 commit 8753162
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions maybe_rayon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg_attr(not(std), no_std)]

#[cfg(not(feature = "parallel"))]
use core::{
iter::{FlatMap, IntoIterator, Iterator},
slice::{Chunks, ChunksExact, ChunksExactMut, ChunksMut},
};
extern crate alloc;

#[cfg(feature = "parallel")]
pub use rayon::{
Expand All @@ -20,6 +19,14 @@ use rayon::{
ChunksMut as ParChunksMut, ParallelSlice, ParallelSliceMut,
},
};
#[cfg(not(feature = "parallel"))]
use {
alloc::vec::Vec,
core::{
iter::{FlatMap, IntoIterator, Iterator},
slice::{self, Chunks, ChunksExact, ChunksExactMut, ChunksMut},
},
};

pub trait MaybeParIter<'data> {
#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -53,7 +60,7 @@ where
#[cfg(not(feature = "parallel"))]
impl<'data, T: 'data> MaybeParIter<'data> for Vec<T> {
type Item = &'data T;
type Iter = std::slice::Iter<'data, T>;
type Iter = slice::Iter<'data, T>;

fn par_iter(&'data self) -> Self::Iter {
self.iter()
Expand All @@ -63,7 +70,7 @@ impl<'data, T: 'data> MaybeParIter<'data> for Vec<T> {
#[cfg(not(feature = "parallel"))]
impl<'data, T: 'data> MaybeParIter<'data> for [T] {
type Item = &'data T;
type Iter = std::slice::Iter<'data, T>;
type Iter = slice::Iter<'data, T>;

fn par_iter(&'data self) -> Self::Iter {
self.iter()
Expand Down Expand Up @@ -102,7 +109,7 @@ where
#[cfg(not(feature = "parallel"))]
impl<'data, T: 'data> MaybeParIterMut<'data> for Vec<T> {
type Item = &'data mut T;
type Iter = std::slice::IterMut<'data, T>;
type Iter = slice::IterMut<'data, T>;

fn par_iter_mut(&'data mut self) -> Self::Iter {
self.iter_mut()
Expand All @@ -112,7 +119,7 @@ impl<'data, T: 'data> MaybeParIterMut<'data> for Vec<T> {
#[cfg(not(feature = "parallel"))]
impl<'data, T: 'data> MaybeParIterMut<'data> for [T] {
type Item = &'data mut T;
type Iter = std::slice::IterMut<'data, T>;
type Iter = slice::IterMut<'data, T>;

fn par_iter_mut(&'data mut self) -> Self::Iter {
self.iter_mut()
Expand Down
2 changes: 1 addition & 1 deletion plonky2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ plonky2_util = { path = "../util", default-features = false }
rand = { version = "0.8.4", default-features = false }
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive", "rc"] }
serde_json = "1.0"
static_assertions = { version = "1.1.0", default-features = false }
unroll = { version = "0.1.5", default-features = false }
web-time = { version = "1.0.0", optional = true }
Expand All @@ -46,6 +45,7 @@ num_cpus = { version = "1.14.0", default-features = false }
rand = { version = "0.8.4", default-features = false, features = ["getrandom"] }
rand_chacha = { version = "0.3.1", default-features = false }
serde_cbor = { version = "0.11.2" }
serde_json = { version = "1.0" }
structopt = { version = "0.3.26", default-features = false }
tynm = { version = "0.1.6", default-features = false }

Expand Down

0 comments on commit 8753162

Please sign in to comment.