From 6dd21822ccfa9cb47ef93d5928c85fd9fe669b13 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Mon, 3 Aug 2026 23:37:48 +0200 Subject: [PATCH] Add native linux/win binaries to the pipeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch the builder image to rust:1-bookworm — bevy's native linux build needs glibc + alsa/udev, which does not build against musl — and add the x86_64-pc-windows-gnu target with mingw-w64 for the windows cross-compile (linker set from the Makefile, no per-repo .cargo/config). Mac stays out: darwin needs osxcross, same as the ebitengine mac plan. Builder steps pull the image on every run so :latest updates reach the runner. Co-Authored-By: Claude Fable 5 --- README.md | 45 ++++++++++++++++++++++++++-------- builder.Dockerfile | 20 +++++++++++---- example-makefile.make | 54 +++++++++++++++++++++++++++++++++++++++-- example-woodpecker.yaml | 7 ++++++ 4 files changed, 109 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ec89213..5d6dc65 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,20 @@ projects, in the same spirit as [godot-tools](../godot-tools). - `example-makefile.make` — project Makefile: local dev targets - (`build`, `run`, `wasm`, `export`, `watch`, `clean`) plus the - Woodpecker pipeline targets (`ci-version`, `ci-export`, `ci-upload`, - `ci-update`). + (`build`, `run`, `wasm`, `export`, `binaries`, `watch`, `clean`) + plus the Woodpecker pipeline targets (`ci-version`, `ci-export`, + `ci-binaries`, `ci-upload`, `ci-update`). - `example-woodpecker.yaml` — Woodpecker pipeline: version → build (Rust, `wasm32-unknown-unknown` target + `wasm-bindgen` in the - `git.teletypegames.org/internal/bevy-builder` image) → upload (scp to the - droparea) → update (calls the teletypegames `/update` endpoint with + `git.teletypegames.org/internal/bevy-builder` image) → binaries + (native linux-x64 + mingw win-x64) → upload (scp to the droparea) → + update (calls the teletypegames `/update` endpoint with `platform=bevy`). -- `builder.Dockerfile` — the CI builder image: `rust:1-alpine` with - the wasm target, the wasm-bindgen CLI and make/zip/curl baked in. +- `builder.Dockerfile` — the CI builder image: `rust:1-bookworm` + (glibc — bevy's native linux build needs alsa/udev, which does not + build against musl) with the wasm + `x86_64-pc-windows-gnu` + targets, mingw-w64, the wasm-bindgen CLI and make/zip/curl baked + in. - `example-tasks.json` — VS Code `.vscode/tasks.json` with the common dev tasks: **Run** (`cargo run`, default build task, `Cmd+Shift+B`), **Build & Run**, **Build WASM** and **Make build**. @@ -49,9 +53,30 @@ Local WASM builds additionally need `rustup target add wasm32-unknown-unknown` and the `wasm-bindgen` CLI (`cargo install wasm-bindgen-cli --version 0.2.100`). -The pipeline uploads `$(PROJECT)-$(VERSION).html.zip` to the droparea, -then triggers -`/update?platform=bevy&name=$(PROJECT)&version=$(VERSION)`. +The pipeline uploads `$(PROJECT)-$(VERSION).html.zip` and the native +binary zips (`-win-x64.zip`, `-linux-x64.zip`) to the droparea, then +triggers `/update?platform=bevy&name=$(PROJECT)&version=$(VERSION)`. +The API's `BinaryAttachment` concern picks up the +`--.zip` files automatically and registers them +as `win_x64` / `linux_x64` release assets. + +## Native binaries + +`make binaries VERSION=x.y` builds: + +- **linux-x64** — a regular `cargo build --release` in the + debian-based builder; the binary links against the builder's glibc + and the usual desktop libs (alsa, udev). +- **win-x64** — mingw-w64 cross-compile via the + `x86_64-pc-windows-gnu` target; the linker is set from the + Makefile (`CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER`), no + per-repo `.cargo/config` needed. +- **mac** — not built here: cgo-style native cross-compilation to + darwin needs osxcross, the same (planned) toolchain as the + ebitengine mac targets. + +If the project has an `assets/` directory it is packaged next to the +binary — bevy loads it at runtime, it is not embedded. ## Builder image diff --git a/builder.Dockerfile b/builder.Dockerfile index 8f36585..f5e36d3 100644 --- a/builder.Dockerfile +++ b/builder.Dockerfile @@ -2,10 +2,16 @@ # wasm32-unknown-unknown target and the wasm-bindgen CLI preinstalled, # so the pipeline's build step does not download them on every run. # +# Debian-based (glibc) rather than alpine: the native linux binary needs +# glibc + alsa/udev dev libs (wgpu/winit), which bevy cannot build against +# musl. The windows binary is cross-compiled with mingw-w64 +# (x86_64-pc-windows-gnu target). Mac is not cross-compiled here — that +# is the same osxcross story as the ebitengine mac targets. +# # WASM_BINDGEN_VERSION must match the `wasm-bindgen` crate version pinned # in the game repos' Cargo.toml (see README) — rebuild and retag this image -# when bumping it. The CLI is the x86_64 musl binary, so the image must be -# built for linux/amd64. +# when bumping it. The CLI is the x86_64 musl binary (static, runs on +# glibc too), so the image must be built for linux/amd64. # # Build & push (the CI runner is linux/amd64): # docker build --platform linux/amd64 -f builder.Dockerfile \ @@ -13,13 +19,17 @@ # -t git.teletypegames.org/internal/bevy-builder:latest . # docker push git.teletypegames.org/internal/bevy-builder:latest -FROM rust:1-alpine +FROM rust:1-bookworm ARG WASM_BINDGEN_VERSION=0.2.100 -RUN apk add --no-cache musl-dev make zip curl git jq +RUN apt-get update && apt-get install -y --no-install-recommends \ + make zip curl git jq pkg-config \ + libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev \ + gcc-mingw-w64-x86-64 \ + && rm -rf /var/lib/apt/lists/* -RUN rustup target add wasm32-unknown-unknown +RUN rustup target add wasm32-unknown-unknown x86_64-pc-windows-gnu RUN curl -sSL "https://github.com/rustwasm/wasm-bindgen/releases/download/${WASM_BINDGEN_VERSION}/wasm-bindgen-${WASM_BINDGEN_VERSION}-x86_64-unknown-linux-musl.tar.gz" \ | tar xz -C /usr/local/bin --strip-components=1 \ diff --git a/example-makefile.make b/example-makefile.make index c36e374..998c9fd 100644 --- a/example-makefile.make +++ b/example-makefile.make @@ -33,6 +33,48 @@ wasm: wasm-bindgen --target web --no-typescript \ --out-dir $(DIST_DIR) --out-name game $(WASM_RELEASE) +# ----------------------------------------- +# Native binaries. linux-x64: glibc build in the debian-based builder +# image; win-x64: mingw-w64 cross-compile (x86_64-pc-windows-gnu). +# Mac needs osxcross, it is not built here. +# The zip gets the assets/ dir too if the project has one — bevy loads +# it at runtime, it is not embedded in the binary. +# ----------------------------------------- + +BINARY_SLUGS = win-x64 linux-x64 +WIN_TARGET = x86_64-pc-windows-gnu + +# $(1) slug, $(2) built binary, $(3) file name inside the package +define f_pack_binary + set -e; \ + PKG_DIR="$(PROJECT)-$(VERSION)-$(1)"; \ + rm -rf "$$PKG_DIR" "$$PKG_DIR.zip"; \ + mkdir -p "$$PKG_DIR"; \ + cp "$(2)" "$$PKG_DIR/$(3)"; \ + chmod +x "$$PKG_DIR/$(3)"; \ + if [ -d assets ]; then cp -r assets "$$PKG_DIR/assets"; fi; \ + zip -qr "$$PKG_DIR.zip" "$$PKG_DIR"; \ + rm -rf "$$PKG_DIR"; \ + echo "==> $$PKG_DIR.zip kesz" +endef + +binaries: + @if [ -z "$(VERSION)" ]; then \ + echo "ERROR: VERSION not set!"; exit 1; \ + fi + @$(MAKE) binary-linux binary-win VERSION=$(VERSION) + +binary-linux: + @echo "==> Building linux-x64 binary" + cargo build --release + @$(call f_pack_binary,linux-x64,target/release/$(PROJECT),$(PROJECT)) + +binary-win: + @echo "==> Building win-x64 binary" + CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc \ + cargo build --release --target $(WIN_TARGET) + @$(call f_pack_binary,win-x64,target/$(WIN_TARGET)/release/$(PROJECT).exe,$(PROJECT).exe) + export: wasm @if [ -z "$(VERSION)" ]; then \ echo "ERROR: VERSION not set!"; exit 1; \ @@ -66,18 +108,26 @@ ci-export: @VERSION=$$(cat $(VERSION_FILE)); \ $(MAKE) export VERSION=$$VERSION +ci-binaries: + @VERSION=$$(cat $(VERSION_FILE)); \ + $(MAKE) binaries VERSION=$$VERSION + ci-upload: @VERSION=$$(cat $(VERSION_FILE)); \ FILE="$(PROJECT)-$$VERSION.html.zip"; \ META_SRC="metadata.json"; \ META_DST="$(PROJECT)-$$VERSION.metadata.json"; \ cp $$META_SRC $$META_DST; \ + BINS=""; \ + for slug in $(BINARY_SLUGS); do \ + [ -f "$(PROJECT)-$$VERSION-$$slug.zip" ] && BINS="$$BINS $(PROJECT)-$$VERSION-$$slug.zip"; \ + done; \ sshpass -p "$(DROPAREA_SSH_PASSWORD)" scp -o StrictHostKeyChecking=no -P $(DROPAREA_PORT) \ - $$FILE $$META_DST \ + $$FILE $$META_DST $$BINS \ $(DROPAREA_USER)@$(DROPAREA_HOST):$(DROPAREA_TARGET_PATH)/ ci-update: @VERSION=$$(cat $(VERSION_FILE)); \ curl "$(UPDATE_SERVER)/update?secret=$(UPDATE_SECRET)&name=$(PROJECT)&platform=bevy&version=$$VERSION" -.PHONY: all build run wasm export watch clean ci-version ci-export ci-upload ci-update +.PHONY: all build run wasm export binaries binary-linux binary-win watch clean ci-version ci-export ci-binaries ci-upload ci-update diff --git a/example-woodpecker.yaml b/example-woodpecker.yaml index d354b88..d3ecb6f 100644 --- a/example-woodpecker.yaml +++ b/example-woodpecker.yaml @@ -7,9 +7,16 @@ steps: - name: build image: git.teletypegames.org/internal/bevy-builder:latest + pull: true commands: - make ci-export + - name: binaries + image: git.teletypegames.org/internal/bevy-builder:latest + pull: true + commands: + - make ci-binaries + - name: upload image: alpine environment: