Skip to content

Commit 98a0ae3

Browse files
committed
Add wasm-lib from template
1 parent 298f65c commit 98a0ae3

File tree

6 files changed

+271
-0
lines changed

6 files changed

+271
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ yarn-error.log*
3535
/tests/extension.spec.ts-snapshots/*darwin*
3636

3737
.env*
38+
39+
# rust
40+
src/wasm-lib/target
41+
src/wasm-lib/bindings
42+
src/wasm-lib/kcl/bindings
43+
public/wasm_lib_bg.wasm
44+
src/wasm-lib/lcov.info
45+
src/wasm-lib/grackle/test_json_output

src/wasm-lib/Cargo.lock

Lines changed: 197 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/wasm-lib/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "wasm-lib"
3+
version = "0.1.0"
4+
edition = "2021"
5+
repository = "https://github.com/KittyCAD/diff-viewer-extension"
6+
rust-version = "1.73"
7+
8+
[lib]
9+
crate-type = ["cdylib", "rlib"]
10+
11+
[features]
12+
default = ["console_error_panic_hook"]
13+
14+
[dependencies]
15+
# kcl-lib = "0.1.51"
16+
# kittycad = { version = "0.3.0", features = ["clap", "tabled", "requests", "retry"] }
17+
wasm-bindgen = "0.2.84"
18+
19+
# The `console_error_panic_hook` crate provides better debugging of panics by
20+
# logging them with `console.error`. This is great for development, but requires
21+
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
22+
# code size when deploying.
23+
console_error_panic_hook = { version = "0.1.7", optional = true }
24+
25+
[dev-dependencies]
26+
wasm-bindgen-test = "0.3.34"
27+
28+
[profile.release]
29+
# Tell `rustc` to optimize for small code size.
30+
opt-level = "s"

src/wasm-lib/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mod utils;
2+
3+
use wasm_bindgen::prelude::*;
4+
5+
#[wasm_bindgen]
6+
extern "C" {
7+
fn alert(s: &str);
8+
}
9+
10+
#[wasm_bindgen]
11+
pub fn greet() {
12+
alert("Hello, wasm-lib!");
13+
}

src/wasm-lib/src/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub fn set_panic_hook() {
2+
// When the `console_error_panic_hook` feature is enabled, we can call the
3+
// `set_panic_hook` function at least once during initialization, and then
4+
// we will get better error messages if our code ever panics.
5+
//
6+
// For more details see
7+
// https://github.com/rustwasm/console_error_panic_hook#readme
8+
#[cfg(feature = "console_error_panic_hook")]
9+
console_error_panic_hook::set_once();
10+
}

src/wasm-lib/tests/web.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Test suite for the Web and headless browsers.
2+
3+
#![cfg(target_arch = "wasm32")]
4+
5+
extern crate wasm_bindgen_test;
6+
use wasm_bindgen_test::*;
7+
8+
wasm_bindgen_test_configure!(run_in_browser);
9+
10+
#[wasm_bindgen_test]
11+
fn pass() {
12+
assert_eq!(1 + 1, 2);
13+
}

0 commit comments

Comments
 (0)