Skip to content

Commit 35a0330

Browse files
committed
preload scripts for wasm
1 parent 6fd707e commit 35a0330

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

.github/workflows/wasm.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ jobs:
4343
- name: Build WASM app
4444
run: |
4545
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
46-
export RUSTUP_TOOLCHAIN=nightly
47-
wasm-pack build --out-dir www/pkg --target web --release --no-default-features --features "wasm-draw"
48-
wasm-opt -O3 --enable-bulk-memory --enable-nontrapping-float-to-int -o www/pkg/kalc_plot_bg.wasm www/pkg/kalc_plot_bg.wasm
46+
cd www
47+
bash start.sh
4948
5049
- name: Copy site files to output
5150
run: |

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/target
22
/www/pkg/
33
/bin
4-
/www/node_modules
5-
/www/dist
4+
/www/index.html

window.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const canvas = document.getElementById('canvas');
22
const ctx = canvas.getContext("2d", {desynchronized: true, alpha: false});
3+
ctx.font = "18px monospace";
34
export function draw(slice, width) {
45
const clamped = new Uint8ClampedArray(slice);
56
const height = clamped.length / (width * 4);

www/index.html renamed to www/index

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<link rel="modulepreload" href="pkg/kalc_plot.js">
5+
<link rel="modulepreload" href="pkg/snippets/@@KALC@@/window.js">
6+
<link rel="modulepreload" href="pkg/snippets/@@RUPL@@/painter.js">
7+
<link rel="preload" href="favicon.ico" as="image">
8+
<link rel="preload" href="pkg/kalc_plot_bg.wasm" as="fetch" type="application/wasm" crossorigin>
49
<meta charset="utf-8">
510
<title>kalc plot</title>
611
<style>

www/start.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set -e
2+
set -x
3+
export RUSTUP_TOOLCHAIN=nightly
4+
wasm-pack build --out-dir www/pkg --target web --release --no-default-features --features "wasm-draw"
5+
wasm-opt -O3 --enable-bulk-memory --enable-nontrapping-float-to-int -o pkg/kalc_plot_bg.wasm pkg/kalc_plot_bg.wasm
6+
cp index index.html
7+
sed -i "s/@@KALC@@/$(ls --color=never -d ./pkg/snippets/kalc-plot-*|sed 's@.*/@@')/" index.html
8+
sed -i "s/@@RUPL@@/$(ls --color=never -d ./pkg/snippets/rupl-*|sed 's@.*/@@')/" index.html
9+
if [ $# -ne 0 ]; then
10+
python3 -m http.server 8080
11+
fi

0 commit comments

Comments
 (0)