You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add browser (WASM) build target with GitHub Pages demo
- build_web.sh: wasm32-unknown-unknown release build, version-matched
wasm-bindgen-cli auto-install, packages target/web_dist static site
- web/index.html: canvas host page (game name templated via {{GAME_NAME}})
- Cargo.toml: webgl2 bevy feature; getrandom wasm_js feature for the
ahash-pulled getrandom 0.3 (plus RUSTFLAGS cfg in script and CI)
- lib.rs: bind window to #game-canvas, fit_canvas_to_parent (wasm only)
- CI: web job builds + zips the site into the release and deploys it to
GitHub Pages as a live demo; setup_env.sh checks the wasm toolchain
- README: demo link, web row/scripts/quick-start, load-bearing wasm notes
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# GameBase
2
2
3
-
A minimal Bevy (Rust) starter game that already ships to **Linux**, **Windows**, and **Android (APK)** from a single Linux dev machine. The build methodology was extracted from the Julian2 train game project.
3
+
A minimal Bevy (Rust) starter game that already ships to **Linux**, **Windows**, **Android (APK)**, and the **browser (WASM)** from a single Linux dev machine. The build methodology was extracted from the Julian2 train game project.
4
+
5
+
**[▶ Play the demo in your browser](https://maxfridbe.github.io/GameBase/)** — deployed automatically to GitHub Pages by the release workflow.
4
6
5
7
The base game is a sphere you drive around a 3D plane:
| Windows | cross-compile from Linux with MinGW (`x86_64-pc-windows-gnu`) |`target/windows_dist/` (exe + assets, zip and ship) |
29
31
| Android A (**primary**) |`cargo apk` builds the **cdylib** into an APK per ABI; NativeActivity, no Java code at all |`target/{debug,release}/apk/*.apk`|
30
32
| Android B (alternative) |`cargo ndk` drops the cdylib into `app/src/main/jniLibs/`, then Gradle wraps it with a Java `GameActivity` into one universal APK |`app/build/outputs/apk/debug/app-debug.apk`|
33
+
| Browser (WASM) | compile the bin to `wasm32-unknown-unknown` (webgl2 feature), `wasm-bindgen` generates the JS glue, `web/index.html` hosts the canvas |`target/web_dist/` (static site — serve anywhere) |
31
34
32
35
Key load-bearing details (easy to lose, hard to rediscover):
33
36
@@ -37,6 +40,7 @@ Key load-bearing details (easy to lose, hard to rediscover):
37
40
- Two APKs are built on purpose in Path A: **x86_64** for the desktop emulator, **arm64-v8a** for real phones. Path B builds one fat APK containing both.
38
41
- Emulator GPU emulation matters for wgpu/Vulkan: `swangle_indirect` (run_emulator.sh) is the most stable; `start_new_emulator.sh` is the SwiftShader/CPU fallback for hosts whose GPU driver crashes the emulator.
39
42
-`game.env` centralizes the game identity + Android SDK paths; every script sources it.
43
+
- Browser build details: `bevy_embedded_assets` means the `.wasm` is fully self-contained (no asset fetch issues on static hosts); `wasm-bindgen-cli` must exactly match the `wasm-bindgen` crate version in `Cargo.lock` (`build_web.sh` auto-installs the right one); `getrandom` 0.3 (pulled via ahash/bevy) needs the `wasm_js` feature **and**`RUSTFLAGS=--cfg getrandom_backend="wasm_js"` — both are wired in already; the window is bound to the `#game-canvas` element in `web/index.html`.
40
44
41
45
## Scripts
42
46
@@ -46,6 +50,7 @@ Key load-bearing details (easy to lose, hard to rediscover):
46
50
|`setup_env.sh`| Check, then install only what's missing: system packages (apt or dnf detected automatically), Rust + cross targets, MinGW-w64, cargo-apk/cargo-ndk, Android SDK/NDK 26, debug keystore |
47
51
|`run_linux.sh [debug]`| Build + run natively on Linux |
48
52
|`build_windows.sh`| Cross-compile Windows release, package exe + assets into `target/windows_dist/`|
53
+
|`build_web.sh`| Build the browser version into `target/web_dist/` (compile to wasm, run wasm-bindgen, add `web/index.html`) |
-`<game>-android-arm64-v<version>.apk` (phones) and `<game>-android-x86_64-v<version>.apk` (emulator)
75
+
-`<game>-web-v<version>.zip` (static site) — the same build is also deployed to **GitHub Pages** as the live demo (first run: if the `pages` job fails, enable Pages once under repo Settings → Pages → Source: GitHub Actions)
70
76
71
77
Pushing again without bumping the version updates the existing release for that tag rather than creating a new one. CI signs APKs with a freshly generated debug keystore — replace that step with a real keystore (repo secret) before shipping to a store.
72
78
@@ -77,6 +83,8 @@ Pushing again without bumping the version updates the existing release for that
77
83
./setup_env.sh # once per machine; installs only the missing pieces (apt or dnf)
78
84
./run_linux.sh # play on Linux
79
85
./build_windows.sh # produce target/windows_dist/ for Windows
86
+
./build_web.sh # produce target/web_dist/ for the browser
87
+
python3 -m http.server -d target/web_dist 8080 # ...then play at localhost:8080
80
88
./run_emulator.sh # boot the Android emulator...
81
89
./build_cargo_apk_debug.sh && ./deploy_cargo_apk.sh # ...and play in it
82
90
./build_cargo_apk.sh && ./deploy_phone.sh # play on a USB phone
**3. App icon** — replace `assets/android-res/mipmap-mdpi/ic_launcher.png` (used by both Android paths).
116
124
125
+
**3b. Demo link** — the browser demo deploys to `https://<your-user>.github.io/<your-repo>/`; update the link at the top of this README. (`web/index.html` needs no changes — `build_web.sh` fills in the game name.)
126
+
117
127
**4. Only if you use Path B (Gradle):**
118
128
119
129
-`app/build.gradle` — `namespace` and `applicationId`
@@ -142,4 +152,5 @@ sed -i "s/Game Base/$NEWLABEL/g" Cargo.toml src/lib.rs
142
152
| Android NDK | 26.1.10909125 | referenced by every script + setup |
143
153
| AGP / Gradle | 8.4.0 / 8.6 | Path B only |
144
154
| games-activity | 4.4.0 | must stay compatible with bevy's `android-activity` crate |
155
+
| wasm-bindgen-cli | = `wasm-bindgen` in Cargo.lock | hard requirement; `build_web.sh`/CI resolve it automatically |
145
156
| minSdk / target/compileSdk | 30 / 33 / 34 | Path B only; cargo-apk defaults handle Path A |
0 commit comments