diff --git a/.git-hooks/pre-push b/.git-hooks/pre-push index 1e9795cfc..b64f0b624 100755 --- a/.git-hooks/pre-push +++ b/.git-hooks/pre-push @@ -12,10 +12,24 @@ echo "$JAVA_HOME" echo "$(java -version)" echo "Running test... " +# Single-variant pre-push tests. `./gradlew test` would compile six Android +# variants of :amethyst (play/fdroid × debug/release/benchmark) plus full +# native-libs merging per variant — ~6× the work of one variant. CI runs the +# multi-flavor matrix on push to main; pre-push only needs one happy path. +TASKS=( + :quartz:jvmTest + :commons:jvmTest + :nestsClient:jvmTest + :quic:jvmTest + :ammolite:testDebugUnitTest + :amethyst:testPlayDebugUnitTest + :cli:test +) + if [ "${CLAUDE_CODE_REMOTE:-}" = "true" ]; then - ./gradlew test --quiet -x :desktopApp:test -x :desktopApp:upxDownload -x :desktopApp:vlcDownload + ./gradlew "${TASKS[@]}" --quiet else - ./gradlew test --quiet + ./gradlew "${TASKS[@]}" :desktopApp:test --quiet fi status=$? diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef274a718..a60dea996 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,17 @@ jobs: with: distribution: 'zulu' java-version: 21 - cache: gradle + + # Remote Gradle build cache: writes on push to main, reads on PRs and + # other branches. Caches both `~/.gradle/caches/` and individual task + # outputs, so dependency-only changes hit the cache and skip recompiling + # downstream modules / re-merging native libs (~600MB of work on + # :amethyst alone). Replaces the narrower `cache: gradle` previously on + # actions/setup-java, which only cached `modules-2`. + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: ${{ github.ref != 'refs/heads/main' }} - name: Linter (gradle) run: ./gradlew spotlessCheck @@ -63,7 +73,11 @@ jobs: with: distribution: 'zulu' java-version: 21 - cache: gradle + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: ${{ github.ref != 'refs/heads/main' }} # Cache vlc-setup plugin downloads (VLC + UPX archives) keyed on the # versions pinned in desktopApp/build.gradle.kts. Each OS gets its own @@ -81,7 +95,7 @@ jobs: vlcsetup-${{ runner.os }}- - name: Test + Build Desktop (gradle) - run: ./gradlew :quartz:jvmTest :commons:jvmTest :nestsClient:jvmTest :cli:test :desktopApp:test :desktopApp:${{ matrix.desktop-task }} --no-daemon + run: ./gradlew :quartz:jvmTest :commons:jvmTest :nestsClient:jvmTest :cli:test :desktopApp:test :desktopApp:${{ matrix.desktop-task }} # jpackage pins libicu to the build host's version (libicu74 on # ubuntu-24.04). Rewrite the .deb so testers on other Debian/Ubuntu @@ -112,10 +126,42 @@ jobs: with: distribution: 'zulu' java-version: 21 - cache: gradle - - name: Android Lint (gradle) - run: ./gradlew :amethyst:lintFdroidBenchmark :amethyst:lintPlayBenchmark --no-daemon + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: ${{ github.ref != 'refs/heads/main' }} + + # Lint + focused unit tests + benchmark assembly in one Gradle invocation. + # Previously: one invocation for lint, one for `test` (which compiled all + # six amethyst variants × all flavors), one for `assembleBenchmark` + # (re-walking the same task graph). Combining them keeps the daemon hot + # across phases and lets task-level dedup (e.g. compileKotlin) only + # happen once. + # + # `-PdisableAbiSplits=true` produces a single non-split APK per + # (flavor, buildType) instead of 5 (4 ABIs + universal). The CI only + # uploads the universal-equivalent benchmark APK; per-ABI splits were + # being built and discarded, costing ~600MB of stripped_native_libs + # intermediates and several minutes per run. + # + # Test scope: only Debug unit tests for amethyst. The release/benchmark + # variants are compile-equivalent for unit-test purposes; running all six + # adds ~5× the kotlinc work without catching new defects on PRs. Push to + # main still gets the full test matrix via the production-build path. + - name: Test + Build Android (gradle) + run: | + ./gradlew \ + :amethyst:lintFdroidBenchmark \ + :amethyst:lintPlayBenchmark \ + :quartz:jvmTest \ + :commons:jvmTest \ + :nestsClient:jvmTest \ + :ammolite:testDebugUnitTest \ + :amethyst:testFdroidDebugUnitTest \ + :amethyst:testPlayDebugUnitTest \ + :amethyst:assembleBenchmark \ + -PdisableAbiSplits=true - name: Upload Android Lint Reports uses: actions/upload-artifact@v7 @@ -124,31 +170,35 @@ jobs: name: Android Lint Reports path: amethyst/build/reports/lint-results-*.html - - name: Test + Build Android (gradle) - run: ./gradlew test assembleBenchmark --no-daemon - - name: Android Test Report uses: asadmansr/android-test-report-action@v1.2.0 if: always() - name: Upload Test Results uses: actions/upload-artifact@v7 - if: always() + if: failure() with: name: Test Reports path: amethyst/build/reports + # With -PdisableAbiSplits=true the APK is named without the ABI/universal + # suffix: amethyst--benchmark.apk. Glob both forms so this still + # works if a contributor runs CI on a branch that doesn't pass the flag. - name: Upload Play APK Benchmark uses: actions/upload-artifact@v7 with: name: Play Benchmark APK - path: amethyst/build/outputs/apk/play/benchmark/amethyst-play-universal-benchmark.apk + path: | + amethyst/build/outputs/apk/play/benchmark/amethyst-play-benchmark.apk + amethyst/build/outputs/apk/play/benchmark/amethyst-play-universal-benchmark.apk - name: Upload FDroid APK Benchmark uses: actions/upload-artifact@v7 with: name: FDroid Benchmark APK - path: amethyst/build/outputs/apk/fdroid/benchmark/amethyst-fdroid-universal-benchmark.apk + path: | + amethyst/build/outputs/apk/fdroid/benchmark/amethyst-fdroid-benchmark.apk + amethyst/build/outputs/apk/fdroid/benchmark/amethyst-fdroid-universal-benchmark.apk - name: Upload Compose Reports uses: actions/upload-artifact@v7 diff --git a/amethyst/build.gradle b/amethyst/build.gradle index ae6d0f09e..32a65cb98 100644 --- a/amethyst/build.gradle +++ b/amethyst/build.gradle @@ -142,10 +142,32 @@ android { ] } + // Opt-in fast-build flags. Default behavior is unchanged. + // + // -PdisableAbiSplits=true skip per-ABI APK splits; produces a single + // APK per (flavor, buildType) instead of 5. + // Cuts ~600 MB of intermediates and several + // minutes off CI. + // -PdisableUniversalApk=true when ABI splits are enabled, skip the + // extra universal APK output. (No effect + // when disableAbiSplits is also set, since + // there are no splits to add to.) + // -Pamethyst.skipMapping=true disable R8 minification on release and + // benchmark. APK is larger, but builds are + // much faster and outputs/mapping/ (~260MB) + // is not produced. Local-dev and PR-CI use + // only — release pipelines must not set it. + def disableAbiSplits = providers.gradleProperty("disableAbiSplits") + .map { it.toBoolean() }.getOrElse(false) + def disableUniversalApk = providers.gradleProperty("disableUniversalApk") + .map { it.toBoolean() }.getOrElse(false) + def skipMapping = providers.gradleProperty("amethyst.skipMapping") + .map { it.toBoolean() }.getOrElse(false) + buildTypes { release { proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), 'proguard-rules.pro' - minifyEnabled = true + minifyEnabled = !skipMapping } debug { applicationIdSuffix '.debug' @@ -186,10 +208,10 @@ android { splits { abi { - enable = true + enable = !disableAbiSplits reset() include "x86", "x86_64", "arm64-v8a", "armeabi-v7a" - universalApk = true + universalApk = !disableUniversalApk } } diff --git a/commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf b/commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf index a8166fc2d..c9276464a 100644 Binary files a/commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf and b/commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf differ diff --git a/tools/material-symbols-subset/README.md b/tools/material-symbols-subset/README.md new file mode 100644 index 000000000..c6f689020 --- /dev/null +++ b/tools/material-symbols-subset/README.md @@ -0,0 +1,56 @@ +# Material Symbols Subset + +The font shipped at +`commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf` +is a **subset** of Google's [Material Symbols +Outlined](https://github.com/google/material-design-icons) variable font, +trimmed to only the codepoints referenced from +`commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/icons/symbols/MaterialSymbols.kt`. + +| | Full upstream | Subset | +|---|---|---| +| Size | ~11 MB | ~410 KB | +| Glyphs | ~3500 | ~210 | + +The subset cuts >10 MB out of every commons build artifact, every Android APK, +and every Desktop app bundle. + +## When to regenerate + +Run `subset.sh` whenever you: + +- add or remove a `MaterialSymbol("\uXXXX")` entry in `MaterialSymbols.kt` +- pin a newer upstream font version + +## Prerequisites + +```bash +pip install fonttools brotli +``` + +## Regenerating + +From the repo root: + +```bash +./tools/material-symbols-subset/subset.sh +``` + +That downloads the upstream variable font, intersects its codepoints with the +ones referenced from `MaterialSymbols.kt`, and overwrites the checked-in +`material_symbols_outlined.ttf`. + +If you already have an upstream `.ttf` on disk: + +```bash +./tools/material-symbols-subset/subset.sh /path/to/MaterialSymbolsOutlined-Regular.ttf +``` + +Commit the regenerated `.ttf` alongside the `MaterialSymbols.kt` change. + +## How it works + +`pyftsubset` (from `fonttools`) reads the codepoints we care about, drops every +glyph and OpenType feature not reachable from those codepoints, and rewrites +`name`, `cmap`, and `GSUB` tables accordingly. The Compose resource pipeline +treats the result as a normal TTF — no code changes needed. diff --git a/tools/material-symbols-subset/subset.sh b/tools/material-symbols-subset/subset.sh new file mode 100755 index 000000000..0689a78ae --- /dev/null +++ b/tools/material-symbols-subset/subset.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +# +# Subset commons/.../material_symbols_outlined.ttf to only the codepoints +# referenced from MaterialSymbols.kt. The full Google variable font is ~11 MB +# (≈3500 glyphs); the subset is ~410 KB. +# +# Run this whenever MaterialSymbols.kt gains or loses a codepoint, or when +# pulling a newer upstream font release. +# +# Inputs: +# $1 (optional) — path to a full upstream MaterialSymbolsOutlined-Regular.ttf +# to subset. If omitted, the script downloads the variable +# font from Google Fonts. +# +# Output: +# Overwrites commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" +SYMBOLS_KT="$REPO_ROOT/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/icons/symbols/MaterialSymbols.kt" +TARGET="$REPO_ROOT/commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf" + +if ! command -v pyftsubset >/dev/null 2>&1; then + echo "pyftsubset not found. Install with: pip install fonttools brotli" >&2 + exit 1 +fi + +if [ "${1:-}" ]; then + SOURCE_TTF="$1" +else + SOURCE_TTF="$(mktemp -t material_symbols.XXXXXX.ttf)" + trap 'rm -f "$SOURCE_TTF"' EXIT + echo "Downloading upstream Material Symbols Outlined variable font..." + curl -fsSL -o "$SOURCE_TTF" \ + "https://github.com/google/material-design-icons/raw/master/variablefont/MaterialSymbolsOutlined%5BFILL%2CGRAD%2Copsz%2Cwght%5D.ttf" +fi + +CODEPOINTS_FILE="$(mktemp -t material_symbols_cp.XXXXXX.txt)" +trap 'rm -f "$CODEPOINTS_FILE" ${SOURCE_TTF:+}' EXIT + +# Pull every \uXXXX literal out of MaterialSymbols.kt as U+XXXX, deduplicated. +grep -oE '\\u[A-Fa-f0-9]{4}' "$SYMBOLS_KT" | sort -u | sed 's/\\u/U+/' > "$CODEPOINTS_FILE" + +count=$(wc -l < "$CODEPOINTS_FILE") +echo "Subsetting to $count codepoints from MaterialSymbols.kt" + +pyftsubset "$SOURCE_TTF" \ + --unicodes-file="$CODEPOINTS_FILE" \ + --output-file="$TARGET" \ + --layout-features='*' \ + --no-hinting \ + --desubroutinize \ + --notdef-outline \ + --recommended-glyphs \ + --name-IDs='*' \ + --name-legacy \ + --name-languages='*' \ + --glyph-names \ + --symbol-cmap + +echo "Wrote $TARGET ($(du -h "$TARGET" | cut -f1))"