Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix wasm build.
Browse files Browse the repository at this point in the history
  • Loading branch information
eskimor committed Mar 14, 2021
1 parent c304e9a commit 292864c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "mast
hex-literal = "0.3.1"
parity-util-mem = { version = "0.9.0", default-features = false, optional = true }
thiserror = "1.0.23"
zstd = { version = "0.5.0", optional = true }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
zstd = "0.5.0"

[dev-dependencies]
sp-serializer = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down Expand Up @@ -56,5 +58,4 @@ std = [
"polkadot-core-primitives/std",
"bitvec/std",
"frame-system/std",
"zstd"
]
10 changes: 5 additions & 5 deletions primitives/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,19 @@ pub enum CompressedPoVError {
#[cfg(feature = "std")]
impl CompressedPoV {
/// Compress the given [`PoV`] and returns a [`CompressedPoV`].
#[cfg(feature = "std")]
#[cfg(not(target_os = "unknown"))]
pub fn compress(pov: &PoV) -> Result<Self, CompressedPoVError> {
zstd::encode_all(pov.encode().as_slice(), 3).map_err(|_| CompressedPoVError::Compress).map(Self)
}

/// Compress the given [`PoV`] and returns a [`CompressedPoV`].
#[cfg(not(feature = "std"))]
#[cfg(target_os = "unknown")]
pub fn compress(_: &PoV) -> Result<Self, CompressedPoVError> {
Err(CompressedPoVError::NotSupported)
}

/// Decompress `self` and returns the [`PoV`] on success.
#[cfg(feature = "std")]
#[cfg(not(target_os = "unknown"))]
pub fn decompress(&self) -> Result<PoV, CompressedPoVError> {
use std::io::Read;
const MAX_POV_BLOCK_SIZE: usize = 32 * 1024 * 1024;
Expand All @@ -511,13 +511,13 @@ impl CompressedPoV {
}

/// Decompress `self` and returns the [`PoV`] on success.
#[cfg(not(feature = "std"))]
#[cfg(target_os = "unknown")]
pub fn decompress(&self) -> Result<PoV, CompressedPoVError> {
Err(CompressedPoVError::NotSupported)
}
}

#[cfg(feature = "std")]
#[cfg(not(target_os = "unknown"))]
impl std::fmt::Debug for CompressedPoV {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CompressedPoV({} bytes)", self.0.len())
Expand Down

0 comments on commit 292864c

Please sign in to comment.