Skip to content

Instantly share code, notes, and snippets.

@apiraino
Created November 27, 2017 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apiraino/ecaf05e427746bfdc7daa1f7fa37c50b to your computer and use it in GitHub Desktop.
Save apiraino/ecaf05e427746bfdc7daa1f7fa37c50b to your computer and use it in GitHub Desktop.
### install deps
Reference here: https://medium.com/@ianjsikes/get-started-with-rust-webassembly-and-webpack-58d28e219635
### create a binary rust project
### write a public function
### compile Rust code targeting WASM
wargo build (i.e. cargo build --target=wasm32-unknown-emscripten)
### test binary
cd target/wasm32-unknown-emscripten/debug/
node meow.js
### get all boiletplate to compile using NodeJS
create webpack.config.js
create package .json
create src/index.js (that includes wasm code)
create index.html (that includes build/bundle.js)
### compile and run using NodeJS
```
npm install
npm run compile
npm run serve
```
# wasm-gc
```
$ rustup update nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
$ rustc +nightly --target wasm32-unknown-unknown -O .\add.rs --crate-type=cdylib
$ cargo install --git https://github.com/alexcrichton/wasm-gc
$ wasm-gc .\add.wasm small-add.wasm
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment