Simple test project that sets up a hybrid cargo crate with a vite project

chore: strip wasm32 version from native version

Signed-off-by: @gm112 <740416+gm112@users.noreply.github.com>

@gm112 421c28ff 1db52e96

+36 -8
+3 -1
Cargo.toml
··· 3 3 resolver = "3" 4 4 5 5 [profile.release] 6 - opt-level = "s" 6 + opt-level = "z" 7 7 panic = "abort" 8 8 lto = true 9 9 codegen-units = 1 10 + strip = true 11 +
+8
com-gm112-rust-testlibrary/.cargo/config.toml
··· 1 + 2 + [target.wasm32-unknown-unknown] 3 + rustflags = [ 4 + "-C", "target-feature=+atomics,+bulk-memory,+mutable-globals" 5 + ] 6 + 7 + [profile.release] 8 + strip = false
+1 -1
com-gm112-rust-testlibrary/Cargo.toml
··· 13 13 [dependencies] 14 14 console_error_panic_hook = { version = "0.1.7", optional = true } 15 15 wasm-bindgen = "0.2.104" 16 - wee_alloc = "0.4.5" 16 + wee_alloc = { version = "0.4.5", default-features = false } 17 17 18 18 [dev-dependencies] 19 19 wasm-bindgen-test = "0.3.54"
+22 -6
com-gm112-rust-testlibrary/src/lib.rs
··· 1 + #[cfg(target_arch = "wasm32")] 1 2 use wasm_bindgen::prelude::*; 3 + #[cfg(target_arch = "wasm32")] 2 4 use wee_alloc::WeeAlloc; 3 5 6 + #[cfg(target_arch = "wasm32")] 4 7 #[global_allocator] 5 8 static ALLOC: WeeAlloc = WeeAlloc::INIT; 6 9 7 10 #[cfg(feature = "console_error_panic_hook")] 11 + #[cfg(target_arch = "wasm32")] 8 12 #[wasm_bindgen(start)] 9 13 pub fn set_panic_hook() { 10 14 console_error_panic_hook::set_once(); ··· 12 16 13 17 /// Adds two numbers. 14 18 /// 15 - /// @example <caption>Add two numbers in Rust</caption> 16 - /// ```rust 17 - /// // In Rust: 18 - /// use com_gm112_rust_testlibrary::add; 19 - /// assert_eq!(add(1, 2).unwrap(), 3); 20 - /// ``` 21 19 /// @example <caption>Add two numbers in TypeScript</caption> 22 20 /// ```typescript 23 21 /// // In TypeScript: 24 22 /// import { add } from 'com-gm112-rust-testlibrary'; 25 23 /// console.log(add(1, 2)); // 3 26 24 /// ``` 25 + #[cfg(target_arch = "wasm32")] 27 26 #[wasm_bindgen] 28 27 pub fn add(a: i32, b: i32) -> Result<i32, JsValue> { 28 + internal_add(a, b).map_err(|e| JsValue::from(e)) 29 + } 30 + 31 + /// Adds two numbers. 32 + /// 33 + /// @example <caption>Add two numbers in Rust</caption> 34 + /// ```rust 35 + /// // In Rust: 36 + /// use com_gm112_rust_testlibrary::add; 37 + /// assert_eq!(add(1, 2).unwrap(), 3); 38 + /// ``` 39 + #[cfg(not(target_arch = "wasm32"))] 40 + pub fn add(a: i32, b: i32) -> Result<i32, i32> { 41 + internal_add(a, b) 42 + } 43 + 44 + fn internal_add(a: i32, b: i32) -> Result<i32, i32> { 29 45 Ok(a + b) 30 46 }
+2
com-gm112-rust-testproject/.cargo/config.toml
··· 1 + [profile.release] 2 + strip = true