Skip to content

Commit

Permalink
Fix the wasm2js example (#1750)
Browse files Browse the repository at this point in the history
This needed and update now that we're explicitly importing `*.wasm` to
import `*.js` instead. Additionally this was moved over to the `web`
target to avoid needing Webpack

Closes #1743
  • Loading branch information
alexcrichton committed Sep 3, 2019
1 parent 1f39a30 commit 4e19ead
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 47 deletions.
2 changes: 1 addition & 1 deletion examples/wasm2js/README.md
Expand Up @@ -14,4 +14,4 @@ $ ./build.sh

(or running the commands on Windows manually)

and then visiting http://localhost:8080 in a browser should run the example!
and then visiting http://localhost:8000 in a browser should run the example!
9 changes: 4 additions & 5 deletions examples/wasm2js/build.sh
Expand Up @@ -3,13 +3,12 @@
set -ex

# Compile our wasm module and run `wasm-bindgen`
wasm-pack build
wasm-pack build --target web

# Run the `wasm2js` tool from `binaryen`
wasm2js pkg/wasm2js_bg.wasm -o pkg/wasm2js_bg.js

# Move our original wasm out of the way to avoid cofusing Webpack.
mv pkg/wasm2js_bg.wasm pkg/wasm2js_bg.bak.wasm
# Update our JS shim to require the JS file instead
sed -i 's/wasm2js_bg.wasm/wasm2js_bg.js/' pkg/wasm2js.js

npm install
npm run serve
http
1 change: 1 addition & 0 deletions examples/wasm2js/index.html
Expand Up @@ -5,4 +5,5 @@
<body>
<p>Open up the developer console to see "Hello, World!"</p>
</body>
<script src=index.js type=module></script>
</html>
8 changes: 4 additions & 4 deletions examples/wasm2js/index.js
@@ -1,4 +1,4 @@
// Note that since we're not using `WebAssembly` we can do a synchronous import
// here!
import { run } from './pkg/wasm2js';
run();
// Import our JS shim and initialize it, executing the start function when it's
// ready.
import init from './pkg/wasm2js.js';
init();
13 changes: 0 additions & 13 deletions examples/wasm2js/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion examples/wasm2js/src/lib.rs
Expand Up @@ -7,7 +7,7 @@ extern "C" {
fn log(s: &str);
}

#[wasm_bindgen]
#[wasm_bindgen(start)]
pub fn run() {
log("Hello, World!");
}
23 changes: 0 additions & 23 deletions examples/wasm2js/webpack.config.js

This file was deleted.

0 comments on commit 4e19ead

Please sign in to comment.