diff --git a/Cargo.toml b/Cargo.toml index 676e789b..741628ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] @@ -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" \ No newline at end of file +tempfile = "3" + diff --git a/src/timers/timers.rs b/src/timers/timers.rs index 671111c4..741d03f4 100644 --- a/src/timers/timers.rs +++ b/src/timers/timers.rs @@ -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 {