From c9044454c4801dc51f466b24465d1200172547be Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Sat, 2 May 2026 08:20:27 +0200 Subject: [PATCH] chore: rewrite rust debug --- Cargo.lock | 11 +++++++++++ rs_lib/Cargo.toml | 1 + rs_lib/src/lib.rs | 13 +------------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67f7a32..d8bc792 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -659,6 +659,7 @@ dependencies = [ "tempfile", "url", "wasm-bindgen", + "web-sys", ] [[package]] @@ -1009,6 +1010,16 @@ dependencies = [ "semver", ] +[[package]] +name = "web-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi-util" version = "0.1.9" diff --git a/rs_lib/Cargo.toml b/rs_lib/Cargo.toml index 0f8ad2e..faef6c1 100644 --- a/rs_lib/Cargo.toml +++ b/rs_lib/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] anyhow.workspace = true deno_config.workspace = true deno_path_util.workspace = true +web-sys = { version = "=0.3.77", features = ["console"] } js-sys.workspace = true sys_traits = { workspace = true, features = ["real"] } serde.workspace = true diff --git a/rs_lib/src/lib.rs b/rs_lib/src/lib.rs index 71ebd90..99e46e5 100644 --- a/rs_lib/src/lib.rs +++ b/rs_lib/src/lib.rs @@ -10,23 +10,12 @@ use sys_traits::FsMetadata; use url::Url; use wasm_bindgen::prelude::*; -#[cfg(target_arch = "wasm32")] -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(js_namespace = console, js_name = log)] - fn console_log(s: &str); -} - -#[cfg(target_arch = "wasm32")] fn debug_log(debug: bool, msg: &str) { if debug { - console_log(&format!("[rs_lib] {}", msg)); + web_sys::console::log_1(&serde_wasm_bindgen::to_value(&format!("[rs_lib] {}", msg)).unwrap()); } } -#[cfg(not(target_arch = "wasm32"))] -fn debug_log(_debug: bool, _msg: &str) {} - #[derive(Serialize)] pub struct ConfigLookup { pub path: Option,