139 lines
7.4 KiB
Shell
139 lines
7.4 KiB
Shell
|
|
#!/bin/sh
|
||
|
|
# SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
# build-aarch64.sh: Nostro's two Flatpaks for aarch64, a phone's architecture, into an OSTree repository: the app
|
||
|
|
# (net.catcrafts.Nostro) and the service with the nostro command (net.catcrafts.Nostrod). crafter-build cross-compiles
|
||
|
|
# the executables against the sysroot of make-aarch64-sysroot.sh (run that first), and flatpak's build commands
|
||
|
|
# assemble them on org.freedesktop.Platform 26.08, with the libc++ they were linked against in /app/lib.
|
||
|
|
#
|
||
|
|
# packaging/flatpak/build-aarch64.sh <repo> [branch] # branch: stable by default
|
||
|
|
#
|
||
|
|
# The repository is created when it does not exist. On the phone, as root, with the repository copied over:
|
||
|
|
# packaging/system/install.sh --repo <repo> --app. The cache and $CRAFTER_REF are make-aarch64-sysroot.sh's.
|
||
|
|
# $NOSTRO_GRAPHICS names a Crafter.Graphics checkout's project.cpp for the app, for as long as project.cpp asks for one
|
||
|
|
# (--graphics=). Needs flatpak, flock, readelf and appstreamcli.
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
REPO=${1:?usage: build-aarch64.sh <repo> [branch]}
|
||
|
|
BRANCH=${2:-stable}
|
||
|
|
APP_ID=net.catcrafts.Nostro
|
||
|
|
SERVICE_ID=net.catcrafts.Nostrod
|
||
|
|
ARCH=aarch64
|
||
|
|
TRIPLE=aarch64-unknown-linux-gnu
|
||
|
|
MULTIARCH=aarch64-linux-gnu
|
||
|
|
RUNTIME_VERSION=26.08
|
||
|
|
CRAFTER_REF=${CRAFTER_REF:-net.catcrafts.CrafterBuild//stable}
|
||
|
|
CACHE=${NOSTRO_FLATPAK_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/nostro-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 directories are 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/flatpak/make-aarch64-sysroot.sh first" >&2; exit 1; } # under the lock: a sysroot being made is not missing
|
||
|
|
|
||
|
|
# Generic armv8-a: a Flatpak is for any aarch64 machine, not one SoC. An output directory's name ends in a hash of the
|
||
|
|
# configuration, and an older variant left in bin/ would be a second match below: this run's are the only ones.
|
||
|
|
rm -rf "$SRC/bin/"*"-$TRIPLE-armv8-a-generic-"*
|
||
|
|
crafter() { (cd "$SRC" && flatpak run "$CRAFTER_REF" --march=armv8-a --mtune=generic --banks=bunq "$@" -- --target="$TRIPLE" --sysroot="$SYSROOT"); }
|
||
|
|
# The one executable of that name this run built. The library and the command are both called nostro, so a directory
|
||
|
|
# is told by what it holds.
|
||
|
|
built() {
|
||
|
|
name=$1
|
||
|
|
set -- "$SRC/bin/$name-$TRIPLE-armv8-a-generic-"*/"$name"
|
||
|
|
[ $# = 1 ] && [ -x "$1" ] || { echo "expected one $name for $TRIPLE under $SRC/bin, found: $*" >&2; exit 1; }
|
||
|
|
echo "$1"
|
||
|
|
}
|
||
|
|
|
||
|
|
echo ">> the executables for $TRIPLE"
|
||
|
|
crafter
|
||
|
|
crafter --product=daemon
|
||
|
|
crafter --product=app ${NOSTRO_GRAPHICS:+"--graphics=$NOSTRO_GRAPHICS"}
|
||
|
|
cli=$(built nostro)
|
||
|
|
daemon=$(built nostrod)
|
||
|
|
app=$(built nostro-app)
|
||
|
|
|
||
|
|
platform=$(withsdk flatpak --user info --show-location --arch="$ARCH" "org.freedesktop.Platform//$RUNTIME_VERSION")/files
|
||
|
|
# Every library an executable and the libraries it carries need is in the Platform or in /app/lib, or the first start
|
||
|
|
# would fail on the phone. And one unwinder: LLVM's libunwind, which the carried libc++abi uses, never the Platform's
|
||
|
|
# libunwind 8 beside it.
|
||
|
|
checked() {
|
||
|
|
files=$1
|
||
|
|
shift
|
||
|
|
missing=0
|
||
|
|
for elf in "$@" "$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
|
||
|
|
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
|
||
|
|
}
|
||
|
|
# What both carry: the C++ runtime they were linked against, and the licences of what is in them, which
|
||
|
|
# packaging/licenses/NOTICE names.
|
||
|
|
carried() {
|
||
|
|
files=$1
|
||
|
|
id=$2
|
||
|
|
mkdir -p "$files/lib"
|
||
|
|
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/flatpak/$id.metainfo.xml" "$files/share/metainfo/$id.metainfo.xml"
|
||
|
|
install -Dm644 -t "$files/share/licenses/$id" "$SRC/LICENSE" "$SRC/LICENSE.GPL" "$SRC/packaging/licenses/NOTICE" \
|
||
|
|
"$SRC/packaging/licenses/nlohmann-json-MIT.txt" "$SRC/packaging/licenses/LLVM-LICENSE.TXT"
|
||
|
|
}
|
||
|
|
# The AppStream catalogue entry software centres list an app by, with PNG icons: appstreamcli's default, JPEG XL, is
|
||
|
|
# not read by older clients.
|
||
|
|
catalogued() {
|
||
|
|
appstreamcli compose --prefix=/ --origin="$2" --image-format=png \
|
||
|
|
--result-root="$1" --data-dir="$1/share/app-info/xmls" --icons-dir="$1/share/app-info/icons/flatpak" "$1"
|
||
|
|
}
|
||
|
|
mkdir -p "$(dirname "$REPO")"
|
||
|
|
|
||
|
|
echo ">> $SERVICE_ID from $cli and $daemon"
|
||
|
|
build="$CACHE/build-service-$ARCH"
|
||
|
|
rm -rf "$build"
|
||
|
|
withsdk flatpak build-init --arch="$ARCH" "$build" "$SERVICE_ID" org.freedesktop.Sdk org.freedesktop.Platform "$RUNTIME_VERSION"
|
||
|
|
files="$build/files"
|
||
|
|
install -Dm755 "$cli" "$files/bin/nostro"
|
||
|
|
install -Dm755 "$daemon" "$files/bin/nostrod"
|
||
|
|
carried "$files" "$SERVICE_ID"
|
||
|
|
checked "$files" "$files/bin/nostro" "$files/bin/nostrod"
|
||
|
|
catalogued "$files" "$SERVICE_ID"
|
||
|
|
# nostrod talks to the bank, and to the bus, logind and polkit on the system bus; the command talks to nostrod there.
|
||
|
|
# As packaging/flatpak/net.catcrafts.Nostrod.yaml has it for x86_64.
|
||
|
|
withsdk flatpak build-finish "$build" --command=nostro --share=network --socket=system-bus
|
||
|
|
withsdk flatpak build-export --arch="$ARCH" "$REPO" "$build" "$BRANCH"
|
||
|
|
|
||
|
|
echo ">> $APP_ID from $app"
|
||
|
|
build="$CACHE/build-app-$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 app finds its fonts and the window library's shaders beside itself.
|
||
|
|
mkdir -p "$files/bin"
|
||
|
|
cp -a "$(dirname "$app")/." "$files/bin/"
|
||
|
|
carried "$files" "$APP_ID"
|
||
|
|
install -Dm644 "$SRC/packaging/flatpak/$APP_ID.desktop" "$files/share/applications/$APP_ID.desktop"
|
||
|
|
install -Dm644 "$SRC/packaging/flatpak/$APP_ID.svg" "$files/share/icons/hicolor/scalable/apps/$APP_ID.svg"
|
||
|
|
install -Dm644 -t "$files/share/licenses/$APP_ID" "$SRC/assets/OFL.txt" "$SRC/packaging/licenses/stb-LICENSE.txt" \
|
||
|
|
"$SRC/packaging/licenses/wayland-protocols-NOTICE.txt" "$SRC/packaging/licenses/Vulkan-Utility-Libraries-Apache-2.0.txt" \
|
||
|
|
"$SRC/packaging/licenses/libevdev-COPYING.txt"
|
||
|
|
checked "$files" "$files/bin/nostro-app"
|
||
|
|
catalogued "$files" "$APP_ID"
|
||
|
|
# The compositor, the graphics device, and nostrod on the system bus; the desktop's portals need no permission. As
|
||
|
|
# project.cpp has it for the x86_64 Flatpak crafter-build makes.
|
||
|
|
withsdk flatpak build-finish "$build" --command=nostro-app --socket=wayland --device=dri --system-talk-name=net.catcrafts.Nostro1
|
||
|
|
withsdk flatpak build-export --arch="$ARCH" "$REPO" "$build" "$BRANCH"
|
||
|
|
echo ">> done: app/$SERVICE_ID/$ARCH/$BRANCH and app/$APP_ID/$ARCH/$BRANCH in $REPO"
|