build fixes
- Commit
4418dd8cc4c7fecefdd2711ebb7b118a63680bea- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-23 05:56 UTC (3 months ago)
- Parents
0451bda
Diff
build-logic/src/main/kotlin/NativeAbis.kt
diff --git a/build-logic/src/main/kotlin/NativeAbis.kt b/build-logic/src/main/kotlin/NativeAbis.ktnew file mode 100644index 0000000000..4647341dee--- /dev/null+++ b/build-logic/src/main/kotlin/NativeAbis.kt@@ -0,0 +1,30 @@+import org.gradle.api.provider.Property++/** arm64-v8a: every phone/tablet target and the Apple-Silicon emulator. */+const val ABI_ARM64 = "arm64-v8a"++/** armeabi-v7a: 32-bit-userspace devices, notably Google TV boxes. */+const val ABI_ARMV7 = "armeabi-v7a"++/**+ * Per-app ABI opt-in, consumed by `common-conventions-app`. Apps stay arm64-only+ * unless they declare otherwise:+ *+ * ```+ * nativeAbis { armv7 = true }+ * ```+ */+interface NativeAbisExtension {+ /**+ * Also package [ABI_ARMV7]. Needed by apps that must run on 32-bit-userspace+ * devices: the onn 4K Streaming Box and most Google TV hardware report only+ * `armeabi-v7a,armeabi` in `ro.product.cpu.abilist`, so an arm64-only APK is+ * rejected at install with "Could not find build of variant which supports+ * density N and an ABI in armeabi-v7a, armeabi".+ *+ * Native (Rust) dependencies must opt in separately via `rustNativeLib`'s+ * `extraAbis`, since `abiFilters` only filters what was built - it cannot+ * conjure an .so for an ABI that was never cross-compiled.+ */+ val armv7: Property<Boolean>+}
build-logic/src/main/kotlin/RustNative.kt
diff --git a/build-logic/src/main/kotlin/RustNative.kt b/build-logic/src/main/kotlin/RustNative.ktindex 15f8723bd8..2f66ff285e 100644--- a/build-logic/src/main/kotlin/RustNative.kt+++ b/build-logic/src/main/kotlin/RustNative.kt@@ -16,20 +16,42 @@ import java.util.Properties abstract class RustToolchainLock : BuildService<BuildServiceParameters.None> /**- * Registers the per-ABI cargo cross-compile of a Rust cdylib (arm64-v8a only)- * into `build/rustJniLibs`, wired ahead of `preBuild`. This consolidates the- * ~80 lines of NDK-toolchain + cargo + reproducible-build boilerplate that used- * to be copy-pasted across every native module (pdf, camera, weather, passwords,- * e2ee-p2p). The caller still registers `build/rustJniLibs` as a jniLibs source- * dir in its own `android { }` block.+ * An Android ABI paired with the Rust target triple and the NDK clang-wrapper prefix+ * used to cross-compile for it. *- * Prereq: `rustup target add aarch64-linux-android`.+ * @param clangPrefix deliberately separate from [triple]: for armeabi-v7a the NDK ships+ * `armv7a-linux-androideabi<api>-clang` (note the `a`) while the Rust triple is+ * `armv7-linux-androideabi`, so deriving one from the other silently misses the wrapper.+ */+data class RustAbi(val abiDir: String, val triple: String, val clangPrefix: String)++private val KNOWN_RUST_ABIS = listOf(+ RustAbi(ABI_ARM64, "aarch64-linux-android", "aarch64-linux-android"),+ RustAbi(ABI_ARMV7, "armv7-linux-androideabi", "armv7a-linux-androideabi"),+)++/**+ * Registers the per-ABI cargo cross-compile of a Rust cdylib into `build/rustJniLibs`,+ * wired ahead of `preBuild`. This consolidates the ~80 lines of NDK-toolchain + cargo ++ * reproducible-build boilerplate that used to be copy-pasted across every native module+ * (pdf, camera, weather, passwords, e2ee-p2p). The caller still registers+ * `build/rustJniLibs` as a jniLibs source dir in its own `android { }` block.+ *+ * Prereq: `rustup target add` for every triple built (see `rust-toolchain.toml`). * * @param crate cargo package lib name → produces `lib<crate>.so` * @param remapLabel `--remap-path-prefix` label baked in for reproducible builds * (defaults to [crate]).+ * @param extraAbis ABIs to build in addition to [ABI_ARM64]. Opt-in per module so only+ * the modules that need a second ABI pay for the extra cargo build;+ * pass [ABI_ARMV7] for libraries consumed by an app that sets+ * `nativeAbis { armv7 = true }`. */-fun Project.rustNativeLib(crate: String, remapLabel: String = crate) {+fun Project.rustNativeLib(+ crate: String,+ remapLabel: String = crate,+ extraAbis: List<String> = emptyList(),+) { // Serialize cargoBuild across all Rust modules to avoid concurrent rustup installs. val rustLock = gradle.sharedServices.registerIfAbsent( "rustToolchainLock",@@ -60,10 +82,17 @@ fun Project.rustNativeLib(crate: String, remapLabel: String = crate) { val ndkBin = "$ndkRoot/toolchains/llvm/prebuilt/$hostTag/bin" val ndkSysroot = "$ndkRoot/toolchains/llvm/prebuilt/$hostTag/sysroot" - // arm64-v8a only — all physical devices + the Apple-Silicon emulator are arm64.- val rustAbis = listOf("arm64-v8a" to "aarch64-linux-android")+ // arm64-v8a always; anything else is opt-in via extraAbis.+ val rustAbis = (listOf(ABI_ARM64) + extraAbis).distinct().map { abiDir ->+ KNOWN_RUST_ABIS.firstOrNull { it.abiDir == abiDir }+ ?: error(+ "rustNativeLib($crate): unknown ABI '$abiDir'. " ++ "Known: ${KNOWN_RUST_ABIS.joinToString { it.abiDir }}"+ )+ } - val perAbi = rustAbis.map { (abiDir, triple) ->+ val perAbi = rustAbis.map { abi ->+ val (abiDir, triple) = abi tasks.register<Exec>("cargoBuild_${abiDir.replace('-', '_')}") { usesService(rustLock) description = "Cross-compiles lib$crate for $abiDir."@@ -73,8 +102,8 @@ fun Project.rustNativeLib(crate: String, remapLabel: String = crate) { val isWindows = OperatingSystem.current().isWindows val exeExt = if (isWindows) ".exe" else "" val clangExt = if (isWindows) ".cmd" else ""- val clang = "$ndkBin/$triple$androidApiLevel-clang$clangExt"- val clangpp = "$ndkBin/$triple$androidApiLevel-clang++$clangExt"+ val clang = "$ndkBin/${abi.clangPrefix}$androidApiLevel-clang$clangExt"+ val clangpp = "$ndkBin/${abi.clangPrefix}$androidApiLevel-clang++$clangExt" val linkerVar = "CARGO_TARGET_${triple.uppercase().replace('-', '_')}_LINKER" // Per-crate target (may exist from older isolated builds) and workspace root target // (current scheme since Cargo.toml workspace unified to root).
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex c83d5be0ef..030c45d6fa 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -39,6 +39,12 @@ val launcherIcon = extensions.create("launcherIcon", LauncherIconExtension::clas val materialSymbolsRef = "819d78680a849ceef4c78f863d8753e3160b7c89" val materialSymbolsCache = File(gradle.gradleUserHomeDir, "material-symbols-cache") +// Apps are arm64-only unless they opt in with `nativeAbis { armv7 = true }`+// (see NativeAbisExtension). Read in finalizeDsl below, not here.+val nativeAbis = extensions.create("nativeAbis", NativeAbisExtension::class.java).apply {+ armv7.convention(false)+}+ extensions.configure<com.android.build.api.variant.ApplicationAndroidComponentsExtension> { // Only `dev` and `release` ship. AGP always creates a `debug` build type and // forbids removing it, so disable its variants instead — no debug variant means@@ -47,6 +53,15 @@ extensions.configure<com.android.build.api.variant.ApplicationAndroidComponentsE beforeVariants(selector().withBuildType("debug")) { variant -> variant.enable = false }+ // abiFilters is a plain Set rather than a lazy Provider, so the opt-in can only be+ // read once the app's own build file has been evaluated — reading nativeAbis.armv7+ // straight from the defaultConfig block below would always observe the convention.+ finalizeDsl { ext ->+ if (nativeAbis.armv7.get()) {+ ext.defaultConfig.ndk.abiFilters.add(ABI_ARMV7)+ ext.buildTypes.getByName("dev").ndk.abiFilters.add(ABI_ARMV7)+ }+ } onVariants { variant -> val gen = tasks.register( "generate${variant.name.replaceFirstChar { it.uppercase() }}LauncherIcon",@@ -109,11 +124,12 @@ configure<com.android.build.api.dsl.ApplicationExtension> { versionCode = appVersionCode versionName = appVersionName targetSdk = 37- // Only arm64-v8a — all physical devices + Apple Silicon emulator are arm64.- // AGP otherwise configures buildCMakeDebug for armeabi-v7a/x86/x86_64 which- // wastes time and broke when offline router's sqlite3.c was removed.+ // arm64-v8a only by default — all phones/tablets + Apple Silicon emulator are+ // arm64. AGP otherwise configures buildCMakeDebug for armeabi-v7a/x86/x86_64+ // which wastes time and broke when offline router's sqlite3.c was removed.+ // 32-bit devices (Google TV) opt in with `nativeAbis { armv7 = true }`. ndk {- abiFilters.add("arm64-v8a")+ abiFilters.add(ABI_ARM64) } } @@ -167,7 +183,7 @@ configure<com.android.build.api.dsl.ApplicationExtension> { matchingFallbacks += listOf("release") ndk { abiFilters.clear()- abiFilters.add("arm64-v8a")+ abiFilters.add(ABI_ARM64) } // initWith(release) copied DEV_BUILD=false; dev is a developer build, so flip it on. buildConfigField("boolean", "DEV_BUILD", "true")
rust-toolchain.toml
diff --git a/rust-toolchain.toml b/rust-toolchain.tomlindex fa6ac3abd8..ea35c95c07 100644--- a/rust-toolchain.toml+++ b/rust-toolchain.toml@@ -1,3 +1,3 @@ [toolchain] channel = "1.97.0"-targets = ["aarch64-linux-android"]+targets = ["aarch64-linux-android", "armv7-linux-androideabi"]