diff --git a/Cargo.lock b/Cargo.lock index 65f0baa8..9f4d1791 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5331,6 +5331,7 @@ dependencies = [ "send_wrapper 0.6.0", "serde 1.0.137", "serde_json", + "tracing", "tracing-subscriber", "tracing-wasm", "veilid-core", diff --git a/setup_macos.sh b/setup_macos.sh index 38777903..273743ea 100755 --- a/setup_macos.sh +++ b/setup_macos.sh @@ -7,7 +7,7 @@ if [ ! "$(uname)" == "Darwin" ]; then fi # install targets -rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-darwin x86_64-apple-ios +rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-darwin x86_64-apple-ios wasm32-unknown-unknown # install cargo packages cargo install wasm-bindgen-cli @@ -50,5 +50,5 @@ if [ "$BREW_USER" == "" ]; then BREW_USER=`whoami` fi fi -sudo -H -u $BREW_USER brew install capnp cmake +sudo -H -u $BREW_USER brew install capnp cmake wabt llvm diff --git a/veilid-wasm/Cargo.toml b/veilid-wasm/Cargo.toml index 8612b6be..6bac02a7 100644 --- a/veilid-wasm/Cargo.toml +++ b/veilid-wasm/Cargo.toml @@ -12,6 +12,7 @@ crate-type = ["cdylib", "rlib"] wasm-bindgen = { version = "^0", features = ["serde-serialize"] } console_error_panic_hook = "^0" wee_alloc = "^0" +tracing = { version = "^0", features = ["log", "attributes"] } tracing-wasm = "^0" tracing-subscriber = "^0" veilid-core = { path = "../veilid-core" } diff --git a/veilid-wasm/src/lib.rs b/veilid-wasm/src/lib.rs index 55954943..b7e3e76a 100644 --- a/veilid-wasm/src/lib.rs +++ b/veilid-wasm/src/lib.rs @@ -6,14 +6,17 @@ extern crate alloc; use alloc::string::String; use alloc::sync::Arc; +use alloc::*; use core::any::{Any, TypeId}; use core::cell::RefCell; use futures_util::FutureExt; use js_sys::*; use lazy_static::*; -use log::*; use send_wrapper::*; use serde::*; +use tracing::*; +use tracing_subscriber::prelude::*; +use tracing_subscriber::*; use tracing_wasm::{WASMLayerConfigBuilder, *}; use veilid_core::xx::*; use veilid_core::*; @@ -29,8 +32,19 @@ pub fn setup() -> () { SETUP_ONCE.call_once(|| {}); } -// API Singleton +// Log filtering +fn logfilter, V: AsRef<[T]>>(metadata: &Metadata, ignore_list: V) -> bool { + // Skip filtered targets + !match (metadata.target(), ignore_list.as_ref()) { + (path, ignore) if !ignore.is_empty() => { + // Check that the module path does not match any ignore filters + ignore.iter().any(|v| path.starts_with(v.as_ref())) + } + _ => false, + } +} +// API Singleton lazy_static! { static ref VEILID_API: SendWrapper>> = SendWrapper::new(RefCell::new(None)); @@ -50,7 +64,6 @@ fn take_veilid_api() -> Result(val: T) -> String { serde_json::to_string(&val).expect("failed to serialize json value") } @@ -129,8 +142,7 @@ pub fn initialize_veilid_wasm() { #[wasm_bindgen()] pub fn configure_veilid_platform(platform_config: String) { - let platform_config = platform_config.into_opt_string(); - let platform_config: VeilidWASMConfig = veilid_core::deserialize_opt_json(platform_config) + let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config) .expect("failed to deserialize plaform config json"); // Set up subscriber and layers diff --git a/veilid-wasm/wasm_build.sh b/veilid-wasm/wasm_build.sh index 4fda8559..7d6b9978 100755 --- a/veilid-wasm/wasm_build.sh +++ b/veilid-wasm/wasm_build.sh @@ -3,6 +3,18 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" pushd $SCRIPTDIR &> /dev/null +if [ -f /usr/local/opt/llvm/bin/llvm-dwarfdump ]; then + DWARFDUMP=/usr/local/opt/llvm/bin/llvm-dwarfdump +elif [ -f /opt/homebrew/llvm/bin/llvm-dwarfdump ]; then + DWARFDUMP=/opt/homebrew/llvm/bin/llvm-dwarfdump +else + DWARFDUMP=`which llvm-dwarfdump` + if [[ "${DWARFDUMP}" == "" ]]; then + echo llvm-dwarfdump not found + fi +fi + + if [[ "$1" == "debug" ]]; then OUTPUTDIR=../target/wasm32-unknown-unknown/debug/pkg INPUTDIR=../target/wasm32-unknown-unknown/debug @@ -10,7 +22,7 @@ if [[ "$1" == "debug" ]]; then RUSTFLAGS="-O -g" cargo build --target wasm32-unknown-unknown mkdir -p $OUTPUTDIR wasm-bindgen --out-dir $OUTPUTDIR --target web --no-typescript --keep-debug --debug $INPUTDIR/veilid_wasm.wasm - ./wasm-sourcemap.py $OUTPUTDIR/veilid_wasm_bg.wasm -o $OUTPUTDIR/veilid_wasm_bg.wasm.map --dwarfdump `which llvm-dwarfdump` + ./wasm-sourcemap.py $OUTPUTDIR/veilid_wasm_bg.wasm -o $OUTPUTDIR/veilid_wasm_bg.wasm.map --dwarfdump $DWARFDUMP wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm else OUTPUTDIR=../target/wasm32-unknown-unknown/release/pkg