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"
|
version = "0.1.0"
|
||||||
authors = ["Sambo Chea <sombochea@cubetiqs.com>"]
|
authors = ["Sambo Chea <sombochea@cubetiqs.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
description = "Just WASM Sample for CUBETIQ Solution"
|
||||||
|
license = "MIT"
|
||||||
|
repository = "https://github.com/CUBETIQ/wasmweb-sample.git"
|
||||||
|
|
||||||
[dependencies.web-sys]
|
[dependencies.web-sys]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
@ -40,3 +43,6 @@ wasm-bindgen-test = "0.3.13"
|
|||||||
[profile.release]
|
[profile.release]
|
||||||
# Tell `rustc` to optimize for small code size.
|
# 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 wasm_bindgen::prelude::*;
|
||||||
|
use math;
|
||||||
|
|
||||||
extern crate web_sys;
|
extern crate web_sys;
|
||||||
|
|
||||||
@ -21,18 +22,13 @@ extern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
pub fn greet() -> String {
|
||||||
fn sum(a: i32, b: i32) -> i32;
|
"Hey, CUBETIQ Solution!".into()
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn greet() {
|
|
||||||
alert("Hey, CUBETIQ Solution!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn just_sum() -> i32 {
|
pub fn just_sum() -> i32 {
|
||||||
let sum = sum(100, 50);
|
let sum = math::sum(100, 50);
|
||||||
log(&format!("Just Sum {} + {} = {}", 100, 50, sum));
|
log(&format!("Just Sum {} + {} = {}", 100, 50, sum));
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,10 @@ use math;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sum = math::sum(1, 2);
|
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 "hello-wasm-pack";
|
||||||
import * as wasm from "./../pkg/wasmweb_sample"
|
// import * as wasm from 'wasmweb-sample'
|
||||||
|
//
|
||||||
wasm.greet()
|
// wasm.log("[WEB] external logging...")
|
||||||
wasm.log("[WEB] external logging...")
|
//
|
||||||
|
// const greeting = wasm.greet()
|
||||||
const sum = wasm.just_sum()
|
// const sum = wasm.just_sum()
|
||||||
console.log("Sum of number", sum)
|
// console.log("Sum of number", sum)
|
@ -33,8 +33,5 @@
|
|||||||
"webpack": "^4.29.3",
|
"webpack": "^4.29.3",
|
||||||
"webpack-cli": "^3.1.0",
|
"webpack-cli": "^3.1.0",
|
||||||
"webpack-dev-server": "^3.1.5"
|
"webpack-dev-server": "^3.1.5"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"wasmweb-sample": "file:../pkg"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user