tammy's blog about
AI alignment,
utopia,
anthropics,
and more;
i like to keep my software stacks simple.
to write wasm modules in rust, i use a relatively simple template, which only requires the wasm-bindgen
utility (cargo install -f wasm-bindgen-cli
) and the wasm32-unknown-unknown
toolchain (rustup target add wasm32-unknown-unknown
).
the Cargo.toml
of the project looks like this; in it, the crate-type = ["cdylib"]
part is the essential thing needed to build a wasm module.
there is a make.sh
script, which compiles the project, calls wasm-bindgen
, and cobbles together two html files: a light.html
which reloads fast (good for development and debugging), but depends on js/wasm.js
and js/wasm_bg.wasm
, as well as a standalone page.html
which doesn't depend on any external files, because it embeds wasm.js
verbatim and wasm_bg.wasm
encoded in base64 (good for distribution).
after that, it starts a python2 -m SimpleHTTPServer
serving the light.html
file at http://localhost:8000/light.html (unlike page.html
, it unfortunately can't be used with the file://
scheme because of CORS security restrictions).
i also use a script called cw
which requires cargo watch
(cargo install cargo-watch
) and calls make.sh
each time the project's source code is modified.
finally, to cobble together the html documents, make.sh
uses a head.html
and tail.html
, which are meant to remain static.
the files from the template can be browsed here or downloaded as a tarball.
unless otherwise specified on individual pages, all posts on this website are licensed under the CC_-1 license.
unless explicitely mentioned, all content on this site was created by me; not by others nor AI.