Files
another-boids-in-rust/makefile_web
Robert Garrett 0358935bf6 Group the WASM & JS targets so they're built once
https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html

The previous recipe told Make that each file could be produced by
running wasm-bindgen. The more correct expression is that *both* files
will be produced at the same time.

Now Make knows to only invoke the command one time to get both files if
either is out of date. Previously, multi-job builds (`-j2`) could build
the files twice -- one invocation for each out-of-date file.
2025-10-28 15:04:45 -05:00

36 lines
1.1 KiB
Plaintext

SRC_DIR = ./src
SRCS := $(wildcard $(SRC_DIR)/**)
.PHONY: clean full-clean web tarball
web: out/boids.js out/boids_bg.wasm out/index.html
tarball: boids_web_root.tar
boids_web_root.tar: out/boids.js out/boids_bg.wasm out/index.html
tar -caf $@ $<
target/wasm32-unknown-unknown/wasm-release/another-boids-in-rust.wasm: $(SRCS)
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.js out/boids_bg.wasm &: target/wasm32-unknown-unknown/wasm-release/another-boids-in-rust.wasm | out
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name boids 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