Add support for wasm32 target & silence arithmetic error#8
Add support for wasm32 target & silence arithmetic error#8indiv0 wants to merge 3 commits intohmeyer:mainfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8 +/- ##
==========================================
- Coverage 85.90% 85.35% -0.56%
==========================================
Files 6 6
Lines 596 478 -118
==========================================
- Hits 512 408 -104
+ Misses 84 70 -14
Continue to review full report at Codecov.
|
src/manifold_dual_contouring.rs
Outdated
| result | ||
| } | ||
|
|
||
| #[cfg(not(target_arch="wasm32"))] |
There was a problem hiding this comment.
Instead of removing the full Timer struct (and all print statements below), how about modifying Timer for wasm32 in a way that makes it always return std::time::Duration::zero()? (And adding a comment about that to the Timer code)...
There was a problem hiding this comment.
Sure thing, sounds like a good idea!
There was a problem hiding this comment.
I've replaced std::time::Instant with instant::Instant which is a portable layer that emulates std::time::Instant's functionality IFF:
- the
stdweborwasm-bindgenfeature is enabled, and - you are targetting wasm32
This appears the be the recommended approach based on my reading of the topic.
If you don't approve of this solution, let me know and I'll go with your suggestion of returning std::time::Duration::zero().
Replace `std::time::Instant` with `instant::Instant`. `instant::Instant`, when compiled natively, is just a type alias for `std::time::Instant`, which means that this change has no effect on native platforms. On platforms like `wasm32-unknown-unknown`, the `instant` crate can be compiled with either the `instant/stdweb` or `instant/wasm-bindgen` features. When compiled with these features, `instant::Instant` emulates `std::time::Instant` using features like `performance.now()`. This allows `instant` (and transitively `tessellation`) to run on WASM platforms. To compile `tessellation` with support for WASM platforms, enable either the `stdweb` or `wasm-bindgen` feature of `tessellation`. These features enable the respective `stdweb` or `wasm-bindgen` features of `instant`. Whether you should use `stdweb` or `wasm-bindgen` depends on which of these the rest of your application/library uses. Even if the `stdweb` or `wasm-bindgen` feature is enabled, the `instant` crate will continue to rely on `std::time::Instant` as long as your are not targetting wasm32. This allows for portable code that works on both native and WASM platforms. To support this behaviour, the `wasm-bindgen` feature is enabled by default. The choice of `wasm-bindgen` over `stdweb` was arbitrary.
hmeyer
left a comment
There was a problem hiding this comment.
Sorry for the late reply.
instant::Instant seems like a cool solution!
As for par_iter() vs. iter() - ideally I'd like to see a transparent wrapper, similar to instant::Instant...one that maps .par_iter() to plain .iter() for WASM. Maybe add a TODO in that regard?
Hello! Thank you so much for the awesome library.
I've started using it in a game I'm developing with the Bevy engine (really all I have right is a sphere).
Your library was super simple to get started with and works really well so far.
The only issue I had was rayon and
std::timedon't work on the wasm32 target yet so I needed to disable those to get it to work in the browser.Adding
cfg(not(target_arch = "wasm32"))everywhere the timer & rayon were used got it working for me.