packaging: the aarch64 flatpak
crafter-build cross-compiles the executable for aarch64, which on an x86_64 machine needs no emulation, and flatpak's build commands assemble the flatpak; there is no flatpak-builder manifest. make-flatpak-sysroot.sh makes the sysroot: the aarch64 Freedesktop Sdk 26.08 with LLVM's libc++ of the release crafter-build carries (23.1.2, the tarball and hash of Crafter.Build's manifest), built for aarch64. build-flatpak.sh builds the executable against it for generic armv8-a and assembles it on the Platform 26.08 with that libc++, libc++abi and LLVM's libunwind in /app/lib: the Platform has no libc++, and its libunwind is libunwind 8. It fails when the executable or a bundled library needs a library neither the Platform nor /app/lib has, and when one of them links libunwind 8, which libc++'s -lunwind found first until the sysroot dropped its link name. The executable it packages is the build it just ran: the output directory's name ends in a hash of the configuration, so an older variant (another sysroot, --debug, --local) left in bin/ is removed first. make-flatpak-sysroot.sh tries each download five times, 30 s apart: Flathub's CDN answers 502 now and then. The sandbox gets Wayland, the GPU, net.catcrafts.IMS1 on the system bus and org.freedesktop.Notifications on the session bus. The metainfo's content rating declares the app's chat (OARS social-chat intense: uncontrolled texting between users), as the baseline Chatty's does, for the software centres and parental controls that read it, and recommends a display of 360 logical pixels or more — the phone screen the window is drawn for; a recommendation, not a requirement. The metainfo's one release is 0.0.0, and the app's version, 0.1.0 in the skeleton, is set to it: the version's comment in Model.cppm says a release moves the two together. AGENTS.md's SPDX rule says what the metainfo carries instead of the two SPDX lines: AppStream's single CC0-1.0 line. The flatpak carries the licences of what it ships under /app/share/licenses/net.catcrafts.ImsdMessages: the app's and the font's, those of the Crafter libraries it links statically and of the code they bring along (packaging/licenses/, with a NOTICE naming what each text covers), and LLVM's for its runtime libraries, which make-flatpak-sysroot.sh keeps beside libc++.
This commit is contained in:
parent
687774864a
commit
411ed55660
11 changed files with 955 additions and 6 deletions
110
packaging/build-flatpak.sh
Executable file
110
packaging/build-flatpak.sh
Executable file
|
|
@ -0,0 +1,110 @@
|
|||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
# build-flatpak.sh — the aarch64 flatpak of imsd-messages, into an OSTree
|
||||
# repository. crafter-build cross-compiles the executable against the
|
||||
# sysroot of packaging/make-flatpak-sysroot.sh (run that first), and
|
||||
# flatpak's build commands assemble it on org.freedesktop.Platform 26.08,
|
||||
# with the libc++ it was linked against in /app/lib.
|
||||
#
|
||||
# packaging/build-flatpak.sh <repo> [branch] # branch: master by default
|
||||
#
|
||||
# The repository is created when it does not exist; `flatpak build-bundle`
|
||||
# makes a single-file bundle out of it. The cache and $CRAFTER_REF are
|
||||
# make-flatpak-sysroot.sh's. Needs flatpak, flock, readelf and
|
||||
# appstreamcli.
|
||||
set -eu
|
||||
|
||||
REPO=${1:?usage: build-flatpak.sh <repo> [branch]}
|
||||
BRANCH=${2:-master}
|
||||
APP_ID=net.catcrafts.ImsdMessages
|
||||
ARCH=aarch64
|
||||
TRIPLE=aarch64-unknown-linux-gnu
|
||||
MULTIARCH=aarch64-linux-gnu
|
||||
RUNTIME_VERSION=26.08
|
||||
CRAFTER_REF=${CRAFTER_REF:-net.catcrafts.CrafterBuild//stable}
|
||||
CACHE=${IMSD_MESSAGES_FLATPAK_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/imsd-messages/flatpak}
|
||||
INSTALLATION="$CACHE/installation"
|
||||
SYSROOT="$CACHE/sysroot-$ARCH"
|
||||
LIBCXX="$CACHE/libcxx-$ARCH"
|
||||
SRC=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
||||
# flatpak commands that need the aarch64 Sdk and Platform see their
|
||||
# installation; crafter-build runs from wherever it is installed.
|
||||
withsdk() { FLATPAK_USER_DIR="$INSTALLATION" "$@"; }
|
||||
|
||||
command -v readelf >/dev/null 2>&1 || { echo "readelf (binutils) is needed: the NEEDED checks below run on it" >&2; exit 1; }
|
||||
# One build at a time on this cache: the build directory is removed and
|
||||
# made again by every run.
|
||||
mkdir -p "$CACHE"
|
||||
exec 9>"$CACHE/lock"; flock 9
|
||||
[ -f "$SYSROOT/.made-from" ] || { echo "no sysroot at $SYSROOT: run packaging/make-flatpak-sysroot.sh first" >&2; exit 1; } # under the lock: a sysroot being made is not missing
|
||||
|
||||
echo ">> the executable for $TRIPLE"
|
||||
# Generic armv8-a: a flatpak is for any aarch64 machine, not one SoC. The
|
||||
# output directory's name ends in a hash of the configuration (the sysroot,
|
||||
# --debug, --local), and an older variant left in bin/ would be a second
|
||||
# match below: this run's is the only one.
|
||||
rm -rf "$SRC/bin/imsd-messages-$TRIPLE-armv8-a-generic-"*
|
||||
(cd "$SRC" && flatpak run "$CRAFTER_REF" --march=armv8-a --mtune=generic -- --target="$TRIPLE" --sysroot="$SYSROOT")
|
||||
set -- "$SRC/bin/imsd-messages-$TRIPLE-armv8-a-generic-"*/
|
||||
[ $# = 1 ] && [ -x "$1/imsd-messages" ] || { echo "expected one output directory with an executable under $SRC/bin for $TRIPLE, found: $*" >&2; exit 1; }
|
||||
bin=$1
|
||||
|
||||
echo ">> $APP_ID from $bin"
|
||||
build="$CACHE/build-$ARCH"
|
||||
rm -rf "$build"
|
||||
withsdk flatpak build-init --arch="$ARCH" "$build" "$APP_ID" org.freedesktop.Sdk org.freedesktop.Platform "$RUNTIME_VERSION"
|
||||
files="$build/files"
|
||||
# The executable finds its shaders and font beside its real path.
|
||||
mkdir -p "$files/bin" "$files/lib/imsd-messages"
|
||||
cp -a "$bin". "$files/lib/imsd-messages/"
|
||||
ln -s ../lib/imsd-messages/imsd-messages "$files/bin/imsd-messages"
|
||||
cp -a "$LIBCXX/usr/lib/"libc++.so.1* "$LIBCXX/usr/lib/"libc++abi.so.1* "$LIBCXX/usr/lib/"libunwind.so.1* "$files/lib/"
|
||||
install -Dm644 "$SRC/packaging/$APP_ID.desktop" "$files/share/applications/$APP_ID.desktop"
|
||||
install -Dm644 "$SRC/packaging/icons/$APP_ID.svg" "$files/share/icons/hicolor/scalable/apps/$APP_ID.svg"
|
||||
install -Dm644 "$SRC/packaging/$APP_ID.metainfo.xml" "$files/share/metainfo/$APP_ID.metainfo.xml"
|
||||
# The licences of what the flatpak carries; packaging/licenses/NOTICE names
|
||||
# what each text covers.
|
||||
licenses="$files/share/licenses/$APP_ID"
|
||||
install -Dm644 "$SRC/LICENSE" "$licenses/LICENSE"
|
||||
install -Dm644 "$SRC/assets/OFL.txt" "$licenses/OFL.txt"
|
||||
install -Dm644 -t "$licenses" "$SRC"/packaging/licenses/* "$LIBCXX"/licenses/*
|
||||
|
||||
# Every library the executable and the bundled ones need is in the Platform
|
||||
# or in /app/lib, or the first start would fail on the phone.
|
||||
platform=$(withsdk flatpak --user info --show-location --arch="$ARCH" "org.freedesktop.Platform//$RUNTIME_VERSION")/files
|
||||
missing=0
|
||||
for elf in "$files/lib/imsd-messages/imsd-messages" "$files/lib/"lib*.so.1; do
|
||||
for lib in $(readelf -d "$elf" | sed -n 's/.*(NEEDED).*\[\(.*\)\]/\1/p'); do
|
||||
if [ ! -e "$platform/lib/$MULTIARCH/$lib" ] && [ ! -e "$platform/lib/$lib" ] && [ ! -e "$files/lib/$lib" ]; then
|
||||
echo "$(basename "$elf") needs $lib, which neither the Platform nor /app/lib has" >&2
|
||||
missing=1
|
||||
fi
|
||||
done
|
||||
done
|
||||
# One unwinder: LLVM's libunwind, which the bundled libc++abi uses, never
|
||||
# the Platform's libunwind 8 beside it.
|
||||
for elf in "$files/lib/imsd-messages/imsd-messages" "$files/lib/"lib*.so.1; do
|
||||
if readelf -d "$elf" | grep -q 'NEEDED.*\[libunwind\.so\.8\]'; then
|
||||
echo "$(basename "$elf") links libunwind 8, not LLVM's libunwind" >&2
|
||||
missing=1
|
||||
fi
|
||||
done
|
||||
[ "$missing" = 0 ] || exit 1
|
||||
|
||||
# The AppStream catalogue entry software centres list the app by, with PNG
|
||||
# icons: appstreamcli's default, JPEG XL, is not read by older clients.
|
||||
appstreamcli compose --prefix=/ --origin="$APP_ID" --image-format=png \
|
||||
--result-root="$files" --data-dir="$files/share/app-info/xmls" \
|
||||
--icons-dir="$files/share/app-info/icons/flatpak" "$files"
|
||||
|
||||
# The phone's compositor, its GPU, imsd on the system bus and the desktop's
|
||||
# notifications; the portals need no permission.
|
||||
withsdk flatpak build-finish "$build" --command=imsd-messages \
|
||||
--socket=wayland --device=dri \
|
||||
--system-talk-name=net.catcrafts.IMS1 \
|
||||
--talk-name=org.freedesktop.Notifications
|
||||
mkdir -p "$(dirname "$REPO")"
|
||||
withsdk flatpak build-export --arch="$ARCH" "$REPO" "$build" "$BRANCH"
|
||||
echo ">> done: app/$APP_ID/$ARCH/$BRANCH in $REPO"
|
||||
Loading…
Reference in a new issue