From 4eb4fefeb2d80cde4629a0db403d6fe25f8789c0 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 28 Oct 2025 12:22:26 -0500 Subject: [PATCH] Add a Makefile to make web builds more ergonomic Call with `make -f makefile_web` to produce a web root for serving. Use target "boids_web_root.tar" to bundle the files into a tarball. For... publishing... or something. The `wasm-server-runner` program seems to supply it's own index.html and is doing *something* regarding MIME types -- hosting a dev build of the Boids program results in the browser complaining about "" (empty string) being an invalid MIME type. I want my own index.html during testing, and I can't figure out why the MIME type info is wrong. I've decided to automate the web-root build process and serve it up with whatever webserver I have on hand. --- .gitignore | 1 + makefile_web | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 makefile_web diff --git a/.gitignore b/.gitignore index ea8c4bf7..c2b9385c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/out \ No newline at end of file diff --git a/makefile_web b/makefile_web new file mode 100644 index 00000000..1384642a --- /dev/null +++ b/makefile_web @@ -0,0 +1,32 @@ +.PHONY: clean full-clean web tarball + +web: out/boids-sim.js out/boids-sim.wasm out/index.html + +tarball: boids_web_root.tar + +boids_web_root.tar: out/boids-sim.js out/boids-sim.wasm out/index.html + tar -caf $@ $< + +target/wasm32-unknown-unknown/wasm-release/another-boids-in-rust.wasm: + cargo build --profile wasm-release --target wasm32-unknown-unknown + +out: + mkdir $@ + +# Both the JS and WASM files are generated by the wasm-bindgen call, so both +# get to be on the target half of this recipe. +out/boids-sim.js out/boids-sim.wasm: out target/wasm32-unknown-unknown/wasm-release/another-boids-in-rust.wasm + wasm-bindgen --no-typescript --target web --out-dir ./out --out-name boids-sim.wasm target/wasm32-unknown-unknown/wasm-release/another-boids-in-rust.wasm + +out/index.html: www/index.html + cp -a $< $@ + +# Clean the web build, but not the Cargo cache. Cargo handles it's own caching +# and I don't want to obliterate it all the time. +clean: + rm -rf out/ boids_web_root.tar + +# Delete everything, including the Cargo build cache. In case someone needs +# this, I guess. +full-clean: clean + cargo clean