Skip to content

Commit

Permalink
Add wasm feature (#114)
Browse files Browse the repository at this point in the history
* Add wasm feature

std::time panics on wasm, so we introduce a feature flag that swaps it
out with the web-time crate.
  • Loading branch information
alexarice authored May 31, 2024
1 parent eb6c5d9 commit 7069d78
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ julia = ["sdp", "dep:libc", "dep:num-derive", "serde", "faer-sparse"]
# enable a blas/lapack source package
python = ["sdp", "dep:libc", "dep:pyo3", "dep:num-derive", "serde", "faer-sparse"]

wasm = ["dep:web-time"]

#compile with faer supernodal solver option
faer-sparse = ["dep:faer", "dep:faer-entity"]
Expand Down Expand Up @@ -190,8 +191,17 @@ crate-type = ["lib","cdylib"]
rustdoc-args = [ "--html-in-header", "./html/rustdocs-header.html" ]
features = ["sdp","sdp-mkl"]

# ------------------------------
# wasm compatibility
# ------------------------------

[dependencies.web-time]
optional = true
version = "0.2.3"

# ------------------------------
# testing, benchmarking etc
# ------------------------------
[dev-dependencies]
tempfile = "3"
tempfile = "3"

11 changes: 10 additions & 1 deletion src/timers/timers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use std::time::{Duration, Instant};

cfg_if::cfg_if! {
if #[cfg(feature="wasm")] {
use web_time::{Duration, Instant};
}
else {
use std::time::{Duration, Instant};
}
}


#[derive(Debug, Default)]
struct InnerTimer {
Expand Down

0 comments on commit 7069d78

Please sign in to comment.