ci: cross-compile with crafter-build instead of pmbootstrap chroots
All checks were successful
package / package (push) Successful in 1m50s

The pmbootstrap approach needed the privileged pmos runner, which only
fp6-img can reach. This repo already had the right flow: make-sysroot.sh
+ crafter-build --target=aarch64-alpine-linux-musl + APKBUILD.binary —
unprivileged, so it runs in an alpine:edge container on the ordinary
arch-latest runner, and minutes instead of qemu-chroot hours. The test
suite runs natively; the aarch64 binaries are further exercised by
fp6-img's chroot 'make check' whenever an image builds.

APKBUILD.binary gains the pmOS integration payload the canonical aport
ships (systemd subpackage, enable preset, wants symlink, config-gated
drop-in, kde-modem-daemon skel override) — required before this pipeline
may publish a version users upgrade to, or the upgrade would strip those
files. pkgver now follows implementations/main.cpp (sed'd by the CI, and
bumped to 0.3.1 in the file).
This commit is contained in:
Jorijn van der Graaf 2026-09-01 23:31:27 +02:00
commit 87376ccd9c
3 changed files with 147 additions and 110 deletions

View file

@ -1,20 +1,26 @@
name: package name: package
# Builds the imsd apk(s) for aarch64 from packaging/aport/ at the pushed # Builds the imsd apk(s) for aarch64 from the pushed commit and publishes
# commit and publishes them to the Forgejo Alpine registry — the repo # them to the Forgejo Alpine registry — the repo installed phones already
# installed phones already point at (via catcrafts-fp6-repo), so a release # point at (via catcrafts-fp6-repo), so a release reaches users through
# reaches users through plain 'apk upgrade' without an fp6-img image run. # plain 'apk upgrade' without an fp6-img image run.
# #
# Release gating is the pkgver: the registry answers 409 for an # Build: crafter-build cross-compiles against an Alpine aarch64 sysroot
# already-published version and the publish step treats that as "nothing to # (packaging/build-package.sh — the README's "Cross-compiling" flow), the
# do" — so pushes only release when packaging/aport/APKBUILD bumps # test suite runs natively, and packaging/APKBUILD.binary wraps the result.
# pkgver/pkgrel. fp6-img images keep building imsd from their own pinned # This needs no privileged runner: it runs in an alpine:edge container on
# checkout of this repo; same aport, so the two pipelines cannot skew. # the ordinary arch-latest runner.
# #
# Runs on the privileged "pmos" runner (qemu-user binfmt on the host for # Release gating is the version: pkgver comes from implementations/main.cpp,
# pmbootstrap's aarch64 chroots). Requires the PACKAGE_TOKEN secret # the registry answers 409 for an already-published version, and the publish
# (catbot account, package:write scope) to publish; without it the build # step treats that as "nothing to do" — so pushes only release when the
# still runs and the publish step skips quietly. # Version constant bumps. fp6-img images keep building imsd from their own
# pinned checkout of this repo (packaging/aport/); APKBUILD.binary's payload
# must stay identical to that aport's, so the two pipelines cannot skew.
#
# Requires the PACKAGE_TOKEN secret (catbot account, package:write scope) to
# publish; without it the build still runs and the publish step skips
# quietly.
on: on:
workflow_dispatch: workflow_dispatch:
@ -23,8 +29,10 @@ on:
jobs: jobs:
package: package:
runs-on: pmos runs-on: arch-latest
timeout-minutes: 180 container:
image: alpine:edge
timeout-minutes: 90
steps: steps:
# actions/checkout is a Node action; bare alpine has no node # actions/checkout is a Node action; bare alpine has no node
- name: Provision job container - name: Provision job container
@ -33,7 +41,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Build package - name: Build and package
run: ./packaging/build-package.sh run: ./packaging/build-package.sh
- name: Publish to the apk registry - name: Publish to the apk registry
@ -45,7 +53,7 @@ jobs:
exit 0 exit 0
fi fi
found=0 found=0
for f in /home/build/.local/var/pmbootstrap/packages/*/aarch64/imsd*.apk; do for f in /home/build/.local/share/abuild/*/aarch64/imsd*.apk; do
[ -e "$f" ] || continue [ -e "$f" ] || continue
found=1 found=1
code=$(curl -s -o /dev/null -w '%{http_code}' \ code=$(curl -s -o /dev/null -w '%{http_code}' \

View file

@ -1,12 +1,16 @@
# SPDX-License-Identifier: GPL-3.0-only # SPDX-License-Identifier: GPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® # SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# Maintainer: Jorijn van der Graaf <jorijnvdgraaf@catcrafts.net> # Maintainer: Jorijn van der Graaf <jorijnvdgraaf@catcrafts.net>
# Interim packaging: wraps a crafter-build binary cross-compiled on a dev box # Binary packaging: wraps a crafter-build binary cross-compiled per the
# (see README "Cross-compiling") into a proper apk, so the daemon is # README's "Cross-compiling" section into a proper apk — used by this repo's
# apk-managed on the phone while crafter-build itself isn't packaged for # package CI (packaging/build-package.sh, which also seds pkgver from
# Alpine yet. The source tarball is produced by packaging/make-bin-tarball.sh. # implementations/main.cpp) and runnable by hand. The source tarball is
# produced by packaging/make-bin-tarball.sh; the desktop/preset files come
# from packaging/aport/ (copy them next to this file). The package payload
# must stay identical to packaging/aport/APKBUILD's, or an apk upgrade
# across the two pipelines would add/strip files on users' phones.
pkgname=imsd pkgname=imsd
pkgver=0.3.0 pkgver=0.3.1
pkgrel=0 pkgrel=0
pkgdesc="Userspace IMS/VoLTE daemon for mainline Linux phones" pkgdesc="Userspace IMS/VoLTE daemon for mainline Linux phones"
url="https://forgejo.catcrafts.net/Catcrafts/imsd" url="https://forgejo.catcrafts.net/Catcrafts/imsd"
@ -19,8 +23,15 @@ depends="modemmanager libc++ opencore-amr vo-amrwbenc pipewire-tools"
# which races imsd for the PDN and flaps it with a new prefix every ~2.5 min # which races imsd for the PDN and flaps it with a new prefix every ~2.5 min
# (fp6 journal/ims.md s57) — the two IMS stacks cannot share one PDN # (fp6 journal/ims.md s57) — the two IMS stacks cannot share one PDN
provides="81voltd=$pkgver-r$pkgrel" provides="81voltd=$pkgver-r$pkgrel"
options="!check" # no OpenRC service yet: the unit's PDN-bring-up/env-file sequencing is only
source="imsd-$pkgver.tar.gz" # tested under systemd; an initd is welcome once someone can verify one
subpackages="$pkgname-systemd"
options="!check !tracedeps"
source="
imsd-$pkgver.tar.gz
org.kde.modem.daemon.desktop
80-imsd.preset
"
package() { package() {
cd "$srcdir/imsd-$pkgver" cd "$srcdir/imsd-$pkgver"
@ -33,4 +44,26 @@ package() {
"$pkgdir"/etc/xdg/autostart/imsd-dialerd.desktop "$pkgdir"/etc/xdg/autostart/imsd-dialerd.desktop
install -Dm644 net.catcrafts.IMS1.conf \ install -Dm644 net.catcrafts.IMS1.conf \
"$pkgdir"/usr/share/dbus-1/system.d/net.catcrafts.IMS1.conf "$pkgdir"/usr/share/dbus-1/system.d/net.catcrafts.IMS1.conf
# the skel override hides kde-telephony's modem daemon autostart for the
# account created at install — imsd-dialerd owns those session bus names
install -Dm644 "$srcdir"/org.kde.modem.daemon.desktop \
"$pkgdir"/etc/skel/.config/autostart/org.kde.modem.daemon.desktop
# enabled by preset: the unit is a no-op until /etc/imsd.env exists, and
# VoLTE surviving reboots must not depend on a manual systemctl enable
install -Dm644 "$srcdir"/80-imsd.preset \
"$pkgdir"/usr/lib/systemd/system-preset/80-imsd.preset
mkdir -p "$pkgdir"/etc/systemd/system/multi-user.target.wants
ln -s /usr/lib/systemd/system/imsd.service \
"$pkgdir"/etc/systemd/system/multi-user.target.wants/imsd.service
# ...but only actually start once the carrier config exists, so
# unconfigured systems don't boot into a failing unit
mkdir -p "$pkgdir"/usr/lib/systemd/system/imsd.service.d
printf '[Unit]\nConditionPathExists=/etc/imsd.env\n' \
> "$pkgdir"/usr/lib/systemd/system/imsd.service.d/10-require-config.conf
}
systemd() {
install_if="$pkgname=$pkgver-r$pkgrel systemd"
amove usr/lib/systemd/system
} }

View file

@ -1,115 +1,111 @@
#!/bin/sh -eu #!/bin/sh -eu
# SPDX-License-Identifier: GPL-3.0-only # SPDX-License-Identifier: GPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® # SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# CI package build: produce the imsd apk(s) for aarch64 from THIS checkout, # CI package build: cross-compile imsd for aarch64 with crafter-build (the
# using packaging/aport/ (the canonical aport) and pmbootstrap's cross # README's "Cross-compiling" flow), run the test suite natively, and package
# chroots. Runs in CI inside an Alpine container on the privileged "pmos" # the result via packaging/APKBUILD.binary. Expects an x86_64 Alpine
# runner (qemu-user binfmt on the host for the aarch64 chroots); also # environment with root — the workflow runs it in an alpine:edge job
# runnable in any Alpine environment with the same privileges # container on an ordinary runner. Root only installs packages and hands off
# (IMSD_NO_CROSSDIRECT=1 for hosts where crossdirect's /native bridge # to a scratch user: the sysroot is built with apk.static --usermode (which
# breaks — the build then runs qemu-only, slower, identical output). # refuses root) and abuild wants a user too.
# #
# Built packages land in ~build/.local/var/pmbootstrap/packages/*/aarch64/; # Built packages land in /home/build/.local/share/abuild/*/aarch64/imsd*.apk;
# the workflow's publish step uploads the imsd*.apk ones to the Forgejo # the workflow's publish step uploads them to the Forgejo Alpine registry.
# Alpine registry.
set -eu set -eu
PMAPORTS_REPO=https://gitlab.postmarketos.org/postmarketOS/pmaports.git # The musl build of crafter-build (Crafter.Build CI's release-musl job):
# this container is Alpine, and the glibc launcher cannot run on musl. v2 =
# SSE4.2 baseline: the CI box is an Intel N5105 (no AVX). Overridable for
# local rehearsals (file:// works).
CRAFTER_URL=${CRAFTER_URL:-https://forgejo.catcrafts.net/Catcrafts/Crafter.Build/releases/download/latest/crafter-build-linux-x86_64-musl-v2.tar.gz}
SRC=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) SRC=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
# pmbootstrap refuses to run as root: install deps, then re-exec as a build # clang cross-targets aarch64 natively and the target's libc++/glib come from
# user with passwordless sudo (pmbootstrap escalates itself where needed). # the sysroot; llvm-runtimes/libc++-dev/glib-dev here serve the NATIVE
# test-suite run. build-base = Alpine's standard build environment (the one
# abuild implies): binutils' ld/ar for clang's default link driver, gcc's
# libgcc_s/crt objects the musl clang driver links against.
if [ "$(id -u)" = 0 ]; then if [ "$(id -u)" = 0 ]; then
apk add -q git sudo python3 py3-pip multipath-tools util-linux tar apk add -q git curl tar clang lld llvm llvm-runtimes libc++-dev llvm-libunwind-dev glib-dev \
# pmbootstrap pinned from git: Alpine's package is older. The pmOS build-base abuild sudo
# gitlab hiccups under crawler load; a failure costs a retry, not the run
for _i in 1 2 3; do
pip install -q --break-system-packages \
git+https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git@3.11.1 \
&& break
if [ "$_i" = 3 ]; then
echo "pmbootstrap pip install failed after 3 attempts" >&2
exit 1
fi
echo "pmbootstrap pip install failed (attempt $_i/3), retrying in 15s..." >&2
sleep 15
done
# containers cannot modprobe; make pmbootstrap's 'sudo modprobe' a no-op
# (/usr/local/sbin precedes /sbin in sudo's secure_path)
mkdir -p /usr/local/sbin
printf '#!/bin/sh\nexit 0\n' > /usr/local/sbin/modprobe
chmod +x /usr/local/sbin/modprobe
id build >/dev/null 2>&1 || adduser -D build id build >/dev/null 2>&1 || adduser -D build
addgroup build abuild 2>/dev/null || true
echo 'build ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/build echo 'build ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/build
# su scrubs the environment — carry the knobs that matter across it # abuild in cross mode strips with $CHOST-strip; llvm-strip handles any
exec su build -c "IMSD_NO_CROSSDIRECT='${IMSD_NO_CROSSDIRECT:-}' sh -eu '$SRC/packaging/build-package.sh'" # ELF arch, so give it that name
ln -sf "$(command -v llvm-strip)" /usr/local/bin/aarch64-alpine-linux-musl-strip
# the CI checkout arrives root-owned; crafter-build writes bin/ into it
chown -R build "$SRC"
# -l: a login shell, so HOME really is /home/build (abuild keys + output);
# it scrubs the environment, so carry the one knob that matters across
exec su -l build -c "CRAFTER_URL='${CRAFTER_URL:-}' sh -eu '$SRC/packaging/build-package.sh'"
fi fi
# the CI checkout is root-owned; let git read it as the build user
git config --global --add safe.directory "$SRC"
# git hosts occasionally hiccup; a clone failure costs a retry, not the run
clone_retry() { # clone_retry <dest> <git clone args...>
_dest=$1; shift
for _i in 1 2 3; do
rm -rf "$_dest"
git clone "$@" "$_dest" && return 0
echo "git clone $_dest failed (attempt $_i/3), retrying in 10s..." >&2
sleep 10
done
echo "git clone $_dest failed after 3 attempts" >&2
return 1
}
retry() { # retry <description> <cmd...> retry() { # retry <description> <cmd...>
_desc=$1; shift _desc=$1; shift
for _i in 1 2 3; do for _i in 1 2 3; do
"$@" && return 0 "$@" && return 0
echo "$_desc failed (attempt $_i/3), retrying in 30s..." >&2 echo "$_desc failed (attempt $_i/3), retrying in 15s..." >&2
sleep 30 sleep 15
done done
echo "$_desc failed after 3 attempts" >&2 echo "$_desc failed after 3 attempts" >&2
return 1 return 1
} }
# pmbootstrap swallows its subcommands' stderr into its own log; surface it # implementations/main.cpp is the version's single source of truth (same
# whenever this script dies so failures are diagnosable from CI output alone # derivation as make-bin-tarball.sh)
trap 'rc=$?; if [ $rc -ne 0 ]; then VER=$(sed -n 's/.*char\* Version = "\(.*\)".*/\1/p' "$SRC/implementations/main.cpp")
echo "=== build-package.sh failed (exit $rc); pmbootstrap log tail ===" [ -n "$VER" ] || { echo "cannot read Version from implementations/main.cpp" >&2; exit 1; }
tail -60 "$HOME/.local/var/pmbootstrap/log.txt" 2>/dev/null || true echo ">> packaging imsd $VER"
fi' EXIT
# --- pmaports with our aport dropped in; source tarball from this checkout # --- crafter-build: static launcher from the rolling release
# (the Forgejo instance serves no source archives, so git-archive it) mkdir -p "$HOME/crafter-build"
WORK=${IMSD_PKG_WORK:-$HOME/imsd-pkg-work} retry "fetch crafter-build" \
rm -rf "$WORK" sh -c "curl -fsSL '$CRAFTER_URL' | tar -xz -C '$HOME/crafter-build'"
mkdir -p "$WORK" PATH="$HOME/crafter-build/bin:$PATH"
clone_retry "$WORK/pmaports" -q --depth=1 "$PMAPORTS_REPO" export CRAFTER_BUILD_HOME="$HOME/crafter-build/share/crafter-build"
mkdir -p "$WORK/pmaports/modem"
cp -r "$SRC/packaging/aport" "$WORK/pmaports/modem/imsd"
COMMIT=$(git -C "$SRC" rev-parse --short HEAD)
git -C "$SRC" archive --prefix=imsd/ \
-o "$WORK/pmaports/modem/imsd/imsd-$COMMIT.tar.gz" HEAD
sed -i "s/^_commit=.*/_commit=\"$COMMIT\"/" "$WORK/pmaports/modem/imsd/APKBUILD"
# --- configure pmbootstrap (config written directly; 'init' is interactive) # --- aarch64 Alpine sysroot (unprivileged: apk.static --usermode)
WORKDIR="$HOME/.local/var/pmbootstrap" SYSROOT="$HOME/.cache/imsd/sysroot-aarch64-alpine"
mkdir -p "$WORKDIR/cache_git" retry "make sysroot" "$SRC/packaging/make-sysroot.sh" "$SYSROOT"
python3 -c "import pmb.config; print(pmb.config.work_version)" > "$WORKDIR/version"
mkdir -p "$HOME/.config"
cat > "$HOME/.config/pmbootstrap_v3.cfg" <<EOF
[pmbootstrap]
aports = $WORK/pmaports
device = fairphone-fp6
ui = console
systemd = always
EOF
NOCROSS=${IMSD_NO_CROSSDIRECT:+--no-cross} # --- cross-compile the products; run the suites natively (same sources,
# host arch — the aarch64 binaries are additionally exercised by fp6-img's
# chroot `make check` whenever an image builds)
cd "$SRC"
XTARGET="--target=aarch64-alpine-linux-musl --sysroot=$SYSROOT --march=armv8-a --mtune=generic"
crafter-build -- $XTARGET
crafter-build -- --product=media $XTARGET
crafter-build -- --product=dialerd $XTARGET
crafter-build test
pmbootstrap checksum imsd # --- bundle + package
retry "build imsd" pmbootstrap $NOCROSS build --arch aarch64 imsd ./packaging/make-bin-tarball.sh "$VER"
PKG="$HOME/pkg"
rm -rf "$PKG"
mkdir -p "$PKG"
cp "$SRC/packaging/APKBUILD.binary" "$PKG/APKBUILD"
cp "$SRC/packaging/aport/org.kde.modem.daemon.desktop" \
"$SRC/packaging/aport/80-imsd.preset" "$PKG/"
mv "imsd-$VER.tar.gz" "$PKG/"
sed -i "s/^pkgver=.*/pkgver=$VER/" "$PKG/APKBUILD"
# a throwaway signing key: phones trust the registry-signed APKINDEX, not
# per-package keys (same situation as fp6-img's pmbootstrap-built packages).
# abuild >= 3.18 keeps keys under ~/.config/abuild and output under
# ~/.local/share/abuild (REPODEST default).
abuild-keygen -a -n >/dev/null 2>&1
sudo cp "$HOME"/.config/abuild/*.rsa.pub /etc/apk/keys/
# CHOST puts abuild in cross mode so arch="aarch64" packages on this x86_64
# host. -d skips dependency handling entirely: nothing compiles under abuild
# (with -r, cross mode would try to install a nonexistent build-base-aarch64
# plus the runtime depends); !tracedeps in the APKBUILD keeps abuild from
# resolving the aarch64 ELF NEEDED entries against this x86_64 host.
cd "$PKG"
abuild checksum
CHOST=aarch64 abuild -d
echo "=== built packages ===" echo "=== built packages ==="
ls -la "$WORKDIR"/packages/*/aarch64/imsd*.apk ls -la "$HOME"/.local/share/abuild/*/aarch64/imsd*.apk