From 79cdecc56d2908e49739e1489e9ba056f2785c1c Mon Sep 17 00:00:00 2001 From: Mike Mulchrone Date: Sun, 8 Mar 2026 02:51:45 +0000 Subject: [PATCH 1/2] adding changes for wasm compatibility --- Cargo.toml | 9 +++++++-- src/http/mod.rs | 12 +++++++++++- src/http/types/runtime.rs | 4 +++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9eaa629..e747cd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,12 +34,17 @@ hkdf = "0.12.4" chacha20poly1305 = "0.10.1" slh-dsa = "0.0.3" ml-kem = "0.2.1" -reqwest = { version = "0.12.24", default-features = false, features = ["json", "cookies", "rustls-tls"] } serde = { version = "1.0.228", features = ["derive"] } -tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] } url = "2.5.7" once_cell = "1.21.3" +[target.'cfg(target_arch = "wasm32")'.dependencies] +reqwest = { version = "0.12.24", default-features = false, features = ["cookies", "json"] } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] } +reqwest = { version = "0.12.24", default-features = false, features = ["cookies", "rustls-tls", "json"] } + [profile.dev.package.num-bigint-dig] opt-level = 3 diff --git a/src/http/mod.rs b/src/http/mod.rs index 77f9ae5..cc8dea7 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1,7 +1,9 @@ -use reqwest::{Client, cookie::Jar}; use std::sync::{Arc, Mutex}; use url::Url; +#[cfg(not(target_arch = "wasm32"))] +use reqwest::{Client, cookie::Jar}; + pub mod types; use crate::http::types::{BenchmarkRequest}; @@ -10,8 +12,11 @@ static BASE_URL: Mutex = Mutex::new(String::new()); static TOKEN: Mutex = Mutex::new(String::new()); static REFRESH_TOKEN: Mutex = Mutex::new(String::new()); + +#[cfg(not(target_arch = "wasm32"))] static BENCHMARK_SENDER_CLIENT: Mutex> = Mutex::new(None); +#[cfg(not(target_arch = "wasm32"))] fn create_benchmark_sender_client(token: String, refresh_token: String) -> Client { let cookie_store = Arc::new(Jar::default()); let base_url = Url::parse(BASE_URL.lock().unwrap().as_str()).unwrap(); @@ -23,6 +28,7 @@ fn create_benchmark_sender_client(token: String, refresh_token: String) -> Clien .unwrap() } +#[cfg(not(target_arch = "wasm32"))] fn determine_api_route() -> String { let base_url = BASE_URL.lock().unwrap(); if base_url.contains("cryptographicapiservices.com") { @@ -32,17 +38,20 @@ fn determine_api_route() -> String { } } +#[cfg(not(target_arch = "wasm32"))] pub async fn set_api_key_in_cache(api_key: String) { let mut key = API_KEY.lock().unwrap(); *key = api_key.clone(); set_tokens_in_cache(api_key).await; } +#[cfg(not(target_arch = "wasm32"))] pub fn set_base_url_in_cache(base_url: String) { let mut url = BASE_URL.lock().unwrap(); *url = base_url } +#[cfg(not(target_arch = "wasm32"))] pub async fn set_tokens_in_cache(api_key: String) { let client = Client::new(); let base_url = BASE_URL.lock().unwrap().clone(); @@ -79,6 +88,7 @@ pub async fn set_tokens_in_cache(api_key: String) { } } +#[cfg(not(target_arch = "wasm32"))] pub async fn send_benchmark(time_in_milliseconds: i64, class_name: String, method_name: String) { let payload = BenchmarkRequest { class_name, diff --git a/src/http/types/runtime.rs b/src/http/types/runtime.rs index 60d1bfc..df707c0 100644 --- a/src/http/types/runtime.rs +++ b/src/http/types/runtime.rs @@ -1,7 +1,9 @@ - +#[cfg(not(target_arch = "wasm32"))] use once_cell::sync::Lazy; +#[cfg(not(target_arch = "wasm32"))] use tokio::runtime::Runtime; +#[cfg(not(target_arch = "wasm32"))] pub static RUNTIME: Lazy = Lazy::new(|| { tokio::runtime::Builder::new_multi_thread() .enable_all() From 67e50483e8c077664666b9b7a5a5f77ceac972bf Mon Sep 17 00:00:00 2001 From: Mike Mulchrone Date: Sun, 8 Mar 2026 03:56:29 +0000 Subject: [PATCH 2/2] version bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e747cd2..e56e97f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cas-lib" -version = "0.2.73" +version = "0.2.74" edition = "2021" description = "A function wrapper layer for RustCrypto and Dalek-Cryptography. Intended to be used in FFI situations with a global heap deallactor at the top level project." license = "Apache-2.0"