diff --git a/package-lock.json b/package-lock.json index ca317691..d2d961e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cardano-serialization-lib", - "version": "14.1.2", + "version": "15.0.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cardano-serialization-lib", - "version": "14.1.2", + "version": "15.0.0-beta.1", "hasInstallScript": true, "license": "MIT", "devDependencies": { diff --git a/package.json b/package.json index 4c040fd7..abd3e898 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cardano-serialization-lib", - "version": "14.1.2", + "version": "15.0.0", "description": "(De)serialization functions for the Cardano blockchain along with related utility functions", "scripts": { "publish-all:prod": "node scripts/build-helper.js publish-all --env prod", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 61cf18b8..6a9c0e94 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardano-serialization-lib" -version = "14.1.2" +version = "15.0.0" edition = "2018" authors = ["EMURGO"] license = "MIT" @@ -19,6 +19,7 @@ arbitrary-precision-json = ["serde_json/arbitrary_precision"] property-test-api = [] generic-serialization = [] with-bench = [] +dont-expose-wasm = [] [lib] crate-type = ["cdylib", "rlib"] diff --git a/rust/json-gen/Cargo.lock b/rust/json-gen/Cargo.lock index 75a46683..cab6f94d 100644 --- a/rust/json-gen/Cargo.lock +++ b/rust/json-gen/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ahash" @@ -49,7 +49,7 @@ checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "cardano-serialization-lib" -version = "14.1.2" +version = "15.0.0" dependencies = [ "bech32", "cbor_event", diff --git a/rust/src/error.rs b/rust/src/error.rs index e1f5b13c..5ec8648a 100644 --- a/rust/src/error.rs +++ b/rust/src/error.rs @@ -149,7 +149,7 @@ impl std::fmt::Display for DeserializeError { } } -#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] impl std::error::Error for DeserializeError {} impl From for JsError { @@ -197,16 +197,16 @@ impl From for DeserializeError { // Generic string error that is replaced with JsError on wasm builds but still usable from non-wasm builds // since JsError panics when used for non-constants in non-wasm builds even just creating one -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))] pub type JsError = JsValue; -#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] #[derive(Debug, Clone)] pub struct JsError { msg: String, } -#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] impl JsError { pub fn from_str(s: &str) -> Self { Self { msg: s.to_owned() } @@ -218,14 +218,14 @@ impl JsError { } } -#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] impl std::fmt::Display for JsError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.msg) } } -#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] impl std::error::Error for JsError {} pub(crate) enum BuilderError { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 02ada321..3f9e2251 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -24,10 +24,10 @@ extern crate num_derive; use std::convert::TryInto; use std::io::{BufRead, Seek, Write}; -#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] +#[cfg(any(not(all(target_arch = "wasm32", not(target_os = "emscripten"))), feature = "dont-expose-wasm"))] use noop_proc_macro::wasm_bindgen; -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))] use wasm_bindgen::prelude::{wasm_bindgen, JsValue}; // This file was code-generated using an experimental CDDL to rust tool: diff --git a/rust/src/protocol_types/certificates/certificates_collection.rs b/rust/src/protocol_types/certificates/certificates_collection.rs index d02d907f..bf45969b 100644 --- a/rust/src/protocol_types/certificates/certificates_collection.rs +++ b/rust/src/protocol_types/certificates/certificates_collection.rs @@ -4,14 +4,14 @@ use std::hash::{Hash, Hasher}; use std::iter::Map; use itertools::Itertools; use std::ops::Deref; -use std::rc::Rc; use std::slice; +use std::sync::Arc; #[wasm_bindgen] #[derive(Clone, Debug)] pub struct Certificates { - pub(crate) certs: Vec>, - pub(crate) dedup: HashSet>, + pub(crate) certs: Vec>, + pub(crate) dedup: HashSet>, pub(crate) cbor_set_type: CborSetType, } @@ -44,7 +44,7 @@ impl Certificates { /// Add a new `Certificate` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, elem: &Certificate) -> bool { - let rc_elem = Rc::new(elem.clone()); + let rc_elem = Arc::new(elem.clone()); if self.dedup.insert(rc_elem.clone()) { self.certs.push(rc_elem.clone()); true @@ -54,7 +54,7 @@ impl Certificates { } pub(crate) fn add_move(&mut self, elem: Certificate) { - let rc_elem = Rc::new(elem); + let rc_elem = Arc::new(elem); if self.dedup.insert(rc_elem.clone()) { self.certs.push(rc_elem.clone()); } @@ -106,8 +106,8 @@ impl Hash for Certificates { impl<'a> IntoIterator for &'a Certificates { type Item = &'a Certificate; type IntoIter = Map< - slice::Iter<'a, Rc>, - fn(&'a Rc) -> &'a Certificate, + slice::Iter<'a, Arc>, + fn(&'a Arc) -> &'a Certificate, >; fn into_iter(self) -> Self::IntoIter { diff --git a/rust/src/protocol_types/credentials.rs b/rust/src/protocol_types/credentials.rs index 8c95cad4..b8de5825 100644 --- a/rust/src/protocol_types/credentials.rs +++ b/rust/src/protocol_types/credentials.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::hash::{Hash, Hasher}; use std::ops::Deref; -use std::rc::Rc; +use std::sync::Arc; use itertools::Itertools; use crate::*; @@ -11,8 +11,8 @@ use crate::*; Debug, )] pub struct Credentials { - pub(crate) credentials: Vec>, - pub(crate) dedup: HashSet>, + pub(crate) credentials: Vec>, + pub(crate) dedup: HashSet>, pub(crate) cbor_set_type: CborSetType, } @@ -29,8 +29,8 @@ impl Credentials { } pub(crate) fn new_from_prepared_fields( - credentials: Vec>, - dedup: HashSet>, + credentials: Vec>, + dedup: HashSet>, ) -> Self { Self { credentials, @@ -50,7 +50,7 @@ impl Credentials { /// Add a new `Credential` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self,credential: &Credential) -> bool { - let credential_rc = Rc::new(credential.clone()); + let credential_rc = Arc::new(credential.clone()); if self.dedup.insert(credential_rc.clone()) { self.credentials.push(credential_rc); true @@ -60,7 +60,7 @@ impl Credentials { } pub(crate) fn add_move(&mut self, credential: Credential) { - let credential_rc = Rc::new(credential); + let credential_rc = Arc::new(credential); if self.dedup.insert(credential_rc.clone()) { self.credentials.push(credential_rc); } @@ -75,7 +75,7 @@ impl Credentials { let mut dedup = HashSet::new(); let mut credentials = Vec::new(); for elem in vec { - let elem_rc = Rc::new(elem); + let elem_rc = Arc::new(elem); if dedup.insert(elem_rc.clone()) { credentials.push(elem_rc); } @@ -87,7 +87,7 @@ impl Credentials { let mut dedup = HashSet::new(); let mut credentials = Vec::new(); for elem in iter { - let elem_rc = Rc::new(elem); + let elem_rc = Arc::new(elem); if dedup.insert(elem_rc.clone()) { credentials.push(elem_rc); } diff --git a/rust/src/protocol_types/ed25519_key_hashes.rs b/rust/src/protocol_types/ed25519_key_hashes.rs index 8f5cad5b..3b0be130 100644 --- a/rust/src/protocol_types/ed25519_key_hashes.rs +++ b/rust/src/protocol_types/ed25519_key_hashes.rs @@ -1,9 +1,9 @@ use std::collections::HashSet; use std::hash::{Hash, Hasher}; use std::ops::Deref; -use std::rc::Rc; use std::slice; use std::iter::Map; +use std::sync::Arc; use itertools::Itertools; pub use crate::*; @@ -15,8 +15,8 @@ pub type RequiredSigners = Ed25519KeyHashes; Debug, )] pub struct Ed25519KeyHashes { - keyhashes: Vec>, - dedup: HashSet>, + keyhashes: Vec>, + dedup: HashSet>, cbor_set_type: CborSetType, } @@ -33,8 +33,8 @@ impl Ed25519KeyHashes { } pub(crate) fn new_from_prepared_fields( - keyhashes: Vec>, - dedup: HashSet>, + keyhashes: Vec>, + dedup: HashSet>, ) -> Self { Self { keyhashes, @@ -54,7 +54,7 @@ impl Ed25519KeyHashes { /// Add a new `Ed25519KeyHash` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, keyhash: &Ed25519KeyHash) -> bool { - let keyhash_rc = Rc::new(keyhash.clone()); + let keyhash_rc = Arc::new(keyhash.clone()); if self.dedup.insert(keyhash_rc.clone()) { self.keyhashes.push(keyhash_rc.clone()); true @@ -76,7 +76,7 @@ impl Ed25519KeyHashes { } pub(crate) fn add_move(&mut self, keyhash: Ed25519KeyHash) { - let keyhash_rc = Rc::new(keyhash); + let keyhash_rc = Arc::new(keyhash); if self.dedup.insert(keyhash_rc.clone()) { self.keyhashes.push(keyhash_rc); } @@ -100,7 +100,7 @@ impl Ed25519KeyHashes { let mut dedup = HashSet::new(); let mut keyhashes = Vec::new(); for keyhash in keyhash_vec { - let keyhash_rc = Rc::new(keyhash.clone()); + let keyhash_rc = Arc::new(keyhash.clone()); if dedup.insert(keyhash_rc.clone()) { keyhashes.push(keyhash_rc); } @@ -121,8 +121,8 @@ impl Ed25519KeyHashes { impl<'a> IntoIterator for &'a Ed25519KeyHashes { type Item = &'a Ed25519KeyHash; type IntoIter = Map< - slice::Iter<'a, Rc>, - fn(&'a Rc) -> &'a Ed25519KeyHash, + slice::Iter<'a, Arc>, + fn(&'a Arc) -> &'a Ed25519KeyHash, >; fn into_iter(self) -> Self::IntoIter { diff --git a/rust/src/protocol_types/governance/proposals/voting_proposals.rs b/rust/src/protocol_types/governance/proposals/voting_proposals.rs index 9d53efbf..5639efe7 100644 --- a/rust/src/protocol_types/governance/proposals/voting_proposals.rs +++ b/rust/src/protocol_types/governance/proposals/voting_proposals.rs @@ -1,10 +1,10 @@ use std::hash::{Hash, Hasher}; use std::ops::Deref; -use std::rc::Rc; use std::slice; use std::iter::Map; use std::collections::HashSet; use std::cmp::Ordering; +use std::sync::Arc; use itertools::Itertools; use schemars::JsonSchema; use crate::*; @@ -15,8 +15,8 @@ use crate::*; Debug, )] pub struct VotingProposals { - proposals: Vec>, - dedup: HashSet>, + proposals: Vec>, + dedup: HashSet>, cbor_set_type: CborSetType, } @@ -39,8 +39,8 @@ impl VotingProposals { } pub(crate) fn new_from_prepared_fields( - proposals: Vec>, - dedup: HashSet>, + proposals: Vec>, + dedup: HashSet>, ) -> Self { Self { proposals, @@ -60,7 +60,7 @@ impl VotingProposals { /// Add a new `VotingProposal` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, proposal: &VotingProposal) -> bool { - let proposal_rc = Rc::new(proposal.clone()); + let proposal_rc = Arc::new(proposal.clone()); if self.dedup.insert(proposal_rc.clone()) { self.proposals.push(proposal_rc.clone()); true @@ -85,7 +85,7 @@ impl VotingProposals { let mut dedup = HashSet::new(); let mut proposals = Vec::new(); for proposal in proposal_vec { - let proposal_rc = Rc::new(proposal.clone()); + let proposal_rc = Arc::new(proposal.clone()); if dedup.insert(proposal_rc.clone()) { proposals.push(proposal_rc); } @@ -105,8 +105,8 @@ impl VotingProposals { impl<'a> IntoIterator for &'a VotingProposals { type Item = &'a VotingProposal; type IntoIter = Map< - slice::Iter<'a, Rc>, - fn(&'a Rc) -> &'a VotingProposal, + slice::Iter<'a, Arc>, + fn(&'a Arc) -> &'a VotingProposal, >; fn into_iter(self) -> Self::IntoIter { diff --git a/rust/src/protocol_types/tx_inputs.rs b/rust/src/protocol_types/tx_inputs.rs index 97936e3e..9192e133 100644 --- a/rust/src/protocol_types/tx_inputs.rs +++ b/rust/src/protocol_types/tx_inputs.rs @@ -3,14 +3,14 @@ use itertools::Itertools; use std::hash::{Hash, Hasher}; use std::iter::Map; use std::ops::Deref; -use std::rc::Rc; use std::slice; +use std::sync::Arc; #[wasm_bindgen] #[derive(Clone, Debug)] pub struct TransactionInputs { - pub(crate) inputs: Vec>, - pub(crate) dedup: BTreeSet>, + pub(crate) inputs: Vec>, + pub(crate) dedup: BTreeSet>, pub(crate) cbor_set_type: CborSetType, } @@ -33,8 +33,8 @@ impl TransactionInputs { } pub(crate) fn new_from_prepared_fields( - inputs: Vec>, - dedup: BTreeSet>, + inputs: Vec>, + dedup: BTreeSet>, ) -> Self { Self { inputs, @@ -54,7 +54,7 @@ impl TransactionInputs { /// Add a new `TransactionInput` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, input: &TransactionInput) -> bool { - let input_rc = Rc::new(input.clone()); + let input_rc = Arc::new(input.clone()); if self.dedup.insert(input_rc.clone()) { self.inputs.push(input_rc.clone()); true @@ -80,7 +80,7 @@ impl TransactionInputs { let mut dedup = BTreeSet::new(); let mut inputs = Vec::new(); for input in inputs_vec { - let input_rc = Rc::new(input.clone()); + let input_rc = Arc::new(input.clone()); if dedup.insert(input_rc.clone()) { inputs.push(input_rc); } @@ -101,8 +101,8 @@ impl TransactionInputs { impl<'a> IntoIterator for &'a TransactionInputs { type Item = &'a TransactionInput; type IntoIter = Map< - slice::Iter<'a, Rc>, - fn(&'a Rc) -> &'a TransactionInput, + slice::Iter<'a, Arc>, + fn(&'a Arc) -> &'a TransactionInput, >; fn into_iter(self) -> Self::IntoIter { diff --git a/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs b/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs index fe62574b..1cdd6862 100644 --- a/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs +++ b/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs @@ -1,9 +1,9 @@ use std::hash::{Hash, Hasher}; -use std::rc::Rc; use std::ops::Deref; use std::slice; use std::iter::Map; use std::collections::HashSet; +use std::sync::Arc; use itertools::Itertools; use schemars::JsonSchema; use crate::*; @@ -11,8 +11,8 @@ use crate::*; #[wasm_bindgen] #[derive(Clone, Debug)] pub struct BootstrapWitnesses { - witnesses: Vec>, - dedup: HashSet>, + witnesses: Vec>, + dedup: HashSet>, cbor_set_type: CborSetType, force_original_cbor_set_type: bool, } @@ -37,8 +37,8 @@ impl BootstrapWitnesses { } pub(crate) fn new_from_prepared_fields( - witnesses: Vec>, - dedup: HashSet>, + witnesses: Vec>, + dedup: HashSet>, ) -> Self { Self { witnesses, @@ -59,7 +59,7 @@ impl BootstrapWitnesses { /// Add a new `BootstrapWitness` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, witness: &BootstrapWitness) -> bool { - let witness_rc = Rc::new(witness.clone()); + let witness_rc = Arc::new(witness.clone()); if self.dedup.insert(witness_rc.clone()) { self.witnesses.push(witness_rc); true @@ -72,7 +72,7 @@ impl BootstrapWitnesses { let mut dedup = HashSet::new(); let mut witnesses = Vec::new(); for witness in witnesses_vec { - let witness_rc = Rc::new(witness.clone()); + let witness_rc = Arc::new(witness.clone()); if dedup.insert(witness_rc.clone()) { witnesses.push(witness_rc); } @@ -89,7 +89,7 @@ impl BootstrapWitnesses { self.cbor_set_type = cbor_set_type; } - pub(crate) fn get_vec_wits(&self) -> &Vec> { + pub(crate) fn get_vec_wits(&self) -> &Vec> { &self.witnesses } @@ -110,8 +110,8 @@ impl BootstrapWitnesses { impl<'a> IntoIterator for &'a BootstrapWitnesses { type Item = &'a BootstrapWitness; type IntoIter = Map< - slice::Iter<'a, Rc>, - fn(&'a Rc) -> &'a BootstrapWitness, + slice::Iter<'a, Arc>, + fn(&'a Arc) -> &'a BootstrapWitness, >; fn into_iter(self) -> Self::IntoIter { diff --git a/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs b/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs index bfb2a568..0dde0737 100644 --- a/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs +++ b/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs @@ -84,13 +84,13 @@ impl FixedTxWitnessesSet { buf.finalize() } - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] pub fn from_bytes(data: Vec) -> Result { let mut raw = Deserializer::from(std::io::Cursor::new(data)); Self::deserialize(&mut raw) } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))] pub fn from_bytes(data: Vec) -> Result { let mut raw = Deserializer::from(std::io::Cursor::new(data)); Ok(Self::deserialize(&mut raw)?) diff --git a/rust/src/protocol_types/witnesses/vkeywitnesses.rs b/rust/src/protocol_types/witnesses/vkeywitnesses.rs index 94bce1d1..bbcd705c 100644 --- a/rust/src/protocol_types/witnesses/vkeywitnesses.rs +++ b/rust/src/protocol_types/witnesses/vkeywitnesses.rs @@ -1,9 +1,9 @@ use std::hash::{Hash, Hasher}; use std::ops::Deref; -use std::rc::Rc; use std::slice; use std::iter::Map; use std::collections::HashSet; +use std::sync::Arc; use itertools::Itertools; use schemars::JsonSchema; use crate::*; @@ -14,8 +14,8 @@ use crate::*; Debug, )] pub struct Vkeywitnesses { - witnesses: Vec>, - dedup: HashSet>, + witnesses: Vec>, + dedup: HashSet>, cbor_set_type: CborSetType, force_original_cbor_set_type: bool, } @@ -40,8 +40,8 @@ impl Vkeywitnesses { } pub(crate) fn new_from_prepared_fields( - witnesses: Vec>, - dedup: HashSet>, + witnesses: Vec>, + dedup: HashSet>, ) -> Self { Self { witnesses, @@ -62,7 +62,7 @@ impl Vkeywitnesses { /// Add a new `Vkeywitness` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, witness: &Vkeywitness) -> bool { - let witness_rc = Rc::new(witness.clone()); + let witness_rc = Arc::new(witness.clone()); if self.dedup.insert(witness_rc.clone()) { self.witnesses.push(witness_rc.clone()); true @@ -72,7 +72,7 @@ impl Vkeywitnesses { } pub(crate) fn add_move(&mut self, witness: Vkeywitness) { - let witness_rc = Rc::new(witness); + let witness_rc = Arc::new(witness); if self.dedup.insert(witness_rc.clone()) { self.witnesses.push(witness_rc); } @@ -82,7 +82,7 @@ impl Vkeywitnesses { let mut dedup = HashSet::new(); let mut witnesses = Vec::new(); for witness in vec { - let witness_rc = Rc::new(witness.clone()); + let witness_rc = Arc::new(witness.clone()); if dedup.insert(witness_rc.clone()) { witnesses.push(witness_rc); } @@ -115,8 +115,8 @@ impl Vkeywitnesses { impl<'a> IntoIterator for &'a Vkeywitnesses { type Item = &'a Vkeywitness; type IntoIter = Map< - slice::Iter<'a, Rc>, - fn(&'a Rc) -> &'a Vkeywitness, + slice::Iter<'a, Arc>, + fn(&'a Arc) -> &'a Vkeywitness, >; fn into_iter(self) -> Self::IntoIter { diff --git a/rust/src/serialization/serialization_macros.rs b/rust/src/serialization/serialization_macros.rs index 6d7623bc..97d81e84 100644 --- a/rust/src/serialization/serialization_macros.rs +++ b/rust/src/serialization/serialization_macros.rs @@ -9,7 +9,7 @@ macro_rules! from_bytes { // Custom from_bytes() code ($name:ident, $data: ident, $body:block) => { // wasm-exposed JsError return - JsError panics when used outside wasm - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))] #[wasm_bindgen] impl $name { pub fn from_bytes($data: Vec) -> Result<$name, JsError> { @@ -17,7 +17,7 @@ macro_rules! from_bytes { } } // non-wasm exposed DeserializeError return - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] impl $name { pub fn from_bytes($data: Vec) -> Result<$name, DeserializeError> $body } @@ -54,7 +54,7 @@ macro_rules! from_hex { // Custom from_bytes() code ($name:ident, $data: ident, $body:block) => { // wasm-exposed JsError return - JsError panics when used outside wasm - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))] #[wasm_bindgen] impl $name { pub fn from_hex($data: &str) -> Result<$name, JsError> { @@ -66,7 +66,7 @@ macro_rules! from_hex { } } // non-wasm exposed DeserializeError return - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))] impl $name { pub fn from_hex($data: &str) -> Result<$name, DeserializeError> $body } @@ -114,9 +114,10 @@ macro_rules! to_from_json { .map_err(|e| JsError::from_str(&format!("to_json: {}", e))) } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))] pub fn to_js_value(&self) -> Result { - serde_wasm_bindgen::to_value(&self) + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + serde::Serialize::serialize(self, &serializer) .map_err(|e| JsError::from_str(&format!("to_js_value: {}", e))) } diff --git a/scripts/build-helper.js b/scripts/build-helper.js index 2fc85200..d35cbabc 100755 --- a/scripts/build-helper.js +++ b/scripts/build-helper.js @@ -78,7 +78,8 @@ program return value; }) .action((options) => { - publishPackage(options.target, options.variant, options.gc, options.env); + const config = { target: options.target, variant: options.variant, gc: options.gc }; + handlePackagePublish(config, options.env, { runTests: true }); console.log(`\n✅ Publish completed successfully!`); }); @@ -171,113 +172,65 @@ function getPackageInfo(packageJsonPath) { } } -function publishPackage(target, variant, gc, env) { +function handlePackagePublish(config, env, options = {}) { + const { dryRun = false, runTests = false } = options; + const { target, variant, gc } = config; const publishTag = env === 'beta' ? '--tag beta' : ''; // Build first buildRust(target, variant, gc); - // Run tests - run('npm run rust:test', 'Running Rust tests'); + // Run tests if requested + if (runTests) { + run('npm run rust:test', 'Running Rust tests'); + } // Prepare publish run('npm run js:prepublish', 'Preparing for publish'); // Configure package - const targetSuffix = variant === 'normal' ? target : `${target}-${variant}`; + let targetSuffix = variant === 'normal' ? target : `${target}-${variant}`; + if(targetSuffix === 'browser-asm') { + targetSuffix = "asmjs" + } const gcSuffix = gc ? ' -gc' : ''; const helperCmd = `node ./scripts/publish-helper -${targetSuffix}${gcSuffix}`; run(helperCmd, 'Configuring package for publish'); // Check if version already exists + let skipPublish = false; const packageInfo = getPackageInfo('./publish/package.json'); if (packageInfo) { console.log(`\n🔍 Checking if ${packageInfo.name}@${packageInfo.version} already exists...`); if (checkVersionExists(packageInfo.name, packageInfo.version)) { - console.log(`\n⚠️ WARNING: Package ${packageInfo.name}@${packageInfo.version} already exists on npm!`); - console.log(` Please bump the version in package.json before publishing.`); - console.log(`\n❌ Aborting publish to prevent duplicate version.`); - process.exit(1); + if (dryRun) { + console.log(`\n⚠️ Package ${packageInfo.name}@${packageInfo.version} already exists on npm.`); + console.log(` In a real publish, this would require a version bump.`); + } else { + console.log(`\n⚠️ WARNING: Package ${packageInfo.name}@${packageInfo.version} already exists on npm!`); + console.log(` Please bump the version in package.json before publishing.`); + console.log(`\n❌ Publish will be skipped.`); + skipPublish = true; + } } else { console.log(`✅ Version ${packageInfo.version} is available for publishing.`); } } - // Publish - run(`cd publish && npm publish ${publishTag} --access public`, `Publishing to npm${env === 'beta' ? ' (beta)' : ''}`); -} - -function publishSinglePackage(config, env) { - const { target: configTarget, variant: configVariant, gc: configGc } = config; - const publishTag = env === 'beta' ? '--tag beta' : ''; - - // Build first - buildRust(configTarget, configVariant, configGc); - - // Prepare publish - run('npm run js:prepublish', 'Preparing for publish'); - - // Configure package - const targetSuffix = configVariant === 'normal' ? configTarget : `${configTarget}-${configVariant}`; - const gcSuffix = configGc ? ' -gc' : ''; - const helperCmd = `node ./scripts/publish-helper -${targetSuffix}${gcSuffix}`; - - run(helperCmd, 'Configuring package for publish'); - - // Check if version already exists - const packageInfo = getPackageInfo('./publish/package.json'); - if (packageInfo) { - console.log(`\n🔍 Checking if ${packageInfo.name}@${packageInfo.version} already exists...`); - - if (checkVersionExists(packageInfo.name, packageInfo.version)) { - console.log(`\n⚠️ WARNING: Package ${packageInfo.name}@${packageInfo.version} already exists on npm!`); - console.log(` Please bump the version in package.json before publishing.`); - console.log(`\n❌ Aborting publish to prevent duplicate version.`); - throw new Error(`Version ${packageInfo.version} already exists`); - } else { - console.log(`✅ Version ${packageInfo.version} is available for publishing.`); - } + if (skipPublish && !dryRun) { + console.log(`\n⚠️ Skipping publish due to existing version.`); + return; } - - // Publish - run(`cd publish && npm publish ${publishTag} --access public`, `Publishing to npm${env === 'beta' ? ' (beta)' : ''}`); -} -function testPublishSinglePackage(config, env) { - const { target: configTarget, variant: configVariant, gc: configGc } = config; - const publishTag = env === 'beta' ? '--tag beta' : ''; - - // Build first - buildRust(configTarget, configVariant, configGc); - - // Prepare publish - run('npm run js:prepublish', 'Preparing for publish'); - - // Configure package - const targetSuffix = configVariant === 'normal' ? configTarget : `${configTarget}-${configVariant}`; - const gcSuffix = configGc ? ' -gc' : ''; - const helperCmd = `node ./scripts/publish-helper -${targetSuffix}${gcSuffix}`; - - run(helperCmd, 'Configuring package for publish'); - - // Check if version already exists - const packageInfo = getPackageInfo('./publish/package.json'); - if (packageInfo) { - console.log(`\n🔍 Checking if ${packageInfo.name}@${packageInfo.version} already exists...`); - - if (checkVersionExists(packageInfo.name, packageInfo.version)) { - console.log(`\n⚠️ Package ${packageInfo.name}@${packageInfo.version} already exists on npm.`); - console.log(` In a real publish, this would require a version bump.`); - } else { - console.log(`✅ Version ${packageInfo.version} is available for publishing.`); - } + // Publish or test publish + if (dryRun) { + run(`cd publish && npm publish ${publishTag} --access public --dry-run`, `Testing publish to npm${env === 'beta' ? ' (beta)' : ''} (dry-run)`); + run(`cd publish && npm pack`, 'Creating package tarball'); + } else { + run(`cd publish && npm publish ${publishTag} --access public`, `Publishing to npm${env === 'beta' ? ' (beta)' : ''}`); } - - // Test publish using dry-run and pack - run(`cd publish && npm publish ${publishTag} --access public --dry-run`, `Testing publish to npm${env === 'beta' ? ' (beta)' : ''} (dry-run)`); - run(`cd publish && npm pack`, 'Creating package tarball'); } function publishAllPackages(env, dryRun = false) { @@ -314,11 +267,7 @@ function publishAllPackages(env, dryRun = false) { console.log(`\n📦 ${dryRun ? 'Testing' : 'Publishing'} ${configName}...`); try { - if (dryRun) { - testPublishSinglePackage(config, env); - } else { - publishSinglePackage(config, env); - } + handlePackagePublish(config, env, { dryRun }); console.log(`✅ Successfully ${dryRun ? 'tested' : 'published'} ${configName}`); results.push({ config: configName, status: 'success' }); } catch (error) {