Skip to content

Commit

Permalink
Merge pull request #2 from codebase-labs/0.16.20-wasm
Browse files Browse the repository at this point in the history
Use c2rust implementation when targeting Wasm
  • Loading branch information
bunnie authored Nov 3, 2022
2 parents 0920704 + 97f508f commit de34076
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ once_cell = { version = "1.5.2", default-features = false, features=["std"], opt
once_cell = { version = "1.5.2", default-features = false, features=["std"] }

[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown", target_env = ""))'.dependencies]
web-sys = { version = "0.3.37", default-features = false, features = ["Crypto", "Window"] }
web-sys = { version = "0.3.37", default-features = false, features = ["Crypto", "Window"], optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.8", default-features = false, features = ["ntsecapi", "wtypesbase"] }
Expand Down Expand Up @@ -347,7 +347,7 @@ slow_tests = []
std = ["alloc"]
test_logging = []
wasm32_c = []
# wasm32_unknown_unknown_js = ["web-sys"]
wasm32_unknown_unknown_js = ["web-sys"]
size_optimized = []

# XXX: debug = false because of https://github.com/rust-lang/rust/issues/34122
Expand Down
17 changes: 8 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extern crate alloc;
#[macro_use]
mod debug;

#[cfg(target_os="xous")]
#[cfg(any(target_arch="wasm32", target_os="xous"))]
#[macro_use]
mod prefixed;

Expand Down Expand Up @@ -109,11 +109,11 @@ pub mod io;

mod cpu;
pub mod digest;
#[cfg(all(target_os="xous",not(target_arch="x86_64")))]
#[cfg(any(target_arch="wasm32", all(target_os="xous",not(target_arch="x86_64"))))]
pub mod ec_17;
#[cfg(all(target_os="xous",not(target_arch="x86_64")))]
#[cfg(any(target_arch="wasm32", all(target_os="xous",not(target_arch="x86_64"))))]
pub use ec_17 as ec;
#[cfg(not(all(target_os="xous",not(target_arch="x86_64"))))]
#[cfg(not(any(target_arch="wasm32", all(target_os="xous",not(target_arch="x86_64")))))]
mod ec;
mod endian;
pub mod error;
Expand Down Expand Up @@ -145,7 +145,7 @@ mod sealed {
pub trait Sealed {}
}

#[cfg(target_os="xous")]
#[cfg(any(target_arch="wasm32", target_os="xous"))]
mod c2rust {
pub mod aes_nohw;
pub mod montgomery;
Expand All @@ -167,12 +167,12 @@ mod xous_rand;
#[cfg(target_os="xous")]
pub mod xous_test;

#[cfg(target_os="xous")]
#[cfg(any(target_arch="wasm32", target_os="xous"))]
type c_char = i8;
#[cfg(target_os="xous")]
#[cfg(any(target_arch="wasm32", target_os="xous"))]
type c_uint = u32;
#[cfg(target_os="xous")]
#[export_name = "__assert_fail"]
#[cfg(any(target_arch="wasm32", target_os="xous"))]
pub unsafe extern "C" fn __assert_fail(
__assertion: *const c_char,
__file: *const c_char,
Expand All @@ -181,4 +181,3 @@ pub unsafe extern "C" fn __assert_fail(
) -> ! {
panic!("assert fail");
}

2 changes: 1 addition & 1 deletion src/limb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ pub fn fold_5_bit_windows<R, I: FnOnce(Window) -> R, F: Fn(R, Window) -> R>(
})
}

#[cfg(target_os="xous")]
#[cfg(any(target_arch = "wasm32", target_os = "xous"))]
#[inline]
pub(crate) fn limbs_add_assign_mod(a: &mut [Limb], b: &[Limb], m: &[Limb]) {
debug_assert_eq!(a.len(), m.len());
Expand Down
16 changes: 16 additions & 0 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ mod sysrand_chunk {
}

#[cfg(all(
feature = "wasm32_unknown_unknown_js",
target_arch = "wasm32",
target_vendor = "unknown",
target_os = "unknown",
Expand Down Expand Up @@ -291,6 +292,21 @@ mod sysrand_chunk {
}
}

#[cfg(all(
not(feature = "wasm32_unknown_unknown_js"),
target_arch = "wasm32",
target_vendor = "unknown",
target_os = "unknown",
target_env = "",
))]
mod sysrand_chunk {
use crate::error;

pub fn chunk(mut _dest: &mut [u8]) -> Result<usize, error::Unspecified> {
unimplemented!()
}
}

#[cfg(windows)]
mod sysrand_chunk {
use crate::{error, polyfill};
Expand Down

0 comments on commit de34076

Please sign in to comment.