`cuprate-daemon` is a default feature, so `cargo test --locked` in the Pi CI job compiles `tapes`. That crate calls `VecDeque::pop_front_if`, stable only since 1.93. `rust:1.91-bookworm` dies with `error[E0658]: use of unstable library feature 'vec_deque_pop_if'` after the rest of the graph has already built. The Android workflows were already on 1.98 for this; ci.yml and release.yml were left on 1.91 when the feature was off, and that is no longer true. `rust-version` moves with the image. cargo checks it before features, so a 1.91 compiler must be refused up front instead of fifteen minutes into `tapes`. `--no-default-features` would still compile on 1.91; the declared floor is the default build's floor, which is what CI and `cargo build` run.
339 lines
18 KiB
YAML
339 lines
18 KiB
YAML
name: android-ci
|
|
|
|
# Android changes had no CI at all: ci.yml's path allowlist (src/**, crates/**,
|
|
# tests/**, Cargo.toml, Cargo.lock, ci.yml) never matches android/**, and
|
|
# android-release.yml is dispatch/tag-driven — so an android-only PR ran zero
|
|
# jobs and merged on an empty check list. This is the android side of CI.
|
|
#
|
|
# It builds the same gradle targets the release builds through the same script
|
|
# android-release.yml calls (scripts/build-android-local.sh): `:sdk:assembleRelease`
|
|
# + `:app:assembleRelease`, Rust for aarch64-linux-android via cargo-ndk, UniFFI
|
|
# bindings, APK packaging with the .so. The only difference from a release is
|
|
# signing: ONIONWIRE_REQUIRE_RELEASE_KEY=false and no release keystore, so
|
|
# Gradle falls back to the debug key. Nothing here is signed for release,
|
|
# nothing is published, no tag is touched.
|
|
#
|
|
# Why a separate workflow instead of android/** added to ci.yml: the only way
|
|
# to keep the Rust jobs from running on android-only diffs is job-level change
|
|
# detection, and a gate that mis-detects hands out a green check for a suite
|
|
# that never ran. Here the runner's own paths filter decides — same mechanism
|
|
# ci.yml already uses.
|
|
#
|
|
# The two triggers differ on purpose, and the asymmetry is the whole point of
|
|
# the `src/**` entry below:
|
|
#
|
|
# pull_request — the client and the SDK binding surface. NOT `src/**`. A
|
|
# Rust-only PR does change the bytes in `libonionwire_sdk.so`, but proving
|
|
# that costs a ~11 minute full APK build, and 95 of 143 recorded runs
|
|
# touched no `android/` file at all. The in-APK checks that actually earn
|
|
# their keep (the `target_max_memory` marker gate, the `.so` listing, the
|
|
# sha256 round-trip) still run on every merge via the push trigger, so
|
|
# nothing reaches a release untested — a Rust PR just finds out at merge
|
|
# instead of before it. If a Rust change ever breaks the Android build
|
|
# specifically, add its path here rather than re-adding all of `src/**`.
|
|
#
|
|
# push: [main] — every Rust or Android change, every merge. This is the
|
|
# safety net, and it is why the trigger cannot simply mirror the PR one.
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- "android/**"
|
|
- "crates/**"
|
|
- "src/**"
|
|
- "Cargo.toml"
|
|
- "Cargo.lock"
|
|
- "scripts/build-android-local.sh"
|
|
- ".forgejo/workflows/android-ci.yml"
|
|
pull_request:
|
|
paths:
|
|
- "android/**"
|
|
- "crates/onionwire-sdk/**"
|
|
- "Cargo.toml"
|
|
- "Cargo.lock"
|
|
- "scripts/build-android-local.sh"
|
|
- ".forgejo/workflows/android-ci.yml"
|
|
workflow_dispatch:
|
|
|
|
# Deliberately the SAME group and the SAME volumes as android-release.yml: the
|
|
# APK build is ~9 min with warm volumes (SDK/NDK, cargo registry, cargo target,
|
|
# Gradle cache) and a cold copy of those is over a gigabyte of downloads per
|
|
# runner. Serializing the two workflows by group name is what keeps them off
|
|
# each other's volumes.
|
|
concurrency:
|
|
group: onionwire-android-release-v2
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: never
|
|
CARGO_BUILD_JOBS: "1"
|
|
ONIONWIRE_ANDROID_ABI: arm64-v8a
|
|
ANDROID_IMAGE: debian:bookworm
|
|
ANDROID_CMDLINE_TOOLS_URL: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
|
|
# Same floor as ci.yml and release.yml (`rust:1.98-bookworm`). The cuprated
|
|
# graph needs >= 1.93 (`tapes` calls `VecDeque::pop_front_if`); 1.91 dies with
|
|
# `error[E0658]: use of unstable library feature 'vec_deque_pop_if'`. 1.98 is
|
|
# the stable release this graph is built and tested with.
|
|
RUST_TOOLCHAIN: "1.98"
|
|
DOCKER_STATIC_URL: https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz
|
|
# Distinct container prefix: run ids are per-workflow, so this workflow and
|
|
# android-release.yml can both be holding a container named "<prefix>-<n>".
|
|
BUILD_CONTAINER: onionwire-android-ci-${{ github.run_id }}
|
|
SDK_VOLUME: onionwire-android-sdk
|
|
CARGO_VOLUME: onionwire-android-cargo-registry
|
|
TARGET_VOLUME: onionwire-android-target
|
|
GRADLE_VOLUME: onionwire-android-gradle
|
|
|
|
jobs:
|
|
android:
|
|
runs-on: docker-amd64
|
|
timeout-minutes: 120
|
|
steps:
|
|
- name: Checkout
|
|
uses: https://code.forgejo.org/actions/checkout@v4
|
|
|
|
- name: Skip superseded run
|
|
id: staleness
|
|
run: |
|
|
set -uo pipefail
|
|
# Same gate as ci.yml: a newer commit on this branch while this run
|
|
# sat in the shared android concurrency queue makes the ~11 minute
|
|
# APK build a proof of nothing. `origin` is anonymously readable
|
|
# here, and a failed lookup runs the job rather than skipping it.
|
|
ref="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}"
|
|
remote=""
|
|
if [ -n "$ref" ]; then
|
|
remote="$(git ls-remote origin "refs/heads/$ref" 2>/dev/null | cut -f1)"
|
|
fi
|
|
if [ -n "$remote" ] && [ "$remote" != "$GITHUB_SHA" ]; then
|
|
echo "::notice::superseded: refs/heads/$ref is at ${remote:0:12}, this run is ${GITHUB_SHA:0:12} — skipping"
|
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "tip=${remote:-unknown} sha=${GITHUB_SHA} ref=${ref:-none} — running"
|
|
echo "skip=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Record runner resources
|
|
if: steps.staleness.outputs.skip != 'true'
|
|
run: |
|
|
set -euo pipefail
|
|
cd "${GITHUB_WORKSPACE}"
|
|
echo "workspace=$GITHUB_WORKSPACE hostname=$(hostname) arch=$(uname -m)"
|
|
nproc || true
|
|
free -h || true
|
|
df -h || true
|
|
ls -l /var/run/docker.sock || true
|
|
|
|
- name: Ensure docker CLI
|
|
if: steps.staleness.outputs.skip != 'true'
|
|
run: |
|
|
set -euo pipefail
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "docker CLI missing in job image; fetching static client"
|
|
curl -fsSL "$DOCKER_STATIC_URL" -o /tmp/docker.tgz
|
|
tar -xzf /tmp/docker.tgz -C /tmp
|
|
install -m 755 /tmp/docker/docker /usr/local/bin/docker
|
|
fi
|
|
export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}"
|
|
docker version
|
|
docker info >/tmp/docker-info.txt
|
|
grep -E 'Server Version|Operating System|Total Memory|Name' /tmp/docker-info.txt || true
|
|
|
|
- name: Build APK + AAR (debug-signed) in bookworm container
|
|
id: build
|
|
if: steps.staleness.outputs.skip != 'true'
|
|
run: |
|
|
set -euo pipefail
|
|
cd "${GITHUB_WORKSPACE}"
|
|
export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}"
|
|
start=$(date +%s)
|
|
cat > .ci-android-verify.sh <<'INNER'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update
|
|
# `cmake` is for RandomX, the C++ half of the in-process chain daemon:
|
|
# without it `randomx-rs`'s build script panics with "failed to execute
|
|
# command: No such file or directory … is `cmake` not installed?" and the
|
|
# Gradle task dies on "cargo finished with non-zero exit value 101".
|
|
apt-get install -y --no-install-recommends \
|
|
openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git \
|
|
cmake
|
|
if [ ! -x /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager ]; then
|
|
mkdir -p /opt/android-sdk/cmdline-tools
|
|
curl -fsSL "$ANDROID_CMDLINE_TOOLS_URL" -o /tmp/cmdline-tools.zip
|
|
rm -rf /tmp/cmdline-tools
|
|
unzip -q /tmp/cmdline-tools.zip -d /tmp/cmdline-tools
|
|
mkdir -p /opt/android-sdk/cmdline-tools/latest
|
|
cp -a /tmp/cmdline-tools/cmdline-tools/. /opt/android-sdk/cmdline-tools/latest/
|
|
fi
|
|
yes | /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager --sdk_root=/opt/android-sdk --licenses >/tmp/sdk-licenses.log || true
|
|
/opt/android-sdk/cmdline-tools/latest/bin/sdkmanager --sdk_root=/opt/android-sdk \
|
|
"platform-tools" "platforms;android-36" "build-tools;36.0.0" "ndk;28.2.13676358"
|
|
test -d /opt/android-sdk/ndk/28.2.13676358
|
|
export ANDROID_HOME=/opt/android-sdk ANDROID_SDK_ROOT=/opt/android-sdk
|
|
export ANDROID_NDK_HOME=/opt/android-sdk/ndk/28.2.13676358
|
|
export PATH="$ANDROID_HOME/build-tools/36.0.0:$ANDROID_HOME/platform-tools:$PATH"
|
|
if [ ! -x /cargo/bin/rustup ]; then
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" --no-modify-path --profile minimal
|
|
fi
|
|
export PATH="/cargo/bin:$PATH"
|
|
rustup toolchain install "$RUST_TOOLCHAIN"
|
|
rustup default "$RUST_TOOLCHAIN"
|
|
rustup target add aarch64-linux-android
|
|
command -v cargo-ndk >/dev/null || cargo install cargo-ndk --locked
|
|
echo "=== toolchain ==="
|
|
java -version
|
|
rustc --version
|
|
cargo ndk --version
|
|
du -sh /opt/android-sdk /cargo /cargo-target /gradle || true
|
|
# Shared /gradle volume: a killed container leaves journal-1.lock.
|
|
# android/gradle.properties also sets org.gradle.parallel=true, which
|
|
# is how two JVMs (PIDs ~5 apart) show up on one lock. Drop the
|
|
# stale locks and force one Gradle process for this container.
|
|
find /gradle -name '*.lock' -type f -delete 2>/dev/null || true
|
|
export GRADLE_OPTS="${GRADLE_OPTS:-} -Dorg.gradle.parallel=false -Dorg.gradle.daemon=false"
|
|
# No keystore here on purpose: this is a verification build, not a
|
|
# release build. The script warns that Gradle fell back to the debug
|
|
# key; that warning is expected in this job.
|
|
scripts/build-android-local.sh
|
|
version="$(python3 - <<'PY'
|
|
import re, pathlib
|
|
t = pathlib.Path('android/app/build.gradle.kts').read_text()
|
|
m = re.search(r'versionName\s*=.*?:\s*"([^"]+)"', t)
|
|
print(m.group(1) if m else '')
|
|
PY
|
|
)"
|
|
abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}"
|
|
apk="dist/onionwire-$version-android-$abi.apk"
|
|
aar="dist/onionwire-sdk-$version.aar"
|
|
{
|
|
echo "=== file ==="
|
|
file "$apk" "$aar"
|
|
echo "=== unzip lib ==="
|
|
unzip -l "$apk" | grep -E 'lib/.+\.so' || true
|
|
unzip -l "$apk" | grep "lib/$abi/libonionwire_sdk.so"
|
|
# `unzip -l` shows the uncompressed size only; the *deflated* entry is
|
|
# what the download actually costs, and it is not visible anywhere else
|
|
# (v0.7.0's SDK lib was 33,481,336 B raw / 12,210,154 B deflated, which
|
|
# is the ratio a reader wants when this one grows).
|
|
echo "=== native lib entries (length / method / deflated) ==="
|
|
unzip -v "$apk" | grep -E 'lib/.+\.so$'
|
|
echo "=== in-process chain daemon (cuprate-daemon) is IN this APK ==="
|
|
# The build log's "features=cuprate-daemon" line says the feature was
|
|
# *requested*; this says it is *in the artifact*. `target_max_memory` is
|
|
# a rodata literal from src/cuprate.rs's config TOML, compiled only under
|
|
# `#[cfg(feature = "cuprate-daemon")]` — v0.7.0's libonionwire_sdk.so
|
|
# contains zero occurrences of it (checked), so its presence is the
|
|
# difference between a build that carries the daemon and one that only
|
|
# claims to. A missing marker fails the job: an APK whose on-device node
|
|
# can only fail is the regression this gate exists to catch.
|
|
unzip -p "$apk" "lib/$abi/libonionwire_sdk.so" > /tmp/libonionwire_sdk.so
|
|
# `grep -c`, deliberately not `grep -q`: under `set -o pipefail` a `-q`
|
|
# match closes the pipe early, `strings` dies on SIGPIPE (141), and the
|
|
# pipeline then reports failure even though the marker was there — this
|
|
# gate failed its own green build once that way.
|
|
marker="$(strings -a /tmp/libonionwire_sdk.so | grep -c 'target_max_memory' || true)"
|
|
echo "target_max_memory occurrences: ${marker:-0}"
|
|
if [ "${marker:-0}" -lt 1 ]; then
|
|
echo "lib/$abi/libonionwire_sdk.so carries no cuprated config string: the cuprate-daemon feature is NOT in this APK" >&2
|
|
exit 1
|
|
fi
|
|
echo "=== classes.dex + Compose entrypoints ==="
|
|
unzip -l "$apk" | grep -E 'classes[0-9]*\.dex' | head -n3
|
|
echo "=== sha256 ==="
|
|
# `sha256sum -c` proves each artifact matches the digest the build
|
|
# recorded, but prints neither number. The digest *is* the artifact's
|
|
# identity, and an APK is not byte-reproducible across machines, so it
|
|
# cannot be derived from the tree afterwards — echo both.
|
|
cat "dist/onionwire-$version-android-$abi.apk.sha256" "dist/onionwire-sdk-$version.aar.sha256"
|
|
( cd dist && sha256sum -c "onionwire-$version-android-$abi.apk.sha256" "onionwire-sdk-$version.aar.sha256" )
|
|
echo "=== apksigner (expect debug cert: this is a verification build) ==="
|
|
apksigner verify --print-certs "$apk" | sed -n '1,6p'
|
|
echo "=== aapt ==="
|
|
aapt dump badging "$apk" | sed -n '1,20p' || true
|
|
echo "=== sizes ==="
|
|
wc -c "$apk" "$aar"
|
|
# The cross-compile volume this build just grew. The cuprated graph is
|
|
# ~152 crates plus a C++ RandomX build, so the number is the disk cost
|
|
# of the feature on the runner, next to the wall clock above.
|
|
echo "=== cargo target volume (after this build) ==="
|
|
du -sh /cargo-target 2>/dev/null || true
|
|
du -sh /cargo-target/aarch64-linux-android/release 2>/dev/null || true
|
|
} | tee dist/android-ci-verify.log
|
|
INNER
|
|
chmod +x .ci-android-verify.sh
|
|
docker volume create "$SDK_VOLUME" >/dev/null
|
|
docker volume create "$CARGO_VOLUME" >/dev/null
|
|
docker volume create "$TARGET_VOLUME" >/dev/null
|
|
docker volume create "$GRADLE_VOLUME" >/dev/null
|
|
# Cancelled jobs never reach the trailing `docker rm`, so a previous
|
|
# onionwire-android-* container can still hold GRADLE_VOLUME. The next
|
|
# Gradle then dies LockTimeoutException on /gradle/caches/journal-1
|
|
# (owner PID vs our PID a few numbers apart — two JVMs, one volume).
|
|
trap 'docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true' EXIT
|
|
docker ps -aq --filter name=onionwire-android- | xargs -r docker rm -f || true
|
|
docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true
|
|
docker pull "$ANDROID_IMAGE"
|
|
# 2 GB of Gradle heap, not 1: the only budget in this build that is close
|
|
# is the single-use daemon's heap, which now has to package a 55 MB SDK
|
|
# lib (plus RandomX's 1.1 MB) through AGP's in-daemon packaging. Run 414
|
|
# died in `:app:packageRelease` with the cause hidden inside
|
|
# `PackageAndroidArtifact$IncrementalSplitterRunnable` — no "Caused by"
|
|
# line, nothing in the log — so give it room instead of guessing again.
|
|
# The runner has 15 GB and the job's peak RSS is ~3 GB.
|
|
docker create --name "$BUILD_CONTAINER" -i \
|
|
-e CARGO_TERM_COLOR=never \
|
|
-e CARGO_BUILD_JOBS="$CARGO_BUILD_JOBS" \
|
|
-e CARGO_HOME=/cargo \
|
|
-e CARGO_TARGET_DIR=/cargo-target \
|
|
-e GRADLE_USER_HOME=/gradle \
|
|
-e ANDROID_HOME=/opt/android-sdk \
|
|
-e ANDROID_SDK_ROOT=/opt/android-sdk \
|
|
-e ANDROID_NDK_HOME=/opt/android-sdk/ndk/28.2.13676358 \
|
|
-e ONIONWIRE_ANDROID_ABI="$ONIONWIRE_ANDROID_ABI" \
|
|
-e ONIONWIRE_REQUIRE_RELEASE_KEY=false \
|
|
-e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \
|
|
-e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \
|
|
-e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
|
|
-v "$SDK_VOLUME":/opt/android-sdk \
|
|
-v "$CARGO_VOLUME":/cargo \
|
|
-v "$TARGET_VOLUME":/cargo-target \
|
|
-v "$GRADLE_VOLUME":/gradle \
|
|
-w /src \
|
|
"$ANDROID_IMAGE" \
|
|
bash -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src && bash /src/.ci-android-verify.sh'
|
|
tar czf - \
|
|
--exclude=./target --exclude=./.git --exclude=./.worktrees \
|
|
--exclude=./android/.gradle --exclude=./android/app/build \
|
|
--exclude=./android/sdk/build --exclude=./dist \
|
|
--exclude=./crates/onionwire-sdk/target \
|
|
. \
|
|
| docker start -a -i "$BUILD_CONTAINER"
|
|
mkdir -p dist
|
|
docker cp "$BUILD_CONTAINER:/src/dist/." dist/
|
|
end=$(date +%s)
|
|
echo "build_wall_clock_seconds=$((end - start))"
|
|
echo "wall_clock_seconds=$((end - start))" >> "$GITHUB_OUTPUT"
|
|
docker rm -f "$BUILD_CONTAINER" >/dev/null || true
|
|
ls -l dist/
|
|
|
|
- name: Verify artifacts
|
|
if: steps.staleness.outputs.skip != 'true'
|
|
run: |
|
|
set -euo pipefail
|
|
cd "${GITHUB_WORKSPACE}"
|
|
abi="$ONIONWIRE_ANDROID_ABI"
|
|
ls -l dist/
|
|
apk="$(ls dist/onionwire-*-android-$abi.apk)"
|
|
aar="$(ls dist/onionwire-sdk-*.aar)"
|
|
[ -s "$apk" ] || { echo "missing or empty $apk" >&2; exit 1; }
|
|
[ -s "$aar" ] || { echo "missing or empty $aar" >&2; exit 1; }
|
|
echo "apk=$apk bytes=$(wc -c < "$apk")"
|
|
echo "aar=$aar bytes=$(wc -c < "$aar")"
|
|
( cd dist && sha256sum -c ./*.sha256 )
|
|
echo "=== android-ci-verify.log (from build container) ==="
|
|
cat dist/android-ci-verify.log
|
|
echo "=== resources after build ==="
|
|
free -h || true
|
|
df -h || true
|