This commit is contained in:
2020-05-21 00:43:45 +08:00
parent ac79156632
commit 6e11724316
6 changed files with 26 additions and 4 deletions

12
deno_run_wasm/run_wasm.ts Normal file
View File

@@ -0,0 +1,12 @@
const wasmCode = await Deno.readFile("./target/wasm32-unknown-unknown/debug/wasm_deno_example.wasm");
const wasmModule = new WebAssembly.Module(wasmCode);
const wasmInstance = new WebAssembly.Instance(wasmModule);
const {
square,
} = wasmInstance.exports;
console.log(square(1));
console.log(square(2));
console.log(square(3));
console.log(square(4));

View File

@@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

5
deno_run_wasm/wasm_sample/Cargo.lock generated Normal file
View File

@@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "warsam_sample"
version = "0.1.0"

View File

@@ -1,9 +1,12 @@
[package]
name = "warsam_sample"
name = "wasm_sample"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type =["cdylib"]
[dependencies]

View File

@@ -0,0 +1 @@
cargo build --target wasm32-unknown-unknown

View File

@@ -0,0 +1,4 @@
#[no_mangle]
pub extern "C" fn square(x: u32) -> u32 {
x * x
}