feat(xtask): cross-platform release build via cargo-zigbuild
Some checks failed
CI / Test (Linux) (push) Has been cancelled
CI / Test (Windows MSVC) (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Format (push) Has been cancelled

Replace build-all.sh shell script with a Rust xtask workspace member.
Uses cargo-zigbuild + zig as a universal cross-linker -- no VMs, no
containers, no root required.

Produces all three release binaries from a single FreeBSD machine:
  anvil-X.Y.Z-freebsd-x86_64.tar.gz  (native cargo build)
  anvil-X.Y.Z-linux-x86_64.tar.gz    (cargo zigbuild)
  anvil-X.Y.Z-windows-x86_64.zip     (cargo zigbuild)

Commands:
  cargo xtask --fix     install zig, zip, cargo-zigbuild, rustup targets
  cargo xtask --check   verify all dependencies
  cargo xtask           build all three binaries + SHA256SUMS
  cargo xtask --clean   remove cross-compile artifacts
  cargo xtask --suffix rc1  build with version suffix

Also converts Cargo.toml to a workspace (members: anvil, xtask).
build-all.sh retained as a thin wrapper around cargo xtask.
This commit is contained in:
Eric Ratliff
2026-03-16 19:54:33 -05:00
parent 13ab202880
commit e7995de547
8 changed files with 768 additions and 209 deletions

112
README.md
View File

@@ -377,65 +377,18 @@ Anvil is written in Rust and compiles to a single static binary. You need:
- **Rust toolchain** (stable, 2021 edition or later)
- **A C linker** (`gcc` or equivalent -- Rust uses it under the hood)
- **MinGW** (only if cross-compiling a Windows binary from Linux)
- **zip** (only for packaging release artifacts)
### Linux / WSL from scratch
A fresh Ubuntu or WSL instance needs three commands:
### Build
```bash
# 1. System packages (C linker + cross-compile + packaging tools)
sudo apt update && sudo apt install build-essential mingw-w64 zip
# 2. Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
# 3. Build
cargo build --release
```
The release binary lands at `target/release/anvil`. Copy it somewhere in
your PATH.
### Windows (native)
Install Rust from [rustup.rs](https://rustup.rs), which includes the MSVC
toolchain. Then:
```
cargo build --release
```
The binary lands at `target\release\anvil.exe`.
### Release builds (Linux + Windows from one machine)
The `build-release.sh` script at the repo root builds optimized, stripped
binaries for both platforms and packages them into tarballs and zips. It
reads the version from `Cargo.toml` (the single source of truth) and
accepts an optional suffix for pre-release builds:
```bash
./build-release.sh # uses version from Cargo.toml (e.g. 1.0.0)
./build-release.sh beta1 # appends suffix (e.g. 1.0.0-beta1)
./build-release.sh rc1 # appends suffix (e.g. 1.0.0-rc1)
```
This produces a `release-artifacts/` directory with:
```
anvil-1.0.0-linux-x86_64.tar.gz
anvil-1.0.0-linux-x86_64.zip
anvil-1.0.0-windows-x86_64.zip
SHA256SUMS
```
Upload these to a Gitea release. The script requires `build-essential`,
`mingw-w64`, and `zip` as described above.
The release binary lands at `target/release/anvil` (or `target\release\anvil.exe`
on Windows). Copy it somewhere in your PATH.
### Running the test suite
```bash
cargo test
```
@@ -449,6 +402,7 @@ skip gracefully and everything else still passes.
#### Full test suite on Linux / WSL
The e2e tests need `cmake`, `g++`, and `arduino-cli` with the AVR core:
```bash
sudo apt install cmake g++
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
@@ -460,6 +414,7 @@ arduino-cli core install arduino:avr
Install [arduino-cli](https://arduino.github.io/arduino-cli/installation/)
and add it to your PATH, then install the AVR core:
```
arduino-cli core install arduino:avr
```
@@ -470,6 +425,61 @@ a Visual Studio Developer Command Prompt (which provides `cl.exe`).
---
## Building Release Binaries
Anvil uses a Rust `xtask` workspace member to build release binaries for all
platforms from a single machine. No VMs, no containers, no root required.
### How it works
The xtask build system uses [cargo-zigbuild](https://github.com/rust-cross/cargo-zigbuild)
with the [Zig](https://ziglang.org) compiler as a universal cross-linker.
From a single FreeBSD machine you get all three platform binaries:
```
release-artifacts/
anvil-X.Y.Z-freebsd-x86_64.tar.gz native FreeBSD build
anvil-X.Y.Z-linux-x86_64.tar.gz cross-compiled via zig
anvil-X.Y.Z-windows-x86_64.zip cross-compiled via zig
SHA256SUMS
```
### First-time setup
```bash
cargo xtask --fix
```
This installs zig (via pkg), zip, cargo-zigbuild, and the required rustup
cross-compile targets. Only the zig and zip installation steps require sudo.
### Building a release
```bash
cargo xtask # build all platforms, version from Cargo.toml
cargo xtask --suffix rc1 # pre-release (e.g. 1.0.0-rc1)
```
### Other commands
```bash
cargo xtask --check # verify all dependencies are installed
cargo xtask --clean # remove cross-compile artifacts
```
### Platform support
| Host | FreeBSD binary | Linux binary | Windows binary |
|---|---|---|---|
| FreeBSD | native | cargo-zigbuild | cargo-zigbuild |
| Linux | not possible | native | cargo-zigbuild |
| Windows | not possible | not tested | native |
FreeBSD is the recommended build host -- it produces all three binaries in
a single run.
---
## License
MIT -- see [LICENSE](LICENSE).