Skip to content
Merged
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
16 changes: 16 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ build:libc++ --action_env=BAZEL_CXXOPTS=-stdlib=libc++
build:libc++ --action_env=BAZEL_LINKLIBS=-l%:libc++.a:-l%:libc++abi.a
build:libc++ --action_env=BAZEL_LINKOPTS=-lm:-pthread
build:libc++ --define force_libcpp=enabled

# Linux ARMv7 hard-float (armhf) cross-compile from a Linux x86_64 or aarch64 host.
# Install g++-arm-linux-gnueabihf and qemu-user-static (Debian/Ubuntu).
# Example:
# bazel build --config=linux_arm32 //phaser/runtime:phaser_runtime
# On macOS, use scripts/build-armhf-colima.sh (Colima + docker/arm32).
build:linux_arm32 --platforms=//platform:linux_arm32
build:linux_arm32 --extra_toolchains=@linux_arm32_toolchain//:cc_toolchain,@linux_arm32_toolchain//:cc_toolchain_aarch64
build:linux_arm32 --cpu=armv7
build:linux_arm32 --features=-external_include_paths
# Keep static bank registrars when the linker would gc unreferenced sections.
build:linux_arm32 --linkopt=-Wl,--no-gc-sections
test:linux_arm32 --run_under=//bazel/toolchains/linux_arm32:qemu
test:linux_arm32 --test_env=QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
run:linux_arm32 --run_under=//bazel/toolchains/linux_arm32:qemu
run:linux_arm32 --run_env=QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
- name: Test (everything except perf_test)
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" $EXTRA_CONFIG \
--test_tag_filters=-linux_arm32 \
-- //... -//phaser:perf_test

# AddressSanitizer runs on macOS (Apple Silicon).
Expand All @@ -63,6 +64,7 @@ jobs:
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" \
--config=asan --config=apple_silicon \
--test_tag_filters=-linux_arm32 \
-- //... -//phaser:perf_test

# AddressSanitizer runs on Linux (no apple_silicon config).
Expand All @@ -84,6 +86,7 @@ jobs:
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" \
--config=asan \
--test_tag_filters=-linux_arm32 \
-- //... -//phaser:perf_test

# Valgrind (memcheck) runs on Linux only.
Expand All @@ -109,4 +112,35 @@ jobs:
- name: Test under Valgrind (everything except perf_test)
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" --config=valgrind \
--test_tag_filters=-linux_arm32 \
-- //... -//phaser:perf_test

# Cross-build phaser_runtime for armhf and smoke-test under QEMU user emulation.
arm32:
name: arm32 (Linux armhf)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install cross toolchain and QEMU
run: |
sudo apt-get update
sudo apt-get install -y \
g++-arm-linux-gnueabihf \
binutils-arm-linux-gnueabihf
# ubuntu-24.04: qemu-user-static; ubuntu-latest (26.04): qemu-user-binfmt.
sudo apt-get install -y qemu-user-static \
|| sudo apt-get install -y qemu-user-binfmt

- name: Cache Bazel
uses: actions/cache@v4
with:
path: ~/.cache/bazel-disk
key: bazel-disk-arm32-linux-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock', '.bazelrc', '.bazelversion') }}
restore-keys: |
bazel-disk-arm32-linux-

- name: Build and test (armhf)
run: |
chmod +x scripts/build-armhf-linux.sh
scripts/build-armhf-linux.sh --test
19 changes: 9 additions & 10 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "phaser",
version = "3.1.1"
version = "3.1.2"
)

bazel_dep(name = "bazel_skylib", version = "1.9.0")
Expand All @@ -20,15 +20,7 @@ bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")

bazel_dep(name = "cpp_toolbelt", version = "2.1.6")

# Remove once cpp_toolbelt 2.1.6 is in the Bazel Central Registry.
git_override(
module_name = "cpp_toolbelt",
commit = "86b45cdd3da46a97a4476be2f2a61909677284a2",
remote = "https://github.com/dallison/cpp_toolbelt.git",
)

bazel_dep(name = "coroutines", version = "3.3.2")
bazel_dep(name = "coroutines", version = "3.4.1")

# protobuf pulls an older rules_go via gazelle; Bazel 9 needs a current rules_go.
single_version_override(
Expand All @@ -51,3 +43,10 @@ rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(edition = "2021")
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")

# Fetched only when --config=linux_arm32 selects @linux_arm32_toolchain.
linux_arm32_toolchain = use_repo_rule(
"//bazel/toolchains/linux_arm32:repo.bzl",
"linux_arm32_toolchain",
)
linux_arm32_toolchain(name = "linux_arm32_toolchain")
109 changes: 106 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ payloads. Protobuf and ROS wire formats are unchanged.
The `PayloadBuffer` (from the [cpp_toolbelt](https://github.com/dallison/cpp_toolbelt)
library) is a relocatable heap — a malloc/free/realloc allocator that uses only offsets
(never raw pointers), so the whole buffer can be copied or moved anywhere. It offers a fast
**bitmap allocator** for small blocks (performance mode, the default) and a **free-list
**small-block size-class allocator** for blocks up to 128 bytes (performance mode,
the default) and a **free-list
allocator** that trades speed for compactness (size mode), selectable via
`::phaser::Tuning`.

Expand Down Expand Up @@ -569,6 +570,28 @@ bazelisk test --config=asan //phaser/...
On Apple Silicon, the `asan` config already pulls in the native `apple_silicon` settings;
see [`.bazelrc`](.bazelrc) for the available configurations.

### Linux armhf (32-bit ARM)

Cross-compile `phaser_runtime` for 32-bit ARM Linux with `--config=linux_arm32`. CI and
native Ubuntu use [`scripts/build-armhf-linux.sh`](scripts/build-armhf-linux.sh) (requires
`g++-arm-linux-gnueabihf` and `qemu-user-static` or `qemu-user-binfmt`). On macOS, [`scripts/build-armhf-colima.sh`](scripts/build-armhf-colima.sh)
builds the same target inside a Colima Docker image. The `protoc-gen-phaser` plugin is built
for the host only (not armhf).

```bash
# Linux (or CI)
scripts/build-armhf-linux.sh
scripts/build-armhf-linux.sh --test

# macOS (Colima + Docker)
scripts/build-armhf-colima.sh --test
```

Arm32 CI runs the same automated `cc_test` targets as the main Linux job under
QEMU (`bazel query 'tests(//...)'` minus `perf_test`, `receive_fuzz_test`, and
host-only Python/Rust/shell tests). LibFuzzer and host `protoc-gen-phaser` tests
are excluded from the armhf job.

### Using Phaser without Bazel

Phaser is a `protoc` plugin, so any build system can drive it as long as the plugin binary
Expand Down
10 changes: 10 additions & 0 deletions bazel/toolchains/linux_arm32/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The armhf C++ toolchain is generated by @linux_arm32_toolchain. This
# package exists so MODULE.bazel can load repo.bzl.
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

package(default_visibility = ["//visibility:public"])

sh_binary(
name = "qemu",
srcs = ["qemu.sh"],
)
12 changes: 12 additions & 0 deletions bazel/toolchains/linux_arm32/qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Run an armhf binary on the host. Ubuntu 24.04 names the emulator
# qemu-arm-static; Ubuntu 26.04 names it qemu-arm.
set -euo pipefail
export QEMU_LD_PREFIX="${QEMU_LD_PREFIX:-/usr/arm-linux-gnueabihf}"
if command -v qemu-arm-static >/dev/null 2>&1; then
exec qemu-arm-static "$@"
elif command -v qemu-arm >/dev/null 2>&1; then
exec qemu-arm "$@"
fi
echo "qemu-arm-static or qemu-arm is required to run armhf binaries" >&2
exit 1
Loading
Loading