Add a Makefile to automate the web build proc
This is also copied from my Boids project, just like the HTML page was.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
/out
|
||||
46
Makefile
Normal file
46
Makefile
Normal file
@@ -0,0 +1,46 @@
|
||||
##
|
||||
## This Makefile exists to produce WASM builds.
|
||||
## Do not use it if that isn't your goal!
|
||||
##
|
||||
|
||||
SRC_DIR = ./src
|
||||
SRCS := $(wildcard $(SRC_DIR)/**)
|
||||
|
||||
# Patch these to select a different build profile or target
|
||||
# The target shouldn't change any time soon. WASM64, I guess. Other targets
|
||||
# aren't aimed at the web, so you shouldn't be using this makefile.
|
||||
CARGO_TARGET := wasm32-unknown-unknown
|
||||
CARGO_PROFILE := tiny
|
||||
|
||||
.PHONY: clean full-clean web tarball
|
||||
|
||||
web: out/asteroids.js out/asteroids_bg.wasm out/index.html
|
||||
|
||||
tarball: asteroids_web_root.tar
|
||||
|
||||
asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm out/index.html
|
||||
tar -caf $@ $^
|
||||
|
||||
target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm: $(SRCS) Cargo.lock Cargo.toml
|
||||
cargo build --profile $(CARGO_PROFILE) --target $(CARGO_TARGET)
|
||||
|
||||
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/asteroids.js out/asteroids_bg.wasm &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm | out
|
||||
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name asteroids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.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/ asteroids_web_root.tar
|
||||
|
||||
# Delete everything, including the Cargo build cache. In case someone needs
|
||||
# this, I guess.
|
||||
full-clean: clean
|
||||
cargo clean
|
||||
Reference in New Issue
Block a user