Skip to content

[rebuilder.lib.sh] Fix the cargo toolchain check, and cap librespot's build parallelism - #28

Open
Gjuju wants to merge 4 commits into
moode-player:mainfrom
Gjuju:feat/rebuilder-cargo-check
Open

[rebuilder.lib.sh] Fix the cargo toolchain check, and cap librespot's build parallelism#28
Gjuju wants to merge 4 commits into
moode-player:mainfrom
Gjuju:feat/rebuilder-cargo-check

Conversation

@Gjuju

@Gjuju Gjuju commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Two independent failures on the on-demand librespot build, one fix each.
Measured on Pi 3B, 3B+, 3A+, Zero 2 W, Pi 4 and Pi 5, all rustc 1.96.0.

rbl_check_cargo never finds an existing toolchain

It looked under /home/pi. Since Bookworm the account is created at first
boot, so on a device whose user is not pi the check finds nothing: every CLI
build re-downloads the whole toolchain and cargo-deb, installs it into
$HOME/.cargo, and finds nothing again on the next run. Verified on a Trixie
device where /home/pi does not exist.

CARGO_HOME is now derived once for both contexts — $HOME/.cargo for user
builds, /root/.cargo for the on-demand install spawned by the worker — and
every step works off it. Along the way:

  • prepend the cargo bin dir to PATH, so a distro /usr/bin/rustc cannot
    shadow the pinned one and trigger a reinstall on every build
  • remove a leftover CARGO_HOME that has no rustup left in it to uninstall
    with, which rustup-init refuses to install over
  • re-check the version after installing and exit 1 on mismatch: the pin exists
    to avoid the 1.97 segfaults

Checked as both user and root for: nothing installed, pinned version already
installed, wrong version installed, leftover CARGO_HOME, and an install that
yields the wrong version.

Low-RAM boards

Jobs. cargo defaults to one rustc per core. On a 1 GB Pi 3B that stacks
four rustc and drives the board into SD thrash. Budget 512 MB per parallel
rustc, clamped to [1, nproc]; an explicit CARGO_BUILD_JOBS still wins.
One board, one variable:

jobs time written to card
1 53m10 1931 MB
2 39m42 3635 MB
3 39m26 4705 MB

Two is the knee — a third job saves 16 s and writes 29% more.

Stack. On aarch64 a codegen worker thread can overflow its stack and take
rustc down with SIGSEGV inside LLVM while compiling librespot-protocol. It is
not the OOM killer and not governed by the job count, so it strikes at random.
RUST_MIN_STACK=16777216 is the remedy rustc's own diagnostic suggests, and it
costs no measurable time: the same board run twice, once each way, gave 21m19
against 21m16 on a Pi 4 and 7m13 against 7m12 on a Pi 5.

Together they bring back builds that had stopped completing: a Pi 3A+ and a
Zero 2 W (512 MB) finish at one job, and a 1 GB Pi 3B+ that had failed several
attempts finished the same way. Not a guarantee — one 512 MB board has still
failed with both applied.

rbl_check_cargo is shared, so pleezer and camilladsp get the raised stack too
when they are built. The job budget stays in packages/librespot/build.sh,
where it was measured, and where the build runs on the user's own board.

@Gjuju
Gjuju force-pushed the feat/rebuilder-cargo-check branch from 714b3d1 to d402d46 Compare August 4, 2026 09:08
Gjuju and others added 4 commits August 5, 2026 10:49
…heck_cargo

Two issues in rbl_check_cargo:

- PATH was appended with the cargo bin dir, so on a build machine that
  also has the distro rust package installed, /usr/bin/rustc shadows the
  rustup one. The version check then never matches RUSTC_PIN_VERSION and
  the toolchain is uninstalled and reinstalled on every single build.
  Prepending the cargo bin dir makes the rustup toolchain win.

- Nothing verified the result of the install. If rustup fails or ends up
  serving a different toolchain, the build silently continues with the
  wrong rustc, which is exactly what pinning 1.96.0 is meant to prevent
  (the 1.97 segfaults). Re-check the version after the install block and
  exit 1 on mismatch, as the pre-refactor code did.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…texts

rbl_check_cargo looked for the toolchain under /home/pi when the build
runs as a user. Since Bookworm the account is created at first boot, so
on a device whose user is not pi the check never finds the install: every
CLI build re-downloads the whole toolchain and cargo-deb, installs it
into $HOME/.cargo, and finds nothing again on the next run. Verified on a
Trixie device where /home/pi does not exist.

Derive CARGO_HOME once for both contexts instead, and drive every step
off it, so detection, cleanup, install and verification all agree on a
single location:

- user builds use $HOME/.cargo, root builds (the on-demand librespot
  install spawned by the moode worker) stay on /root/.cargo, spelled out
  because the worker does not necessarily export HOME
- query $CARGO_HOME/bin/rustc by full path, so the version read is the
  toolchain we manage and not some other rustc on the machine, and
  prepend the cargo bin dir to PATH for the same reason
- remove a leftover CARGO_HOME that has no rustup left in it to uninstall
  with, otherwise rustup-init will not install over it
- re-check the version after installing and exit 1 on mismatch: the pin
  is there to avoid the 1.97 segfaults, so a build with the wrong
  toolchain should not silently proceed

Behaviour verified for the states: nothing installed, pinned version
already installed (no download), wrong version installed (uninstall then
reinstall), leftover CARGO_HOME, and an install that yields the wrong
version (exits 1). Checked as both user and root on the device.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
cargo defaults to one rustc per core. On a 1GB Pi 3B+ that stacks 4
rustc, saturates RAM and drives the board into SD I/O thrash: 81min,
1.8GB swap, load ~10, and two crash/reboots. One job per ~1GB of RAM
instead: 73min, 782MB swap, load ~2, no crashes.
…SIGSEGV

Set RUST_MIN_STACK in rbl_check_cargo, next to the rest of the rust
environment, so every cargo build started from here gets it. Honours a
value already in the environment.
@Gjuju
Gjuju force-pushed the feat/rebuilder-cargo-check branch from d402d46 to 63329a0 Compare August 5, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant