-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix emscripten now method #33
Conversation
this fixes rapier upstream running via emscripten: dimforge/rapier#207 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks you for this PR!
src/wasm.rs
Outdated
#[cfg(not(target_os = "emscripten"))] | ||
mod js { | ||
extern "C" { | ||
pub fn now() -> f64; | ||
} | ||
} | ||
// Make the unsafe extern function "safe" so it can be called like the other 'now' functions | ||
#[cfg(not(any(feature = "wasm-bindgen", feature = "stdweb")))] | ||
#[cfg(not(target_os = "emscripten"))] | ||
pub fn now() -> f64 { | ||
unsafe { js::now() } | ||
} | ||
|
||
#[cfg(not(any(feature = "wasm-bindgen", feature = "stdweb")))] | ||
#[cfg(target_os = "emscripten")] | ||
mod js { | ||
extern "C" { | ||
pub fn _emscripten_get_now() -> f64; | ||
} | ||
} | ||
// Make the unsafe extern function "safe" so it can be called like the other 'now' functions | ||
#[cfg(not(any(feature = "wasm-bindgen", feature = "stdweb")))] | ||
#[cfg(target_os = "emscripten")] | ||
pub fn now() -> f64 { | ||
unsafe { js::_emscripten_get_now() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be more consise:
mod js {
extern "C" {
#[cfg(not(target_os = "emscripten"))]
pub fn now() -> f64;
#[cfg(target_os = "emscripten")]
pub fn _emscripten_get_now() -> f64;
}
}
// Make the unsafe extern function "safe" so it can be called like the other 'now' functions
#[cfg(not(any(feature = "wasm-bindgen", feature = "stdweb")))]
pub fn now() -> f64 {
#[cfg(not(target_os = "emscripten"))]
return unsafe { js::now() };
#[cfg(target_os = "emscripten")]
return unsafe { js::_emscripten_get_now() };
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 👍
8a6117c
to
671a8de
Compare
Thanks! |
see https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/emscripten.h#L85