wasm fixes
This commit is contained in:
		
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -5331,6 +5331,7 @@ dependencies = [
 | 
				
			|||||||
 "send_wrapper 0.6.0",
 | 
					 "send_wrapper 0.6.0",
 | 
				
			||||||
 "serde 1.0.137",
 | 
					 "serde 1.0.137",
 | 
				
			||||||
 "serde_json",
 | 
					 "serde_json",
 | 
				
			||||||
 | 
					 "tracing",
 | 
				
			||||||
 "tracing-subscriber",
 | 
					 "tracing-subscriber",
 | 
				
			||||||
 "tracing-wasm",
 | 
					 "tracing-wasm",
 | 
				
			||||||
 "veilid-core",
 | 
					 "veilid-core",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@ if [ ! "$(uname)" == "Darwin" ]; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# install targets
 | 
					# 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
 | 
					# install cargo packages
 | 
				
			||||||
cargo install wasm-bindgen-cli
 | 
					cargo install wasm-bindgen-cli
 | 
				
			||||||
@@ -50,5 +50,5 @@ if [ "$BREW_USER" == "" ]; then
 | 
				
			|||||||
        BREW_USER=`whoami`
 | 
					        BREW_USER=`whoami`
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
sudo -H -u $BREW_USER brew install capnp cmake
 | 
					sudo -H -u $BREW_USER brew install capnp cmake wabt llvm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,7 @@ crate-type = ["cdylib", "rlib"]
 | 
				
			|||||||
wasm-bindgen = { version = "^0", features = ["serde-serialize"] }
 | 
					wasm-bindgen = { version = "^0", features = ["serde-serialize"] }
 | 
				
			||||||
console_error_panic_hook = "^0"
 | 
					console_error_panic_hook = "^0"
 | 
				
			||||||
wee_alloc = "^0"
 | 
					wee_alloc = "^0"
 | 
				
			||||||
 | 
					tracing = { version = "^0", features = ["log", "attributes"] }
 | 
				
			||||||
tracing-wasm = "^0"
 | 
					tracing-wasm = "^0"
 | 
				
			||||||
tracing-subscriber = "^0"
 | 
					tracing-subscriber = "^0"
 | 
				
			||||||
veilid-core = { path = "../veilid-core" }
 | 
					veilid-core = { path = "../veilid-core" }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,14 +6,17 @@
 | 
				
			|||||||
extern crate alloc;
 | 
					extern crate alloc;
 | 
				
			||||||
use alloc::string::String;
 | 
					use alloc::string::String;
 | 
				
			||||||
use alloc::sync::Arc;
 | 
					use alloc::sync::Arc;
 | 
				
			||||||
 | 
					use alloc::*;
 | 
				
			||||||
use core::any::{Any, TypeId};
 | 
					use core::any::{Any, TypeId};
 | 
				
			||||||
use core::cell::RefCell;
 | 
					use core::cell::RefCell;
 | 
				
			||||||
use futures_util::FutureExt;
 | 
					use futures_util::FutureExt;
 | 
				
			||||||
use js_sys::*;
 | 
					use js_sys::*;
 | 
				
			||||||
use lazy_static::*;
 | 
					use lazy_static::*;
 | 
				
			||||||
use log::*;
 | 
					 | 
				
			||||||
use send_wrapper::*;
 | 
					use send_wrapper::*;
 | 
				
			||||||
use serde::*;
 | 
					use serde::*;
 | 
				
			||||||
 | 
					use tracing::*;
 | 
				
			||||||
 | 
					use tracing_subscriber::prelude::*;
 | 
				
			||||||
 | 
					use tracing_subscriber::*;
 | 
				
			||||||
use tracing_wasm::{WASMLayerConfigBuilder, *};
 | 
					use tracing_wasm::{WASMLayerConfigBuilder, *};
 | 
				
			||||||
use veilid_core::xx::*;
 | 
					use veilid_core::xx::*;
 | 
				
			||||||
use veilid_core::*;
 | 
					use veilid_core::*;
 | 
				
			||||||
@@ -29,8 +32,19 @@ pub fn setup() -> () {
 | 
				
			|||||||
    SETUP_ONCE.call_once(|| {});
 | 
					    SETUP_ONCE.call_once(|| {});
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// API Singleton
 | 
					// Log filtering
 | 
				
			||||||
 | 
					fn logfilter<T: AsRef<str>, 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! {
 | 
					lazy_static! {
 | 
				
			||||||
    static ref VEILID_API: SendWrapper<RefCell<Option<veilid_core::VeilidAPI>>> =
 | 
					    static ref VEILID_API: SendWrapper<RefCell<Option<veilid_core::VeilidAPI>>> =
 | 
				
			||||||
        SendWrapper::new(RefCell::new(None));
 | 
					        SendWrapper::new(RefCell::new(None));
 | 
				
			||||||
@@ -50,7 +64,6 @@ fn take_veilid_api() -> Result<veilid_core::VeilidAPI, veilid_core::VeilidAPIErr
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// JSON Marshalling
 | 
					// JSON Marshalling
 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn serialize_json<T: Serialize>(val: T) -> String {
 | 
					pub fn serialize_json<T: Serialize>(val: T) -> String {
 | 
				
			||||||
    serde_json::to_string(&val).expect("failed to serialize json value")
 | 
					    serde_json::to_string(&val).expect("failed to serialize json value")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -129,8 +142,7 @@ pub fn initialize_veilid_wasm() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#[wasm_bindgen()]
 | 
					#[wasm_bindgen()]
 | 
				
			||||||
pub fn configure_veilid_platform(platform_config: String) {
 | 
					pub fn configure_veilid_platform(platform_config: String) {
 | 
				
			||||||
    let platform_config = platform_config.into_opt_string();
 | 
					    let platform_config: VeilidWASMConfig = veilid_core::deserialize_json(&platform_config)
 | 
				
			||||||
    let platform_config: VeilidWASMConfig = veilid_core::deserialize_opt_json(platform_config)
 | 
					 | 
				
			||||||
        .expect("failed to deserialize plaform config json");
 | 
					        .expect("failed to deserialize plaform config json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Set up subscriber and layers
 | 
					    // Set up subscriber and layers
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,18 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
pushd $SCRIPTDIR &> /dev/null
 | 
					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  
 | 
					if [[ "$1" == "debug" ]]; then  
 | 
				
			||||||
    OUTPUTDIR=../target/wasm32-unknown-unknown/debug/pkg
 | 
					    OUTPUTDIR=../target/wasm32-unknown-unknown/debug/pkg
 | 
				
			||||||
    INPUTDIR=../target/wasm32-unknown-unknown/debug
 | 
					    INPUTDIR=../target/wasm32-unknown-unknown/debug
 | 
				
			||||||
@@ -10,7 +22,7 @@ if [[ "$1" == "debug" ]]; then
 | 
				
			|||||||
    RUSTFLAGS="-O -g" cargo build --target wasm32-unknown-unknown
 | 
					    RUSTFLAGS="-O -g" cargo build --target wasm32-unknown-unknown
 | 
				
			||||||
    mkdir -p $OUTPUTDIR
 | 
					    mkdir -p $OUTPUTDIR
 | 
				
			||||||
    wasm-bindgen --out-dir $OUTPUTDIR --target web --no-typescript --keep-debug --debug $INPUTDIR/veilid_wasm.wasm
 | 
					    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
 | 
					    wasm-strip $OUTPUTDIR/veilid_wasm_bg.wasm
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
    OUTPUTDIR=../target/wasm32-unknown-unknown/release/pkg
 | 
					    OUTPUTDIR=../target/wasm32-unknown-unknown/release/pkg
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user