Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ jobs:
fetch-depth: 0

- name: Setup cross environment for meson
uses: robotpy/build-actions/setup-cross-meson@v2027
run: bash devtools/cross/setup.sh

- name: Install deps
shell: bash
Expand All @@ -365,7 +365,7 @@ jobs:
- name: Build + test wheels
shell: bash
run: |
/build/venv/bin/cross-python -m devtools ci build-other-wheels --no-test
bash devtools/cross/build.sh other

- uses: actions/upload-artifact@v7
with:
Expand Down Expand Up @@ -397,7 +397,7 @@ jobs:
path: dist-other

- name: Setup cross environment for meson
uses: robotpy/build-actions/setup-cross-meson@v2027
run: bash devtools/cross/setup.sh

- run: apt-get update
- name: Setup ccache
Expand All @@ -414,7 +414,7 @@ jobs:
- name: Build wheels
shell: bash
run: |
/build/venv/bin/cross-python -m devtools ci build-meson-wheels --no-test --cross=cross.txt
bash devtools/cross/build.sh meson


- uses: actions/upload-artifact@v7
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.py[ciod]
/dist
/dist-other
/wheels
/cache

rpy-include
Expand Down
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ Then run these commands to build all the wheels for the current operating system

All the resulting wheels are in `dist`, which can be installed using `pip`.

To build wheels for the robot platform, you need to use a crossenv docker image.
See `.github/workflows/dist.yml` for details.
To build wheels for the robot platform, see Cross Compilation below.

Development environment
-----------------------
Expand Down Expand Up @@ -84,7 +83,31 @@ for tips to make it more efficient.
Cross Compilation
-----------------

We only support cross-compiling for RoboRIO and raspbian via the WPILib
docker build containers. See `.github/workflows/dist.yml`'s `cross-build`
job for the name of the containers and the steps that must be run inside
the container.
Build Systemcore wheels using the same Docker image and build steps as CI:

./rdev.sh cross-build --output wheels

Docker must be running, and the host Python needs `rdev_requirements.txt`.
The current image is `wpilib/systemcore-cross-debian:2026-trixie-py315`.
Use `--buildtype=debug` to request a debug Meson build.

The command copies tracked and non-ignored untracked sources, including local
edits, into an isolated workspace. Build directories, caches, and the local
`build-actions` checkout are excluded. Existing desktop build artifacts are
unaffected. Relative output paths are relative to this repository, as with other
`rdev.sh` commands.
The repository's `wheels/` directory is ignored by Git; an absolute output path
can also be used.

Native, pure-Python, and wrapper wheels are copied to the output directory only
after a successful build. Matching filenames are replaced; other files are left
alone. Cross-compiled tests are not run, matching CI.

Compiler, pip, and artifact downloads persist in the Docker volume
`rdev-systemcore-cache`. The cross files use ccache, whose statistics are printed
at the end of the build. Wheels are exported with the invoking user's ownership.
The container requires network access to install tools and download dependencies.

CI and local builds share `devtools/cross/setup.sh` and `build.sh`. The setup and
cross files originate from `robotpy/build-actions/setup-cross-meson@v2027`;
update them together when changing toolchains.
2 changes: 2 additions & 0 deletions devtools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .ctx import Context
from . import ci
from . import examples
from .cross_build import cross_build

#
# Environment variables for configuring the builds
Expand Down Expand Up @@ -36,6 +37,7 @@ def main(ctx: click.Context, verbose: bool):

main.add_command(ci.ci)
main.add_command(examples.test_examples)
main.add_command(cross_build)


@main.command("update-pyproject")
Expand Down
17 changes: 17 additions & 0 deletions devtools/cross/bookworm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[binaries]
c = ['ccache', 'armv6-bookworm-linux-gnueabihf-gcc']
cpp = ['ccache', 'armv6-bookworm-linux-gnueabihf-g++']
ar = 'armv6-bookworm-linux-gnueabihf-ar'
strip = 'armv6-bookworm-linux-gnueabihf-strip'
gfortran = 'armv6-bookworm-linux-gnueabihf-gfortran'

pkg-config = '/build/venv/cross/bin/pkgconf-pypi'

[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'armv6'
endian = 'little'

[properties]
longdouble_format = 'IEEE_DOUBLE_LE'
22 changes: 22 additions & 0 deletions devtools/cross/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Shared by CI and the local Docker launcher. Run from the repository root.
set -euo pipefail
export PATH="/build/venv/cross/bin:/build/venv/build/bin:$PATH"
stage=${1:?Expected other, meson, or all}
shift
case "$stage" in
other)
/build/venv/bin/cross-python -m devtools ci build-other-wheels --no-test
;;
meson)
/build/venv/bin/cross-python -m devtools ci build-meson-wheels --no-test --cross=cross.txt "$@"
;;
all)
bash devtools/cross/build.sh other
mkdir -p dist-other
mv dist/*.whl dist-other/
/build/venv/bin/cross-python -m devtools ci build-pure-wheels
bash devtools/cross/build.sh meson "$@"
;;
*) echo "Unknown build stage: $stage" >&2; exit 2 ;;
esac
20 changes: 20 additions & 0 deletions devtools/cross/local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -euo pipefail
mkdir /work
cp -a /source/. /work/
cd /work
export PATH="/build/venv/cross/bin:/build/venv/build/bin:$PATH"
export CCACHE_DIR=/cache/ccache
export CCACHE_BASEDIR=/work
export HATCH_ROBOTPY_CACHE=/cache/downloads
export PIP_CACHE_DIR=/cache/pip
trap 'ccache --show-stats' EXIT
if ! command -v ccache >/dev/null; then
apt-get update
apt-get install -y --no-install-recommends ccache
fi
bash devtools/cross/setup.sh
/build/venv/bin/build-pip --disable-pip-version-check install -r rdev_requirements.txt
bash devtools/cross/build.sh all "$@"
cp dist/*.whl dist-other/*.whl /export/
chown "${EXPORT_UID}:${EXPORT_GID}" /export/*.whl
17 changes: 17 additions & 0 deletions devtools/cross/roborio.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[binaries]
c = ['ccache', 'arm-frc2025-linux-gnueabi-gcc']
cpp = ['ccache', 'arm-frc2025-linux-gnueabi-g++']
ar = 'arm-frc2025-linux-gnueabi-ar'
strip = 'arm-frc2025-linux-gnueabi-strip'
gfortran = 'arm-frc2025-linux-gnueabi-gfortran'

pkg-config = '/build/venv/cross/bin/pkgconf-pypi'

[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'armv7l'
endian = 'little'

[properties]
longdouble_format = 'IEEE_DOUBLE_LE'
37 changes: 37 additions & 0 deletions devtools/cross/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# Keep in sync with robotpy/build-actions/setup-cross-meson@v2027.
set -euo pipefail
cross_dir="$(cd "$(dirname "$0")" && pwd)"
mkdir -p ~/.local/share/meson/cross
toolchain_found=false
for entry in \
arm-frc2025-linux-gnueabi:roborio \
armv6-bookworm-linux-gnueabihf:bookworm \
aarch64-bookworm-linux-gnu:systemcore_bookworm \
aarch64-systemcore2027-linux-gnu:systemcore_2027; do
if command -v "${entry%:*}-g++" >/dev/null; then
cp "$cross_dir/${entry#*:}.txt" ~/.local/share/meson/cross/cross.txt
toolchain_found=true
break
fi
done
if [[ $toolchain_found == false ]]; then
echo 'No known cross toolchain found' >&2
exit 1
fi
/build/venv/bin/cross-pip --disable-pip-version-check install meson
scratch=$(mktemp -d)
trap 'rm -rf "$scratch"' EXIT
cd "$scratch"
for package in ninja pkgconf; do
/build/venv/bin/build-pip --disable-pip-version-check download --no-deps "$package"
for wheel in "$package"-*.whl; do
renamed=$(echo "$wheel" | sed -E 's/([^-]+-[^-]+-[^-]+)-.*/\1-none-any.whl/')
mv "$wheel" "$renamed"
/build/venv/bin/cross-pip --disable-pip-version-check install "$renamed"
rm "$renamed"
done
done
if [[ -n ${GITHUB_PATH:-} ]]; then
echo /build/venv/cross/bin:/build/venv/build/bin >> "$GITHUB_PATH"
fi
18 changes: 18 additions & 0 deletions devtools/cross/systemcore_2027.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[binaries]
c = ['ccache', 'aarch64-systemcore2027-linux-gnu-gcc']
cpp = ['ccache', 'aarch64-systemcore2027-linux-gnu-g++']
ar = 'aarch64-systemcore2027-linux-gnu-ar'
strip = 'aarch64-systemcore2027-linux-gnu-strip'
gfortran = 'aarch64-systemcore2027-linux-gnu-gfortran'

pkg-config = '/build/venv/cross/bin/pkgconf-pypi'

[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'aarch64'
endian = 'little'

[built-in options]
c_args = ['-Wno-psabi']
cpp_args = ['-Wno-psabi']
18 changes: 18 additions & 0 deletions devtools/cross/systemcore_bookworm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[binaries]
c = ['ccache', 'aarch64-bookworm-linux-gnu-gcc']
cpp = ['ccache', 'aarch64-bookworm-linux-gnu-g++']
ar = 'aarch64-bookworm-linux-gnu-ar'
strip = 'aarch64-bookworm-linux-gnu-strip'
gfortran = 'aarch64-bookworm-linux-gnu-gfortran'

pkg-config = '/build/venv/cross/bin/pkgconf-pypi'

[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'aarch64'
endian = 'little'

[built-in options]
c_args = ['-D__FIRST_SYSTEMCORE__', '-Wno-psabi']
cpp_args = ['-D__FIRST_SYSTEMCORE__', '-Wno-psabi']
101 changes: 101 additions & 0 deletions devtools/cross_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""Launch the CI cross build in an isolated Docker workspace."""

import os
from pathlib import Path
import shutil
import subprocess
import tempfile

import click

from .ctx import Context

IMAGE = "wpilib/systemcore-cross-debian:2026-trixie-py315"


def snapshot(root: Path, destination: Path, output: Path):
"""Copy current sources, including untracked edits, but no build artifacts."""
paths = (
subprocess.check_output(
["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard"],
cwd=root,
)
.decode()
.split("\0")
)
for name in set(paths) - {""}:
relative = Path(name)
if any(
part
in {"build-actions", "build", "dist", "dist-other", "cache", "__pycache__"}
for part in relative.parts
):
continue
source = root / relative
if source.resolve().is_relative_to(output) or not source.is_file():
continue
target = destination / relative
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, target)


@click.command("cross-build")
@click.option(
"--output",
required=True,
type=click.Path(path_type=Path, file_okay=False),
help="Destination for wheels (relative paths are relative to the repository).",
)
@click.option("--buildtype", help="Meson build type (release, debug, etc).")
@click.pass_obj
def cross_build(ctx: Context, output: Path, buildtype: str | None):
"""Build SystemCore wheels in CI's Docker image, with persistent ccache."""
if shutil.which("docker") is None:
raise click.ClickException("Docker is required for cross-build")
output = output.resolve()
root = ctx.root_path.resolve()
if root.is_relative_to(output):
raise click.BadParameter(
"must not contain the source repository", param_hint="--output"
)
try:
with tempfile.TemporaryDirectory(prefix="rdev-cross-") as temporary:
staging = Path(temporary)
source = staging / "source"
exported = staging / "wheels"
source.mkdir()
exported.mkdir()
snapshot(root, source, output)
command = [
"docker",
"run",
"--rm",
"--platform",
"linux/amd64",
"--mount",
f"type=bind,source={source},target=/source,readonly",
"--mount",
f"type=bind,source={exported},target=/export",
"--mount",
"type=volume,source=rdev-systemcore-cache,target=/cache",
"--env",
f"EXPORT_UID={os.getuid()}",
"--env",
f"EXPORT_GID={os.getgid()}",
IMAGE,
"bash",
"/source/devtools/cross/local.sh",
]
if buildtype:
command.append(f"--buildtype={buildtype}")
click.echo(f"Building in {IMAGE}")
subprocess.run(command, check=True)
wheels = list(exported.glob("*.whl"))
if not wheels:
raise click.ClickException("The build produced no wheels")
output.mkdir(parents=True, exist_ok=True)
for wheel in wheels:
shutil.copy2(wheel, output / wheel.name)
click.echo(f"Wrote {len(wheels)} wheels to {output}")
except (OSError, subprocess.CalledProcessError) as exc:
raise click.ClickException(str(exc)) from exc
Loading
Loading