Fixed wasm build with string error and warning
This commit is contained in:
parent
cc6b0c38db
commit
e7b88b96e1
@ -3,6 +3,9 @@ name = "wasmweb-sample"
|
||||
version = "0.1.0"
|
||||
authors = ["Sambo Chea <sombochea@cubetiqs.com>"]
|
||||
edition = "2018"
|
||||
description = "Just WASM Sample for CUBETIQ Solution"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/CUBETIQ/wasmweb-sample.git"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3"
|
||||
@ -39,4 +42,7 @@ wasm-bindgen-test = "0.3.13"
|
||||
|
||||
[profile.release]
|
||||
# Tell `rustc` to optimize for small code size.
|
||||
opt-level = "s"
|
||||
opt-level = "s"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = false
|
12
src/lib.rs
12
src/lib.rs
@ -1,4 +1,5 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use math;
|
||||
|
||||
extern crate web_sys;
|
||||
|
||||
@ -21,18 +22,13 @@ extern {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn sum(a: i32, b: i32) -> i32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn greet() {
|
||||
alert("Hey, CUBETIQ Solution!");
|
||||
pub fn greet() -> String {
|
||||
"Hey, CUBETIQ Solution!".into()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn just_sum() -> i32 {
|
||||
let sum = sum(100, 50);
|
||||
let sum = math::sum(100, 50);
|
||||
log(&format!("Just Sum {} + {} = {}", 100, 50, sum));
|
||||
return sum;
|
||||
}
|
||||
|
@ -2,5 +2,10 @@ use math;
|
||||
|
||||
fn main() {
|
||||
let sum = math::sum(1, 2);
|
||||
println!("Sum number {}", sum)
|
||||
println!("Sum number {}", sum);
|
||||
println!("Greetings, {}", welcome());
|
||||
}
|
||||
|
||||
fn welcome() -> String {
|
||||
return String::from("Hello, Sambo")
|
||||
}
|
14
www/index.ts
14
www/index.ts
@ -1,8 +1,8 @@
|
||||
// import * as wasm from "hello-wasm-pack";
|
||||
import * as wasm from "./../pkg/wasmweb_sample"
|
||||
|
||||
wasm.greet()
|
||||
wasm.log("[WEB] external logging...")
|
||||
|
||||
const sum = wasm.just_sum()
|
||||
console.log("Sum of number", sum)
|
||||
// import * as wasm from 'wasmweb-sample'
|
||||
//
|
||||
// wasm.log("[WEB] external logging...")
|
||||
//
|
||||
// const greeting = wasm.greet()
|
||||
// const sum = wasm.just_sum()
|
||||
// console.log("Sum of number", sum)
|
@ -33,8 +33,5 @@
|
||||
"webpack": "^4.29.3",
|
||||
"webpack-cli": "^3.1.0",
|
||||
"webpack-dev-server": "^3.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"wasmweb-sample": "file:../pkg"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user