Nostro/packaging/flatpak/make-aarch64-sysroot.sh
Jorijn van der Graaf 5b4037955b feat(app): add the Nostro app, a window for phones and desktops
Linux phones have no banking apps, and a command line is no answer on a
phone. The app does everything the nostro command does and, like it, only
talks to nostrod: it holds no key and no token.

- Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported
  from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens;
  Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics;
  nostro-app; and Nostro.DebugCommands for the --debug-api build.
- Client: every method also in an asynchronous form for an sd-event loop,
  with DaemonMissing and OutcomeUnknown.
- nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes
  net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both
  Flatpaks cross-built for aarch64, and the licence texts they carry.
- nostro-fake-system, a made-up bus and bank with a real nostrod on them, to
  look at the app against. The README's screenshots are taken on it.
- The nostro command: an API key's environment is the key's own to say, so
  --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL.

The published contract changes in three places, before any release (design
rule 10):
- Transactions' query takes `stored`: answered from what nostrod has stored,
  without asking the bank. The app searches with it; before, every search was
  a call to bunq.
- AddBunq's `environment` no longer chooses over what the key says of itself:
  a key of the other environment is refused.
- SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one
  as DEACTIVATED however well it pays, and leaves it as it is when asked,
  without an error.

The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved
from one to the other (design rule 13). Transaction's schema is unchanged.

Verified: the 17 tests pass with every line, function and region of what they
link run, and the five lint runs are clean. Every screen was looked at on the
made-up system, at a phone's and a desktop's sizes in the light and the dark
look, on Plasma under Wayland. What is said of bunq's cards comes from its
sandbox, with throwaway users, and from one real virtual card. Known to have
been used against production: connecting, and reading accounts, payments and
cards. Not known to have been tried: a payment from the app against bunq,
OAuth against bunq, and anything on a phone.

Building the app takes --graphics=, a Crafter.Graphics checkout on its branch
claude/nostro-app, until that branch is merged and pinned here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 12:27:14 +01:00

138 lines
7.7 KiB
Shell
Executable file

#!/bin/sh
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# make-aarch64-sysroot.sh: what Nostro's aarch64 executables are cross-compiled against, for a phone. crafter-build's
# own Flatpak, which the x86_64 Flatpaks are built with, exists for x86_64 alone, so an aarch64 build is a cross build
# from it against this sysroot: the Freedesktop Sdk for aarch64 (glibc, OpenSSL, libsystemd, Wayland, xkbcommon, udev
# and the Vulkan loader, the libraries the Platform runtime has at run time) plus LLVM's libc++ of the release
# crafter-build itself carries, built for aarch64, which the runtime does not have.
#
# packaging/flatpak/make-aarch64-sysroot.sh
#
# Everything goes under $NOSTRO_FLATPAK_CACHE (default ${XDG_CACHE_HOME:-~/.cache}/nostro-flatpak), outside /tmp, which
# the crafter-build sandbox does not share:
# installation/ a flatpak installation of the aarch64 Sdk and Platform (build-aarch64.sh builds the apps on it)
# sysroot-aarch64/ the Sdk's files as usr/, with libc++ added
# libcxx-aarch64/ libc++, libc++abi and libunwind as installed, which the Flatpaks carry in /app/lib
# A sysroot made from the same Sdk commit, LLVM release and recipe is kept.
#
# Needs flatpak, flock, curl, tar, xz and sha256sum; crafter-build ($CRAFTER_REF, the Crafter.Build Flatpak) provides
# clang, cmake and ninja. Network: Flathub and the LLVM release on GitHub.
set -eu
ARCH=aarch64
TRIPLE=aarch64-unknown-linux-gnu
MULTIARCH=aarch64-linux-gnu
MARCH=armv8-a
RUNTIME_VERSION=26.08
# The LLVM release crafter-build itself carries, whose std module source it ships. The tarball and hash are the ones
# Crafter.Build's manifest builds that LLVM from.
LLVM_VERSION=23.1.2
LLVM_SHA256=c98bbef08a2b4c2613cd50e9aa9ae7b69b1fe6c16b2c40373bc0ab6116fdf78a
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"
# The Sdk and the Platform for aarch64 go into a flatpak installation of their own; crafter-build is run from wherever
# it is installed.
sdkpak() { FLATPAK_USER_DIR="$INSTALLATION" flatpak --user "$@"; }
# Flathub's CDN answers 502 now and then, and flatpak reports a summary it could not fetch as a runtime that does not
# exist.
retry() {
for attempt in 1 2 3 4 5; do
"$@" && return 0
echo "attempt $attempt of 5 failed: $*" >&2
[ "$attempt" = 5 ] || sleep 30
done
return 1
}
mkdir -p "$CACHE"
# One run at a time on this cache: the sysroot and the LLVM build are removed and made again by a run that finds them
# stale.
exec 9>"$CACHE/lock"; flock 9
echo ">> the $ARCH Sdk and Platform $RUNTIME_VERSION into $INSTALLATION"
retry sdkpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
retry sdkpak install -y --noninteractive --no-related --arch="$ARCH" flathub \
"org.freedesktop.Sdk//$RUNTIME_VERSION" "org.freedesktop.Platform//$RUNTIME_VERSION"
retry sdkpak update -y --noninteractive --no-related --arch="$ARCH"
sdk=$(sdkpak info --show-location --arch="$ARCH" "org.freedesktop.Sdk//$RUNTIME_VERSION")
sdk_commit=$(sdkpak info --show-commit --arch="$ARCH" "org.freedesktop.Sdk//$RUNTIME_VERSION")
# A sysroot is kept while the Sdk commit, the LLVM release and this recipe stay the same.
stamp="sdk $sdk_commit llvm $LLVM_VERSION recipe $(sha256sum "$0" | cut -c1-16)"
if [ -f "$SYSROOT/.made-from" ] && [ "$(cat "$SYSROOT/.made-from")" = "$stamp" ] && [ -f "$LIBCXX/usr/lib/libc++.so.1" ]; then
echo ">> $SYSROOT is current ($stamp)"
exit 0
fi
echo ">> $SYSROOT from the Sdk at $sdk_commit"
rm -rf "$SYSROOT" "$LIBCXX"
mkdir -p "$SYSROOT"
# A copy: libc++ is installed into it, and the installation's files are hard links into its object store.
cp -a --reflink=auto "$sdk/files" "$SYSROOT/usr"
# Linker scripts and the dynamic linker's path name /lib.
ln -s usr/lib "$SYSROOT/lib"
# libc++'s linker script adds -lunwind, which would find the Sdk's libunwind 8 (in the multiarch directory, searched
# first) beside the LLVM libunwind its libc++abi uses: without the Sdk's link name it finds LLVM's.
rm "$SYSROOT/usr/lib/$MULTIARCH/libunwind.so"
src="$CACHE/llvm-project-$LLVM_VERSION.src"
tarball="$CACHE/llvm-project-$LLVM_VERSION.src.tar.xz"
if [ ! -d "$src/runtimes" ] || [ ! -d "$src/libc/shared" ]; then
echo ">> LLVM $LLVM_VERSION's runtimes source"
retry curl -fsSL -o "$tarball" "https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/llvm-project-$LLVM_VERSION.src.tar.xz"
got=$(sha256sum "$tarball" | cut -d' ' -f1)
[ "$got" = "$LLVM_SHA256" ] || { echo "llvm-project-$LLVM_VERSION.src.tar.xz: sha256 $got, expected $LLVM_SHA256" >&2; exit 1; }
rm -rf "$src" "$src.part"
mkdir -p "$src.part"
# Only part of the tree is unpacked; libc is among it because libc++'s from_chars parses floating point with LLVM
# libc's shared headers. It lands under $src only once complete: a tar cut short leaves nothing a later run would
# take for the source.
tar -xJf "$tarball" -C "$src.part" --strip-components=1 \
"llvm-project-$LLVM_VERSION.src/runtimes" "llvm-project-$LLVM_VERSION.src/libcxx" \
"llvm-project-$LLVM_VERSION.src/libcxxabi" "llvm-project-$LLVM_VERSION.src/libunwind" \
"llvm-project-$LLVM_VERSION.src/cmake" "llvm-project-$LLVM_VERSION.src/llvm/cmake" \
"llvm-project-$LLVM_VERSION.src/llvm/utils" "llvm-project-$LLVM_VERSION.src/third-party" \
"llvm-project-$LLVM_VERSION.src/libc"
mv "$src.part" "$src"
rm -f "$tarball"
fi
echo ">> libc++, libc++abi and libunwind $LLVM_VERSION for $TRIPLE"
build="$CACHE/libcxx-build-$ARCH"
rm -rf "$build"
# The classic layout (include/c++/v1, lib/) is where crafter-build looks in a sysroot. libc++abi unwinds with LLVM's
# libunwind, as crafter-build's own libc++ does. Programs come from the sandbox, never from the sysroot: the Sdk's own
# ninja and tools are aarch64 binaries. The C++ compiler cannot link a test program before there is a libc++ to link;
# the C compiler's check still runs.
flatpak run --command=sh "$CRAFTER_REF" -eu -c '
cmake -S "$1/runtimes" -B "$2" -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR="$3" \
-DCMAKE_SYSROOT="$4" \
-DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
-DCMAKE_C_COMPILER=/app/bin/clang -DCMAKE_CXX_COMPILER=/app/bin/clang++ -DCMAKE_ASM_COMPILER=/app/bin/clang \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DCMAKE_C_COMPILER_TARGET="$5" -DCMAKE_CXX_COMPILER_TARGET="$5" -DCMAKE_ASM_COMPILER_TARGET="$5" \
-DCMAKE_AR=/app/bin/llvm-ar -DCMAKE_RANLIB=/app/bin/llvm-ranlib -DCMAKE_NM=/app/bin/llvm-nm \
-DCMAKE_C_FLAGS="-march=$6" -DCMAKE_CXX_FLAGS="-march=$6" \
-DCMAKE_INSTALL_PREFIX="$7/usr" \
"-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind" \
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
-DLIBCXX_INSTALL_MODULES=ON \
-DLLVM_INCLUDE_TESTS=OFF -DLIBCXX_INCLUDE_TESTS=OFF -DLIBCXXABI_INCLUDE_TESTS=OFF \
-DLIBUNWIND_INCLUDE_TESTS=OFF -DLIBCXX_INCLUDE_BENCHMARKS=OFF
ninja -C "$2" install
' sh "$src" "$build" "$ARCH" "$SYSROOT" "$TRIPLE" "$MARCH" "$LIBCXX"
rm -rf "$build"
grep -q "_LIBCPP_VERSION 230102" "$LIBCXX/usr/include/c++/v1/__config" || { echo "the installed libc++ headers are not $LLVM_VERSION" >&2; exit 1; }
cp -a "$LIBCXX/usr/." "$SYSROOT/usr/"
echo "$stamp" > "$SYSROOT/.made-from"
echo ">> done: $SYSROOT ($stamp)"