Add init function to wasm-bindings crate and update dependencies (#33)

This commit is contained in:
ProTheory8
2021-03-19 22:57:18 +05:00
committed by GitHub
parent cf6c857846
commit f0e27dba6c
5 changed files with 34 additions and 99 deletions

View File

@@ -4,8 +4,6 @@ version = "0.1.0"
authors = ["Keavon Chambers <graphite@keavon.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "rlib"]
@@ -13,7 +11,7 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = "0.2.7"
wasm-bindgen = "0.2.72"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
@@ -21,16 +19,5 @@ wasm-bindgen = "0.2.7"
# code size when deploying.
console_error_panic_hook = { version = "0.1.6", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.5", optional = true }
[dev-dependencies]
wasm-bindgen-test = "0.3.13"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
wasm-bindgen-test = "0.3.22"

View File

@@ -2,17 +2,13 @@ mod utils;
use wasm_bindgen::prelude::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn greet() {
#[wasm_bindgen(start)]
pub fn init() {
utils::set_panic_hook();
alert("Hello, Graphite!");
}