19 Commits

Author SHA1 Message Date
8346527d05 Release v0.6.0
All checks were successful
check / stable / fmt (push) Successful in 20s
check / nightly / doc (push) Successful in 2m21s
check / ubuntu / stable / features (push) Successful in 2m25s
check / ubuntu / 1.87.0 (push) Successful in 2m19s
2025-11-15 15:15:01 -06:00
6329d000f5 Use compressed WASM for even smaller webroot size
All checks were successful
check / stable / fmt (push) Successful in 21s
check / nightly / doc (push) Successful in 2m24s
check / ubuntu / stable / features (push) Successful in 2m27s
check / ubuntu / 1.87.0 (push) Successful in 2m18s
2025-11-15 15:14:20 -06:00
46892ec32c Fix: Syntax errors in README.md
Some checks failed
check / nightly / doc (push) Has been cancelled
check / ubuntu / stable / features (push) Has been cancelled
check / ubuntu / 1.87.0 (push) Has been cancelled
check / stable / fmt (push) Has been cancelled
2025-11-08 11:28:43 -06:00
f6c6f26b8b Update CI, the MSRV is 1.87
Some checks failed
check / stable / fmt (push) Successful in 21s
check / nightly / doc (push) Successful in 2m19s
check / ubuntu / stable / features (push) Successful in 2m26s
check / ubuntu / 1.87.0 (push) Has been cancelled
I really should have fixed this forever ago and just didn't. Good thing
nobody uses this program and it doesn't matter :p
2025-11-08 11:19:15 -06:00
9f8598c794 Drop CI semver check, this isn't a library
Semver checks only make sense for things that have a public interface.
While an application technically does, these semver checks are for the
Rust API not the GUI shape or something. It's for checking that a
library upholds it's semver promise.

This is not a library, so these checks don't make sense.
2025-11-08 11:14:27 -06:00
b64771f3fc Drop CI cargo-clippy check, can't run on Gitea
The Reviewdog tool hits GitHub API endpoints that don't have an
equivalent on Gitea.
2025-11-08 11:11:15 -06:00
d1941217c4 Release v0.5.0
Some checks failed
check / stable / fmt (push) Successful in 21s
check / beta / clippy (push) Failing after 1m15s
check / semver (push) Has been cancelled
check / nightly / doc (push) Has been cancelled
check / ubuntu / stable / features (push) Has been cancelled
check / ubuntu / 1.79.0 (push) Has been cancelled
check / stable / clippy (push) Has been cancelled
2025-11-08 11:07:04 -06:00
ba5183b30d Remove bogus dependencies from build container
These are only required for Linux builds, not WASM/WASI builds.
2025-11-08 10:59:30 -06:00
3e3bbd973f Update Dockerfile to use the new Make-based build
I'm going to run into consistency problems at some point, so I'm going
to get ahead of that by updating the container build process.
2025-11-08 10:58:48 -06:00
5abe894354 Add a bunch of CSS
Some checks failed
check / beta / clippy (push) Has been cancelled
check / stable / clippy (push) Has been cancelled
check / semver (push) Has been cancelled
check / nightly / doc (push) Has been cancelled
check / ubuntu / stable / features (push) Has been cancelled
check / ubuntu / 1.79.0 (push) Has been cancelled
check / stable / fmt (push) Has been cancelled
It's not amazing work, but now there's *something.*
2025-11-08 10:37:34 -06:00
86483497e9 Add an install target 2025-11-06 14:18:18 -06:00
3f6a4ae532 Set charset & viewport meta tags 2025-11-06 13:24:11 -06:00
7a5148dc74 Update the README with new web build variant info 2025-11-06 12:19:26 -06:00
8d4b033922 Add the tarball-standalone recipe(s)
Some checks failed
check / stable / fmt (push) Successful in 21s
check / beta / clippy (push) Failing after 54s
check / stable / clippy (push) Failing after 49s
check / semver (push) Failing after 5m25s
check / nightly / doc (push) Successful in 2m22s
check / ubuntu / stable / features (push) Successful in 2m32s
check / ubuntu / 1.79.0 (push) Failing after 26s
I forgot to put this in when I added the phony target. Oops.
2025-11-06 10:46:13 -06:00
0c915b025e HTML-installing targets remove the other one
This is actually a build configuration task, but I don't have a tool to
do that (no `./configure.sh` to run!).

To work around this, I'll just have each of the html-installing targets
install their own and remove the other. That way back-to-back builds
don't accidentally contaminate each other. The WASM and JS files are
identical, so they don't need this treatment.
2025-11-06 10:22:44 -06:00
15a1d5c6de New build variants: "standalone" and "bundle-able"
The `web-standalone` target does what the old `web` target did: Produce
the WASM, JS, and an index.html so the output can be served up directly.

The new `web` target renames the "index.html" to "boids.html" so it can
be used as a submodule/subpage in a larger website build.
2025-11-06 10:20:30 -06:00
e7e5337f22 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 09:54:30 -06:00
e65deec5ea Rename the Makefile, add usage note at the top
I had named it makefile_web" in an effort to communicate to the user
that the Make-based build path is only for web builds. It's annoying to
type all that out, though, and it doesn't seem like other projects
follow this convention. I'll just put a usage note at the top. It's not
like the Makefile can be mis-used to make a non-web version. There is no
footgun here.
2025-11-06 09:43:11 -06:00
29d0b644ec Remove fly.toml from repo
Some checks failed
check / stable / fmt (push) Successful in 51s
check / beta / clippy (push) Failing after 1m18s
check / stable / clippy (push) Failing after 1m0s
check / semver (push) Failing after 5m49s
check / nightly / doc (push) Successful in 2m20s
check / ubuntu / stable / features (push) Successful in 2m26s
check / ubuntu / 1.79.0 (push) Failing after 28s
As a general rule, this probably shouldn't be in the main repo. I've
also deleted the Fly app, so it doesn't need to exist anywhere.
2025-11-04 14:03:55 -06:00
9 changed files with 157 additions and 148 deletions

View File

@@ -34,44 +34,6 @@ jobs:
components: rustfmt components: rustfmt
- name: cargo fmt --check - name: cargo fmt --check
run: cargo fmt --check run: cargo fmt --check
clippy:
runs-on: ubuntu-latest
name: ${{ matrix.toolchain }} / clippy
permissions:
contents: read
checks: write
strategy:
fail-fast: false
matrix:
# Get early warning of new lints which are regularly introduced in beta channels.
toolchain: [stable, beta]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install ${{ matrix.toolchain }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
components: clippy
- name: cargo clippy
uses: giraffate/clippy-action@v1
with:
reporter: 'github-pr-check'
github_token: ${{ secrets.GITHUB_TOKEN }}
semver:
runs-on: ubuntu-latest
name: semver
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install stable
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: cargo-semver-checks
uses: obi1kenobi/cargo-semver-checks-action@v2
doc: doc:
# run docs generation on nightly rather than stable. This enables features like # run docs generation on nightly rather than stable. This enables features like
# https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an # https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an
@@ -116,7 +78,7 @@ jobs:
# https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
strategy: strategy:
matrix: matrix:
msrv: ["1.79.0"] msrv: ["1.87.0"]
name: ubuntu / ${{ matrix.msrv }} name: ubuntu / ${{ matrix.msrv }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

50
Cargo.lock generated
View File

@@ -142,7 +142,7 @@ dependencies = [
[[package]] [[package]]
name = "another-boids-in-rust" name = "another-boids-in-rust"
version = "0.4.0" version = "0.6.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy_spatial", "bevy_spatial",
@@ -1489,9 +1489,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.10.1" version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
[[package]] [[package]]
name = "calloop" name = "calloop"
@@ -1509,9 +1509,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.43" version = "1.2.46"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2" checksum = "b97463e1064cb1b1c1384ad0a0b9c8abd0988e2a91f52606c80ef14aadb63e36"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"jobserver", "jobserver",
@@ -1963,9 +1963,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]] [[package]]
name = "erased-serde" name = "erased-serde"
version = "0.4.8" version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "259d404d09818dec19332e31d94558aeb442fea04c817006456c24b5460bbd4b" checksum = "89e8918065695684b2b0702da20382d5ae6065cf3327bc2d6436bd49a71ce9f3"
dependencies = [ dependencies = [
"serde", "serde",
"serde_core", "serde_core",
@@ -2029,9 +2029,9 @@ dependencies = [
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.4" version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
[[package]] [[package]]
name = "fixedbitset" name = "fixedbitset"
@@ -2063,9 +2063,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]] [[package]]
name = "font-types" name = "font-types"
version = "0.10.0" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "511e2c18a516c666d27867d2f9821f76e7d591f762e9fc41dd6cc5c90fe54b0b" checksum = "39a654f404bbcbd48ea58c617c2993ee91d1cb63727a37bf2323a4edeed1b8c5"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
] ]
@@ -2455,9 +2455,9 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]] [[package]]
name = "image" name = "image"
version = "0.25.8" version = "0.25.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "529feb3e6769d234375c4cf1ee2ce713682b8e76538cb13f9fc23e1400a591e7" checksum = "e6506c6c10786659413faa717ceebcb8f70731c0a60cbae39795fdf114519c1a"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"byteorder-lite", "byteorder-lite",
@@ -3269,9 +3269,9 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]] [[package]]
name = "orbclient" name = "orbclient"
version = "0.3.48" version = "0.3.49"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba0b26cec2e24f08ed8bb31519a9333140a6599b867dac464bb150bdb796fd43" checksum = "247ad146e19b9437f8604c21f8652423595cf710ad108af40e77d3ae6e96b827"
dependencies = [ dependencies = [
"libredox", "libredox",
] ]
@@ -3501,9 +3501,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.41" version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@@ -3568,9 +3568,9 @@ checksum = "c3d6831663a5098ea164f89cff59c6284e95f4e3c76ce9848d4529f5ccca9bde"
[[package]] [[package]]
name = "rangemap" name = "rangemap"
version = "1.6.0" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93e7e49bb0bf967717f7bd674458b3d6b0c5f48ec7e3038166026a69fc22223" checksum = "acbbbbea733ec66275512d0b9694f34102e7d5406fdbe2ad8d21b28dce92887c"
[[package]] [[package]]
name = "raw-window-handle" name = "raw-window-handle"
@@ -3758,9 +3758,9 @@ dependencies = [
[[package]] [[package]]
name = "ruzstd" name = "ruzstd"
version = "0.8.1" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3640bec8aad418d7d03c72ea2de10d5c646a598f9883c7babc160d91e3c1b26c" checksum = "e5ff0cc5e135c8870a775d3320910cd9b564ec036b4dc0b8741629020be63f01"
dependencies = [ dependencies = [
"twox-hash", "twox-hash",
] ]
@@ -3979,9 +3979,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.108" version = "2.0.110"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -4297,9 +4297,9 @@ checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]] [[package]]
name = "unicode-properties" name = "unicode-properties"
version = "0.1.3" version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d"
[[package]] [[package]]
name = "unicode-script" name = "unicode-script"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "another-boids-in-rust" name = "another-boids-in-rust"
version = "0.4.0" version = "0.6.0"
edition = "2024" edition = "2024"
license = "AGPL-3.0-only" license = "AGPL-3.0-only"

View File

@@ -1,19 +1,12 @@
FROM rust:1.89 AS builder FROM rust:1.89 AS builder
RUN apt-get update RUN apt-get update
RUN apt-get install -y --no-install-recommends libasound2-dev libudev-dev
RUN rustup target add wasm32-unknown-unknown RUN rustup target add wasm32-unknown-unknown
RUN cargo install --locked wasm-bindgen-cli RUN cargo install --locked wasm-bindgen-cli
# Copy only the package manifest and source code. Otherwise changes to anything COPY . .
# will cause Docker to re-run `cargo build` even when the source hasn't changed.
COPY src/ ./src
COPY Cargo.toml ./Cargo.toml
COPY Cargo.lock ./Cargo.lock
RUN cargo build --locked --target wasm32-unknown-unknown --profile=wasm-release RUN make -j
RUN wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name "boids" target/wasm32-unknown-unknown/wasm-release/another-boids-in-rust.wasm
COPY www/index.html out/index.html
FROM busybox:musl FROM busybox:musl
RUN mkdir -p /var/www RUN mkdir -p /var/www

73
Makefile Normal file
View File

@@ -0,0 +1,73 @@
# This script produces a web build. If you aren't trying to do that, it is
# entirely useless to you.
# 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 := wasm-release
# Override DESTDIR to set a custom install path (such as your web root)
DESTDIR ?= .
SRC_DIR = ./src
SRCS := $(wildcard $(SRC_DIR)/**)
.PHONY: clean full-clean install tarball tarball-standalone web web-standalone
# "Standalone" version
# (i.e., it includes an index.html so it can be placed on a server as-is)
web-standalone: out/boids.js out/boids_bg.wasm.gz out/index.html
# "Bundle-able" version. The host site must provide it's own HTML page.
web: out/boids.js out/boids_bg.wasm.gz out/boids.html
tarball: boids_web_root.tar
tarball_standalone: boids_web_root_standalone.tar
boids_web_root.tar: out/boids.js out/boids_bg.wasm.gz out/boids.html
tar -caf $@ $^
boids_web_root_standalone.tar: out/boids.js out/boids_bg.wasm.gz out/index.html
tar -caf $@ $^
target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.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/boids.js out/boids_bg.wasm.gz &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm | out
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name boids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm
gzip -9 -f out/boids_bg.wasm
# Copies the index page to the output
out/index.html: www/index.html
cp -a $< $@
rm -f out/boids.html
# Like `out/index.html`, but renames it for use in a larger site.
out/boids.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/ boids_web_root.tar boids_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/boids.js $(DESTDIR)/
install -m0644 out/boids_bg.wasm.gz $(DESTDIR)/
install -m0644 out/boids.html $(DESTDIR)/

View File

@@ -21,13 +21,42 @@ You'll need a working Rust toolchain, of course. See the [rustup](https://rustup
### Web ### Web
This project creates a "static site," meaning a complete deployment of the site is simply copying the output folder onto a webserver. This project creates a "static site," meaning a complete deployment of the site is simply copying the output folder onto a webserver. There are **two** ways to use this.
1. Build `make -f ./makefile_web web` 1. A standalone application which can be quickly hosted as-is. This includes the WASM, it's JS glue, and an index.html page.
2. A sub-page in a larger website. This is actually the same, but names it's HTML page "boids.html" so consumers (you) can provide their own index.html.
- I'm not using a JS Bundler at this time. If you're familiar with JS development, this probably looks like a dumb way to do it. Sorry about that.
#### Standalone build:
1. Build `make web-standalone`
2. Serve `python3 -m http.server -d ./out` 2. Serve `python3 -m http.server -d ./out`
3. Visit site in browser: `http://localhost:8000` 3. Visit site in browser: `http://localhost:8000`
You can use any HTTP server you like. Here, I'm using the Python3 built-in [http.server module](https://docs.python.org/3/library/http.server.html); which is **NOT** recommended for production use. Don't put that on the Internet! Alternatives include [Miniserve](https://crates.io/crates/miniserve) and [BusyBox](https://busybox.net/). The latter of which I'm using in the Docker image. To quickly get a tarball, use `make tarball_standalone`. If you're trying to build and upload the program somewhere, this may provide a bit of convenience. Compressing it may be a good idea, too.
#### "Bundle-able" build
For a "bundle-able" build, you'll need to write your own index.html and link to the boids.html file.
Basically, just throw in a hyperlink with `<a href="boids.html">Boids</a>`
```html
<!DOCTYPE html>
<html>
<!-- your page content, etc -->
<body>
<a href="boids.html">Boids</a>
</body>
<!-- more page content, etc -->
</html>
```
As mentioned in the option 2 description, I'm not using a JS Bundler. There is no "package.json" or anything to integrate properly with a JS framework. I plan to fix that at some point, but for now there are just a bunch of files to grab.
---
You can use any HTTP server you like. In the steps above, I'm using the Python3 built-in [http.server module](https://docs.python.org/3/library/http.server.html); which is **NOT** recommended for production use. Don't put that on the Internet! Alternatives include [Miniserve](https://crates.io/crates/miniserve) and [BusyBox](https://busybox.net/). The latter of which I'm using in the Docker image.
### Web, but as a Docker Container ### Web, but as a Docker Container
@@ -45,6 +74,7 @@ You may also notice that the Dockerfile doesn't call on the Makefile. This is be
## Controls ## Controls
| Input | Effect | | Input | Effect |
|-|-|
| Mouse | The scanner circle is attached to the mouse cursor. Move it to scan boids within the radius. | | Mouse | The scanner circle is attached to the mouse cursor. Move it to scan boids within the radius. |
| Left mouse button | Put scanner into center-of-mass mode | | Left mouse button | Put scanner into center-of-mass mode |
| Right mouse button | Put scanner into average velocity mode | | Right mouse button | Put scanner into average velocity mode |

View File

@@ -1,25 +0,0 @@
# fly.toml app configuration file generated for boids-autumn-lake-5810 on 2025-09-03T16:02:00-05:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'boids-autumn-lake-5810'
primary_region = 'ord'
[build]
[env]
PORT = '8080'
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[vm]]
memory = '256mb'
cpu_kind = 'shared'
cpus = 1

View File

@@ -1,41 +0,0 @@
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 := wasm-release
.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/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.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/boids.js out/boids_bg.wasm &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm | out
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name boids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/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

View File

@@ -1,16 +1,28 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style> <style>
body {
background-color: hsl(100, 10%, 60%);
color: hsl(0, 0%, 15%);
}
h1 { h1 {
background-color: rgb(72, 97, 72);
text-align: center; text-align: center;
margin: auto;
padding: 0.5em;
} }
canvas { canvas {
padding-left: 0; margin-top: 1em;
padding-right: 0;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
display: block; display: block;
outline-color: hsl(100, 100%, 15%);
outline-style: outset;
border-radius: 8px;
background-color: rgb(40%, 40%, 40%);
} }
main { main {
margin-left: auto; margin-left: auto;
@@ -18,11 +30,12 @@
width: 70%; width: 70%;
} }
table { table {
margin-bottom: 10px;
border-collapse: collapse; border-collapse: collapse;
} }
th, td { th, td {
border: 1px solid; border: 1px solid;
padding: 2px 4px; padding: 0.1em 0.3em;
} }
</style> </style>
</head> </head>
@@ -91,7 +104,7 @@
<tr> <tr>
<td>Program Version</td> <td>Program Version</td>
<!-- This version text is completely unchecked. I'll need to do something about that. --> <!-- This version text is completely unchecked. I'll need to do something about that. -->
<td><code>v0.4.0</code></td> <td><code>v0.6.0</code></td>
</tr> </tr>
</table> </table>
</article> </article>
@@ -99,7 +112,11 @@
<script type="module"> <script type="module">
import init from './boids.js' import init from './boids.js'
init().catch((error) => { let compressed = await fetch("./boids_bg.wasm.gz")
let wasm_stream = compressed.body.pipeThrough(new DecompressionStream("gzip"))
let blob = await new Response(wasm_stream).blob();
init(await blob.arrayBuffer()).catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) { if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
throw error; throw error;
} }