Skip to content

Commit

Permalink
Switch to no-modules wasm-pack build, in preparation for using WASM with
Browse files Browse the repository at this point in the history
web workers. #23
  • Loading branch information
dabreegster committed Nov 17, 2022
1 parent cb0dff1 commit 7879dd2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

- name: Build web app
run: |
wasm-pack build --release --target web route-snapper
wasm-pack build --release --target no-modules route-snapper
mkdir -p publish/route-snapper
cp -Rv *.html *.geojson *.js *.css deps publish
Expand Down
2 changes: 1 addition & 1 deletion route-snapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]
crate-type = ["cdylib"]

[dependencies]
bincode = "1.3.1"
Expand Down
10 changes: 7 additions & 3 deletions route-snapper/lib.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import init, { JsRouteSnapper } from "./pkg/route_snapper.js";

await init();
// Weird workaround to make WASM work in web workers. See
// https://rustwasm.github.io/wasm-bindgen/examples/wasm-in-web-worker.html
const { JsRouteSnapper } = wasm_bindgen;
async function setup() {
await wasm_bindgen("./route-snapper/pkg/route_snapper_bg.wasm");
}
setup();

export class RouteSnapper {
constructor(app, mapBytes) {
Expand Down
3 changes: 3 additions & 0 deletions scheme.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<script src="deps/maplibre-gl.js"></script>
<script src="deps/geojson-extent.js"></script>
<script src="deps/mapbox-gl-draw.js"></script>
<!-- Weird ES module workaround -->
<script src="route-snapper/pkg/route_snapper.js"></script>

<script type="module">
import { App } from "./app.js";

Expand Down
2 changes: 1 addition & 1 deletion serve_locally.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

wasm-pack build --release --target web route-snapper && python3 -m http.server --directory .
wasm-pack build --release --target no-modules route-snapper && python3 -m http.server --directory .

0 comments on commit 7879dd2

Please sign in to comment.