init: it builds

This commit is contained in:
鲁树人
2024-09-02 21:01:19 +01:00
commit ff11a8186e
23 changed files with 1073 additions and 0 deletions

6
um_wasm/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log

28
um_wasm/Cargo.toml Normal file
View File

@@ -0,0 +1,28 @@
[package]
name = "um_wasm"
version = "0.1.0"
authors = ["鲁树人 <lu.shuren@um-react.app>"]
edition = "2018"
[lib]
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = "0.2.84"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }
umc_kuwo = { path = "../um_crypto/kuwo" }
[dev-dependencies]
wasm-bindgen-test = "0.3.34"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

3
um_wasm/README.md Normal file
View File

@@ -0,0 +1,3 @@
# um_wasm
加解密算法 Rust ❤️ WebAssembly 计划。

19
um_wasm/src/lib.rs Normal file
View File

@@ -0,0 +1,19 @@
mod utils;
use utils::set_panic_hook;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn init() {
set_panic_hook();
}
#[wasm_bindgen]
pub fn greet() {
alert("hello world!");
}

10
um_wasm/src/utils.rs Normal file
View File

@@ -0,0 +1,10 @@
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}

13
um_wasm/tests/web.rs Normal file
View File

@@ -0,0 +1,13 @@
//! Test suite for the Web and headless browsers.
#![cfg(target_arch = "wasm32")]
extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn pass() {
assert_eq!(1 + 1, 2);
}