Skip to content
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

Merged
merged 1 commit into from
Jun 27, 2021
Merged

Conversation

extrawurst
Copy link
Contributor

@extrawurst
Copy link
Contributor Author

this fixes rapier upstream running via emscripten: dimforge/rapier#207

Copy link
Owner

@sebcrozet sebcrozet left a 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
Comment on lines 129 to 144
#[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() }
}
Copy link
Owner

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() };
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

@extrawurst extrawurst force-pushed the emscripten-fix branch 2 times, most recently from 8a6117c to 671a8de Compare June 27, 2021 09:46
@sebcrozet sebcrozet merged commit ebce2bb into sebcrozet:master Jun 27, 2021
@sebcrozet
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants