Skip to content

add naive wasm32 support using extern date_now() #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/jitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,16 @@ mod platform {

#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub fn get_nstime() -> u64 {
unreachable!()
(unsafe { date_now() } as u64)
}

extern {
pub fn date_now() -> u32;
}
}



// A function that is opaque to the optimizer to assist in avoiding dead-code
// elimination. Taken from `bencher`.
fn black_box<T>(dummy: T) -> T {
Expand Down
11 changes: 9 additions & 2 deletions src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,22 @@ mod imp {

impl OsRng {
pub fn new() -> io::Result<OsRng> {
Err(io::Error::new(io::ErrorKind::Other, "Not supported"))
//Err(io::Error::new(io::ErrorKind::Other, "Not supported"))
Ok(OsRng)
}
}

impl Rng for OsRng {
fn next_u32(&mut self) -> u32 {
panic!("Not supported")
//panic!("Not supported")
let n:u32 = unsafe { date_now() };
(n/1000) as u32
}
}

extern {
pub fn date_now() -> u32;
}
}

#[cfg(test)]
Expand Down