6 Commits

Author SHA1 Message Date
84d93d496a Remove Linux-specific deps from web build
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 6m24s
The Alsa and Udev system dependencies are only required on Linux. The
WASM/WASI build doesn't use them, so they don't need to exist in the
build container.
2025-11-08 12:10:42 -06:00
4a9d252691 Update Dockerfile, copy everything, use makefile
I have figured out the `.dockerignore` file so I don't have to do manual
context size management like before.

The Dockerfile now uses the Makefile to ensure image builds contain the
same thing non-image builds would.
2025-11-08 12:08:45 -06:00
3c9a9a7d9d Add some CSS 2025-11-08 12:07:30 -06:00
010cbd6d4b Add an install target 2025-11-06 14:18:13 -06:00
918992702f Add standalone & bundle-able build variants
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 8m8s
Now there are build targets for producing a version that can be served
as-is, and another that can be included as a page in a larger site.
2025-11-06 10:48:06 -06:00
c8c64e4d22 Place Makefile 'configurables' up top
Variables that a package consumer might want to adjust should be placed
at the top of the file so they are immediately visible. Any constants
shall live below those (just the SRC folder, really).
2025-11-06 10:26:35 -06:00
3 changed files with 48 additions and 23 deletions

View File

@@ -1,22 +1,11 @@
FROM rust:1.89 AS builder
RUN apt-get update
RUN apt-get install -y --no-install-recommends libasound2-dev libudev-dev
RUN rustup target add wasm32-unknown-unknown
RUN cargo install --locked wasm-bindgen-cli
# Copy in only the parts we care about. This is to prevent Docker from re-
# running some steps because unimportant files changed (e.g.: the .git/ folder)
COPY src/ ./src
COPY Cargo.toml ./Cargo.toml
# WARN: The lockfile doesn't exist in the repo. You will have to create it
# before building the Docker image (i.e.: run `cargo update` first)
COPY Cargo.lock ./Cargo.lock
COPY www/ ./www
COPY Makefile ./Makefile
COPY . .
# Oops. There's no text output in the Docker build command line (it still works, though)
RUN make
RUN make -j
FROM busybox:musl
RUN mkdir -p /var/www

View File

@@ -3,22 +3,32 @@
## 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
SRC_DIR = ./src
SRCS := $(wildcard $(SRC_DIR)/**)
web: out/asteroids.js out/asteroids_bg.wasm out/index.html
.PHONY: clean full-clean tarball tarball-standalone web web-standalone
# "Standalone" version. It includes an index.html to serve as-is
web-standalone: out/asteroids.js out/asteroids_bg.wasm out/index.html
# "Bundle-able" version. It has a page, but no index.html. Consumers are
# expected to provide their own index.html and link to this page.
web: out/asteroids.js out/asteroids_bg.wasm out/asteroids.html
tarball: asteroids_web_root.tar
asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm out/index.html
tarball_standalone: asteroids_web_root_standalone.tar
asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm out/asteroids.html
tar -caf $@ $^
asteroids_web_root_standalone.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
@@ -32,15 +42,30 @@ out:
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
# Copies the index page to the output dir.
out/index.html: www/index.html
cp -a $< $@
rm -f out/boids.html
# Like `out/index.html`, but renames the page for use in a larger site.
out/asteroids.html: www/index.html
cp -a $< $@
rm -f out/index.html
# 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
rm -rf out/ asteroids_web_root.tar asteroids_web_root_standalone.tar
# Delete everything, including the Cargo build cache. In case someone needs
# this, I guess.
full-clean: clean
cargo clean
# Installation goal. It's meant to be a helper utility for moving the built
# output into the web root. Only supports the "bundle-able" mode.
install: web
install -dm0755 $(DESTDIR)
install -m0644 out/asteroids.js $(DESTDIR)/
install -m0644 out/asteroids_bg.wasm $(DESTDIR)/
install -m0644 out/asteroids.html $(DESTDIR)/

View File

@@ -2,15 +2,25 @@
<html lang="en">
<head>
<style>
body {
background-color: hsl(200, 3%, 65%);
}
h1 {
color: hsl(200, 3%, 90%);
background-color: hsl(195, 5%, 17%);
text-align: center;
margin: auto;
padding: 0.5em;
}
canvas {
padding-left: 0;
padding-right: 0;
margin-top: 1em;
margin-left: auto;
margin-right: auto;
display: block;
outline-color: hsl(200, 7%, 50%);
outline-style: outset;
border-radius: 8px;
background-color: rgb(40%, 40%, 40%);
}
main {
margin-left: auto;
@@ -18,11 +28,12 @@
width: 70%;
}
table {
margin-bottom: 10px;
border-collapse: collapse;
}
th, td {
border: 1px solid;
padding: 2px 4px;
padding: 0.1em 0.3em;
}
</style>
</head>