Skip to content

Commit

Permalink
wasm as platform dependency (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
goulart-paul authored Jan 6, 2025
1 parent 5cf3c76 commit bdbf909
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ 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 @@ -204,9 +202,10 @@ features = ["sdp","sdp-mkl"]
# wasm compatibility
# ------------------------------

[dependencies.web-time]
optional = true
version = "0.2.3"
[target.'cfg(target_family = "wasm")'.dependencies]
web-time = "0.2.3"
[target.'cfg(target_family = "wasm")'.dev-dependencies]
wasm-bindgen-test = "0.3"

# ------------------------------
# testing, benchmarking etc
Expand Down
3 changes: 1 addition & 2 deletions src/timers/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ use std::collections::HashMap;
use std::ops::{Deref, DerefMut};

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


#[derive(Debug, Default)]
struct InnerTimer {
Expand Down
11 changes: 11 additions & 0 deletions tests/basic_qp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![allow(non_snake_case)]
#[cfg(target_family = "wasm")]
use wasm_bindgen_test::*;

use clarabel::{algebra::*, solver::*};

Expand Down Expand Up @@ -173,3 +175,12 @@ fn test_qp_dual_infeasible_ill_cond() {
assert!(solver.solution.obj_val.is_nan());
assert!(solver.solution.obj_val_dual.is_nan());
}

// a minimal test to check that the wasm build is working

#[cfg(target_family = "wasm")]
#[wasm_bindgen_test]
fn test_qp_feasible_wasm() {
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
test_qp_feasible();
}

0 comments on commit bdbf909

Please sign in to comment.