Repository navigation
feat(rust): add the anthias_native extension and its wheel pipeline - #3536
vpetersson-bot wants to merge 3 commits into
Conversation
Add a Rust extension module, anthias_native (PyO3 + maturin, abi3 for CPython 3.13+), so parts of Anthias can move to Rust one module at a time while Django stays the application. The pilot is the backup member name checks (runtime whitelist, absolute paths, '..' and empty components) that guard restoring an uploaded archive. The Python code moves to lib/backup_paths.py and stays as the fallback; backup_helper uses the Rust version unless ANTHIAS_NATIVE_DISABLE=backup (or all) is set. The whole backup test suite runs against both, plus a parity test over ~13k generated names. Images: a native-builder stage runs on the build platform and cross-compiles the wheel for the board with zig, so no Rust is compiled under QEMU; uv-builder installs it into /venv. Locally, uv sync builds the crate from rust/anthias_native. CI: a Rust workflow runs fmt, clippy, cargo test and cargo deny, builds the x86_64/aarch64/armv7 wheels, checks each (natively or under QEMU on Debian trixie's Python) with rust/scripts/check_wheel.py, and uploads them as artifacts. Refs #3520 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
There was a problem hiding this comment.
Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.
- pyo3's build script reads python3 on PATH and refuses anything older than the abi3-py313 floor; the runner's own python3 is 3.12, so the clippy step failed before linting. Set up 3.13 in the checks job. - Check wheels by unpacking them onto PYTHONPATH instead of installing them with pip/uv: same files the images get, nothing resolved. - Apply the dual-implementation fixture through usefixtures instead of autouse with params. - Name the Docker platform strings in the image builder once. Refs #3520 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
There was a problem hiding this comment.
Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.
Refs #3520 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
There was a problem hiding this comment.
Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.
|



Issues Fixed
Closes #3520. This is the pilot that #3521, #3522 and #3523 build on.
Description
This adds
anthias_native, a Rust extension module (PyO3 0.30 + maturin, abi3 for CPython 3.13+, so one wheel per architecture), plus the pipeline that builds it for every board. Django stays the application. Each Python module stays the public interface and calls into Rust, and its Python implementation stays alongside as a fallback.Pilot function: the backup member name checks. Those are the runtime whitelist, absolute paths, and
..or empty components that_safe_tar_memberapplies to every member of an uploaded backup. I picked these overifaddrs.parse_dumpbecause the host agent runs from a host venv rather than an image, so a pilot there wouldn't prove the image pipeline, and #3523 replaces that agent with a static binary anyway. The backup checks run inanthias-server/anthias-celeryon every board, and #3521 extends them.src/anthias_server/lib/backup_paths.pyholds the Python implementation (moved out ofbackup_helper.pyunchanged).rust/anthias_native/src/backup.rsholds the Rust port, withcargo testtests. Bindings are inlib.rs. Names that aren't valid UTF-8 (lone surrogates from tarfile) are converted lossily, which gives the same answer because the checks only compare ASCII.backup_helperuses Rust unlessANTHIAS_NATIVE_DISABLE=backup(orall) is set (anthias_common/native.py). Therealpathconfinement and the member-type checks stay in Python because they need the filesystem and theTarInfo.Tests against both implementations
tests/test_backup_helper.pyagainst both Rust and Python.tests/test_native_backup_paths.pycompares the two over about 13k generated names, covering traversal, backslashes, doubled separators, non-ASCII, surrogates and NUL. It also covers the switch and checks that the abi3 build is what gets loaded.Images: no Rust under QEMU. A new
native-builderstage (docker/native-builder.j2) runs on$BUILDPLATFORMand cross-compiles the board's wheel withmaturin --zig.uv-buildersyncs with--no-install-package anthias-nativeand installs that wheel into/venv. The stage is only added for theserverandtestuv groups; the viewer image is unchanged.Local dev:
uv sync --group testbuilds the crate from source through a uv path dependency. uvcache-keysmake it rebuild when.rsorCargo.tomlfiles change.CI (
.github/workflows/rust.yaml)cargo fmt --check,clippy -D warnings,cargo testandcargo deny(licences, advisories, sources).rust/scripts/check_wheel.py: natively on x86_64, under QEMU in Debian trixie's Python 3.13 for the ARM wheels (only the import and the check run under QEMU; nothing is compiled there).Dependabot now covers
cargotoo.Docs: there is a new "Rust extension" section in the developer documentation (building locally, CI checks, how it ships, the fallback switch, and how to move the next module).
rust/README.mdandCLAUDE.mdpoint to it.Measurements
These were taken on an x86_64 build host with QEMU for armv7, same as CI. Both sides were built
--no-cache.uv-buildertargetThe difference is within noise. The
native-builderstage takes about 45 s (rustup target addplus maturin), runs natively, and overlaps withuv-builder's 761 suv sync. The only serial addition is copying and installing the wheel, about 4 s. The wheels are about 350 KB, link only against glibc (2.28 symbol floor), and import in the built armv7 venv.check_wheel.pyper-call timings. The x86_64 numbers are native; the ARM numbers come from QEMU, so they are not representative of real hardware:is_safe_member_nameThe pilot was chosen for the pipeline, not for speed; these are per-name checks on a restore.
Still open from the acceptance criteria: verifying the cross-compiled armv7 wheel on real Pi 2/3 hardware. That is being done on the device rig with the CI artifact and
rust/scripts/check_wheel.py, and the results will be added here.Local verification
cargo fmt --check,clippy --all-features -D warnings,cargo test --no-default-features(5 tests) andcargo deny checkall pass.ruff check,ruff format --check,mypy .(strict) andactionlintall pass.backup_paths.pyandnative.pyat 100%); 73 integration tests passed, 2 skipped.anthias_nativeimports from/venv.check_wheel.pyin adebian:trixievenv.Checklist
🤖 Generated with Claude Code