feat(users/kranzes): add wasm-hello-world
This can be used as a reference for how to build a wasm project with crate2nix. Change-Id: Ib4d0db6bf24d8f1dec4734d5f1e8de19212a54cd Reviewed-on: https://cl.tvl.fyi/c/depot/+/11859 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
4b2f3c5454
commit
7f8da5e6a9
7 changed files with 1262 additions and 0 deletions
19
users/kranzes/wasm-hello-world/src/index.html
Normal file
19
users/kranzes/wasm-hello-world/src/index.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
|
||||
</head>
|
||||
<body>
|
||||
<script type="module">
|
||||
import init, { hello_world } from './wasm_hello_world.js';
|
||||
|
||||
async function run() {
|
||||
await init();
|
||||
|
||||
hello_world();
|
||||
}
|
||||
|
||||
run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
11
users/kranzes/wasm-hello-world/src/lib.rs
Normal file
11
users/kranzes/wasm-hello-world/src/lib.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
fn alert(s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn hello_world() {
|
||||
alert("Hello World!");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue