-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbuild-flipctl.sh
More file actions
executable file
·92 lines (83 loc) · 4.86 KB
/
Copy pathbuild-flipctl.sh
File metadata and controls
executable file
·92 lines (83 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# build-flipctl.sh [<checkout> [<staging dir>]] - build flipctl for the image.
#
# Stages the tree the ospack overlays onto /usr: bin/flipctl, its remote-view assets
# under share/flipctl, and the four files the repository ships in systemd/, which are
# the unit and the three things it cannot start without. Called by build-ospack.sh once
# it has the checkout.
#
# No apps. The image ships none: flipctl's app manager lists what the catalogue offers
# and downloads what somebody asks for, into the user's own Apps folder. That replaced
# both of the things this used to do, shipping the radio built and shipping every other
# app as sources for the device to compile, and with them the framework and fonts that
# an on-device build needed.
#
# Native on an arm64 builder, cross anywhere else. Nothing here links a C library (EGL
# and GBM are dlopened, wayland-client uses its Rust backend, slint renders in software),
# so a cross build needs the aarch64 std and a linker and nothing else.
: "${FLIPCTL_DIR:=src/flipctl}"
: "${FLIPCTL_OUT:=prebuilt/flipctl}"
: "${FLIPCTL_FEATURES:=device,slint,remote,wayland,gpu}"
set -e
SRC=${1:-$FLIPCTL_DIR}
OUT=${2:-$FLIPCTL_OUT}
PKG=flipctl
[ -d "$SRC" ] || { echo "build-flipctl: no checkout at $SRC" >&2; exit 1; }
command -v cargo >/dev/null || { echo "build-flipctl: cargo not found" >&2; exit 1; }
# slint 1.17.1 sets the floor. An older cargo gets there through the resolver instead,
# a hundred lines of "requires rustc" for every crate in the graph, so check it here.
MSRV=92
ver=$(cargo --version 2>/dev/null | awk '{print $2}')
case "$ver" in 1.*) minor=${ver#1.}; minor=${minor%%.*} ;; *) minor=0 ;; esac
case "$minor" in ''|*[!0-9]*) minor=0 ;; esac
if [ "$minor" -lt "$MSRV" ]; then
echo "build-flipctl: cargo ${ver:-unknown} is too old; flipctl needs 1.$MSRV (slint 1.17.1)" >&2
echo "build-flipctl: on Debian, apt-get install -t trixie-backports cargo rustc libstd-rust-dev" >&2
exit 1
fi
# Cross unless the builder is already arm64. Passing --target on an arm64 builder too
# would flatten this, at the cost of cargo building every proc macro and build script for
# the host separately from the target, which is the slint compiler twice over.
TARGET_ARG=()
if [ "$(uname -m)" != aarch64 ]; then
TARGET=aarch64-unknown-linux-gnu
TARGET_ARG=(--target "$TARGET")
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
# a toolchain carries the host's standard library and no other, and without the
# target's the build fails a long way in with "can't find crate for std"
[ -d "$(rustc --print sysroot)/lib/rustlib/$TARGET" ] || {
echo "build-flipctl: no std for $TARGET" >&2
echo "build-flipctl: on Debian, apt-get install libstd-rust-dev:arm64" >&2
exit 1
}
fi
# cargo install builds and places the binary in one step, and --root makes the staging
# tree what it installs into: bin/flipctl, already the install layout, so the ospack
# overlays it and moves nothing afterwards. --no-track keeps the .crates.toml it would
# leave beside it out of a tree that becomes /usr, --target-dir keeps the build cache in
# the checkout rather than the temporary directory cargo install builds in and throws
# away, and --locked pins what cargo build would: this is the one cargo command that
# ignores a lockfile unless told not to.
rm -rf "$OUT"
cargo install --path "$SRC/bin/$PKG" --root "$OUT" --no-track --locked \
--target-dir "$SRC/target" "${TARGET_ARG[@]}" --features "$FLIPCTL_FEATURES"
# The browser view's own files: the device photo it draws the panel into.
mkdir -p "$OUT/share/flipctl/assets"
cp -a "$SRC/crates/flipper-ui/assets/remote" "$OUT/share/flipctl/assets/remote"
# The unit ships from the repository, not a copy in overlays/, so a deploy from a
# checkout restarts the same unit the image boots.
install -D -m 644 "$SRC/systemd/flipctl.service" "$OUT/lib/systemd/system/flipctl.service"
# What the unit needs in place before it can start, staged into the vendor paths under
# /usr rather than /etc, which is where a deploy onto a running system writes them.
#
# The group is the one that bites: SupplementaryGroups names `gpio`, and systemd
# refuses to start a unit naming a group that does not exist, with 216/GROUP and
# nothing on the panel. sysusers creates it at boot, the udev rule hands the gpiochip
# and spidev nodes to it, and the module list registers the device classes the unit's
# DeviceAllow lines resolve by name when it starts.
install -D -m 644 "$SRC/systemd/flipctl.sysusers.conf" "$OUT/lib/sysusers.d/flipctl.conf"
install -D -m 644 "$SRC/systemd/70-flipctl-devices.rules" \
"$OUT/lib/udev/rules.d/70-flipctl-devices.rules"
install -D -m 644 "$SRC/systemd/flipctl-devices.conf" \
"$OUT/lib/modules-load.d/flipctl-devices.conf"
echo "build-flipctl: staged $(du -sh "$OUT" | cut -f1) in $OUT"