Files
giza-kmp/composeApp/build.gradle.kts
T
Kgothatso NgakoandClaude Opus 5 f0f1c179df build: the engine cannot come back from quartz (marmot-kmp, Phase 7)
marmotAudit runs docs/scripts/marmot-kmp-imports.sh --check from `check`, beside the M3,
brand and wallet audits. Verified both ways: silent on a clean tree, and on a tree with
one import put back it names the file and the line and fails with a pointer to the note.
That is C2 made enforceable -- a cherry-pick from a Bennu still on quartz 1.15.2 brings
the old spelling back, and "re-run the rule" is advice until a build failure makes it a
step.

The other three items of this phase are named in the note rather than done, each for a
reason:

- The app's own copies: nothing to delete. CommitOrdering is still live in NostrDao's
  reindex sweep and MarmotInboundManager's epoch tracker, and marmot-kmp has no
  CommitOrdering at all -- the convergence engine replaced the idea, not the class. Under
  D4 the legacy pipeline keeps its behaviour, so the comparator retires with the profile.
- The sender ratchet record wants a new table, so schema 36 -> 37 and an AutoMigration,
  and the interface says the write MUST be durable before it returns or a lost position
  reuses an AEAD key and nonce pair. A per-message write path with a correctness hazard
  does not belong in the tail of a migration whose discipline was D5. It is the obvious
  next task, and it is the same shape as the receive-side write Phase 5 pinned: one piece
  of work that decides how often this app persists a group, in both directions.
- Durable ingest dedup is taken by MarmotManager, not by MarmotInboundProcessor, so it
  needs the client D1 deferred. Phase 3 is where that stopped being hypothetical.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-11-19 00:16:21 +02:00

501 lines
22 KiB
Kotlin

import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.androidApplication)
// alias(libs.plugins.androidx.room)
alias(libs.plugins.androidx.room3)
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.composeHotReload)
alias(libs.plugins.kotlinPluginSerialization)
alias(libs.plugins.ksp)
// No sqldelight plugin here on purpose. The fr.acinq.phoenix.db.sqldelight databases this
// module used to generate are the same three lightning-kmp-app's :library generates from an
// identical copy of the .sq sources, and nothing under mobi.giza touches them. Generating
// them on both sides put every generated class in the apk twice, which debug tolerates and
// mergeDexRelease rejects as duplicate types. The library's copies are the ones that count.
}
kotlin {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
androidTarget {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}
// Declared only on a mac, mirroring the gate lightning-kmp-app's :library applies to its own ios
// targets. Down the composite chain secp256k1-kmp declares a libsecp256k1 cinterop, which makes
// gradle switch off klib cross compilation for apple targets, so on a linux/windows host nothing
// in the build tree offers an ios variant of fr.acinq.phoenix:lightning-kmp-app. Declaring these
// targets anyway leaves every ios compilation unable to resolve it and fails the build outright.
// Building an ios binary needs a mac regardless.
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) {
listOf(
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
}
}
jvm()
sourceSets {
androidMain.dependencies {
// The android secp256k1 natives. Nothing pulls these in transitively: lightning-kmp-core
// publishes no android variant, so the android target resolves it to the jvm one, which
// asks for secp256k1-kmp-jni-jvm and gets desktop .so/.dylib/.dll files that cannot load
// on a device. The app has to name the android artifact itself.
//
// Resolved from source via the composite build, not from Maven Central -- bitcoin-kmp's
// settings.gradle.kts substitutes this coordinate for secp256k1-kmp's :jni:android. That
// matters: the stock artifact has no ChillDKG module, so ChillDKG would compile and then
// fail with UnsatisfiedLinkError. The version is never resolved; substitution matches on
// group:name.
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-android:0.24.0")
implementation(libs.androidx.activity.compose)
// implementation(libs.androidx.room.sqlite.wrapper)
implementation(libs.compose.uiToolingPreview)
implementation(libs.sqldelight.android.driver)
}
commonMain.dependencies {
implementation(libs.androidx.datastore)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.lifecycle.viewmodelCompose)
implementation(libs.androidx.lifecycle.runtimeCompose)
// implementation(libs.androidx.room.runtime)
implementation(libs.androidx.room3.runtime)
implementation(libs.androidx.sqlite.bundled)
implementation(libs.coil.compose)
implementation(libs.coil.network.ktor3)
implementation(libs.compose.runtime)
implementation(libs.compose.foundation)
implementation(libs.compose.material3)
implementation(libs.compose.material3.adaptive)
implementation(libs.compose.material3.adaptive.navigation.suite)
implementation (libs.compose.material.icons.core)
implementation (libs.compose.material.icons.extended)
implementation(libs.compose.ui)
implementation(libs.compose.components.resources)
implementation(libs.compose.uiToolingPreview)
implementation(libs.kermit)
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.serialization.cbor)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.websockets)
implementation(libs.ktor.serialization.kotlinx.json)
// implementation(libs.lightning.kmp.core)
// resolved via the lightning-kmp-app composite build (see settings.gradle.kts)
implementation("fr.acinq.phoenix:lightning-kmp-app:1.0.0")
implementation(libs.navigation.compose)
implementation(libs.okio)
implementation(libs.qrose)
implementation(libs.sqldelight.runtime)
implementation(libs.sqldelight.coroutines.extensions)
implementation(libs.vitorpamplona.quartz)
// The Marmot engine, which quartz 2.3.0 dropped: the three processors, the
// MLS group manager and its store, convergence, the publish gate, the app
// components and the KeyPackage managers. quartz keeps the event classes --
// KeyPackageEvent, WelcomeEvent, GroupEvent, the MIP-05 push events -- and
// marmot-kmp imports those from it, so the two halves are declared together.
// docs/marmot-kmp.md.
implementation(libs.vitorpamplona.marmot)
// The RFC 9420 engine under it, which reads and writes the group state blob
// in ChatRoom.mlsGroupState. Transitive through marmot's `api`, and named
// here because MlsGroup, MlsGroupState and the TLS codec are the app's own
// imports in 80 places.
implementation(libs.vitorpamplona.mls)
// The primitives under both. Transitive as well; named for the 27 places the
// app reaches for Ed25519, X25519, RandomInstance and sha256 directly.
implementation(libs.vitorpamplona.crypto)
}
commonTest.dependencies {
implementation(libs.kotlin.test)
// runTest: the DAO, model and relay layers are all suspending, and there is no
// runBlocking in a common source set — so anything worth asserting about them
// needs a coroutine, and a scheduler, to assert it in.
implementation(libs.kotlinx.coroutinesTest)
}
jvmTest.dependencies {
// A layout modifier cannot be asserted by reading it. `readableContent()` is
// three modifiers whose order decides whether the content is capped, centred,
// both or neither, and every ordering compiles and renders something -- so the
// check has to be a measurement of a real composition. Pinned to the same
// version as the rest of Compose Multiplatform; test-only.
implementation(compose.desktop.uiTestJUnit4)
implementation(libs.kotlin.testJunit)
}
jvmMain.dependencies {
implementation(compose.desktop.currentOs)
implementation(libs.kotlinx.coroutinesSwing)
// The jvm counterpart to sqldelight-android-driver / -native-driver above.
implementation(libs.sqldelight.sqlite.driver)
}
// Only exists when the ios targets above were declared; the default hierarchy template
// creates this source set from them.
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) {
iosMain.dependencies {
implementation(libs.sqldelight.native.driver)
// CIO has no TLS implementation on native ("TLS sessions are not
// supported on Native platform"), so every wss/https call it makes on
// a device fails at the handshake. Darwin (NSURLSession) is the engine
// apple targets must use.
implementation(libs.ktor.client.darwin)
}
}
}
}
/**
* Kotlin 2.4.10's release backend crashes linking this module's ios binaries:
*
* e: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
* at org.jetbrains.kotlin.backend.konan.optimizations.StaticInitializersOptimization
* $InterproceduralAnalysis.getCalledInitializer(StaticInitializersOptimization.kt:244)
*
* `RemoveRedundantCallsToStaticInitializersPhase` -- an LTO pass, so only optimized links hit
* it, which is why the debug test binary links fine -- assumes every function in the call
* graph has at least one statement in its body, and something in this module's graph arrives
* with an empty one. The pass is an optimization only; disabling it costs the redundant
* initializer calls it would have removed and nothing else.
*/
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink>().configureEach {
if (name.startsWith("linkRelease")) {
toolOptions.freeCompilerArgs.add("-Xdisable-phases=RemoveRedundantCallsToStaticInitializersPhase")
}
}
android {
namespace = "mobi.giza.android"
compileSdk = libs.versions.android.compileSdk.get().toInt()
buildFeatures {
buildConfig = true
}
defaultConfig {
// The store identity and the namespace are one value. They were split when the app
// was com.it.curated, and again for one commit of the Giza fork, when the store
// identity moved ahead of the sources (docs/giza-rebrand.md, Phase 2). `BuildConfig`
// and the manifest's relative `android:name=".GizaApplication"` resolve against it.
applicationId = "mobi.giza.android"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
// Giza's own numbering, from the start (docs/giza-rebrand.md, D7). A new
// applicationId has no versions in the store to stay above; Bennu's ran to 9, 0.1.5.
versionCode = 1
versionName = "0.1.0"
}
// The upload key, from outside the repository: gradle properties (~/.gradle/gradle.properties,
// or -P on the command line) or the environment, under the names below. Without them a
// release build is unsigned, as Bennu's always were from this script, and is signed by hand.
//
// Never Bennu's key. Two apps sharing a key is half of what Android needs to let one read
// the other's data, and Giza must never be able to open Bennu's (giza-rebrand.md, Phase 0).
val uploadStoreFile = providers.gradleProperty("giza.upload.storeFile")
.orElse(providers.environmentVariable("GIZA_UPLOAD_STORE_FILE"))
signingConfigs {
if (uploadStoreFile.isPresent) {
create("upload") {
storeFile = file(uploadStoreFile.get())
storePassword = providers.gradleProperty("giza.upload.storePassword")
.orElse(providers.environmentVariable("GIZA_UPLOAD_STORE_PASSWORD")).get()
keyAlias = providers.gradleProperty("giza.upload.keyAlias")
.orElse(providers.environmentVariable("GIZA_UPLOAD_KEY_ALIAS")).get()
keyPassword = providers.gradleProperty("giza.upload.keyPassword")
.orElse(providers.environmentVariable("GIZA_UPLOAD_KEY_PASSWORD")).get()
}
}
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
excludes += "META-INF/versions/9/OSGI-INF/MANIFEST.MF"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
signingConfigs.findByName("upload")?.let { signingConfig = it }
}
getByName("debug") {
applicationIdSuffix = ".debug"
versionNameSuffix = "-DEBUG"
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
testOptions {
unitTests {
// Quartz logs through android.util.Log on the error paths -- parsing a
// malformed event, for one. Unmocked, those methods throw, so a test
// covering such a path fails on the log line rather than on what it
// came to check. Default values let the code under test carry on.
isReturnDefaultValues = true
}
}
}
dependencies {
debugImplementation(libs.compose.uiTooling)
// ksp(libs.androidx.room3.compiler)
add("kspAndroid", libs.androidx.room3.compiler)
// These configurations only exist when the ios targets are declared, which the kotlin block
// above does only on a mac.
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) {
add("kspIosSimulatorArm64", libs.androidx.room3.compiler)
// add("kspIosX64", libs.androidx.room.compiler)
add("kspIosArm64", libs.androidx.room3.compiler)
}
add("kspJvm", libs.androidx.room3.compiler)
// Add any other platform target you use in your project, for example kspDesktop
}
/**
* The package of the generated `Res` class, pinned rather than derived.
*
* Left alone, compose-resources builds it from the root project's name --
* `bennu.composeapp.generated.resources` while the project was Bennu -- so renaming the
* project rewrote every one of a thousand imports, and the docs/scripts extractors that
* write them. Pinned under the app's own package, a later rename of the root project
* changes nothing here (docs/giza-rebrand.md, D6).
*/
compose.resources {
packageOfResClass = "mobi.giza.compose.resources"
}
room3 {
schemaDirectory("$projectDir/schemas")
}
/**
* The Material Design conformance audit, as a build task.
*
* `docs/scripts/m3-audit.sh --check` counts what the phases in
* docs/material-design-conformance.md drove to zero -- hardcoded colours, dp literals in
* spacing positions, bare `.clickable`, title case, untriaged `contentDescription = null`
* -- and exits 1 when one of them has come back. It also holds two floors, for the
* adaptive and navigation work, which regress by being *removed*.
*
* Wired into `check` rather than left as a script somebody remembers to run: the whole
* point of a budget is that it is enforced at the moment the number moves, and a number
* that is only checked when a person thinks to look is a number that drifts.
*
* It reads the source tree with grep and needs no gradle, no android SDK and no
* submodules, so it is also the one part of this build that a bare CI runner can do.
*/
val m3Audit = tasks.register("m3Audit") {
group = "verification"
description = "Checks the Material Design conformance budgets in docs/material-design-conformance.md."
val script = rootProject.layout.projectDirectory.file("docs/scripts/m3-audit.sh").asFile
val uiSources = rootProject.layout.projectDirectory
.dir("composeApp/src/commonMain/kotlin/mobi/giza/compose/ui")
val projectDirectory = rootProject.layout.projectDirectory.asFile
inputs.file(script).withPropertyName("auditScript")
inputs.dir(uiSources).withPropertyName("uiSources")
// No outputs, so this would run every time. A marker file is what makes it
// up-to-date-able, and it is the only thing the task writes.
val marker = layout.buildDirectory.file("m3-audit/passed.txt")
outputs.file(marker)
doLast {
// Windows has no bash unless somebody installed one. Skipping loudly beats
// failing a build for a reason that has nothing to do with the change under it;
// the CI runner and every developer machine here are unix.
val bash = listOf("/bin/bash", "/usr/bin/bash").firstOrNull { File(it).canExecute() }
if (bash == null) {
logger.warn("m3Audit: no bash found, skipping. Run docs/scripts/m3-audit.sh --check by hand.")
marker.get().asFile.apply { parentFile.mkdirs() }.writeText("skipped: no bash\n")
return@doLast
}
val result = providers.exec {
commandLine(bash, script.absolutePath, "--check")
workingDir = projectDirectory
isIgnoreExitValue = true
}
val text = result.standardOutput.asText.get()
val exit = result.result.get().exitValue
logger.lifecycle(text)
if (exit != 0) {
throw GradleException(
"Material Design conformance budgets exceeded. See the report above and " +
"docs/material-design-conformance.md."
)
}
marker.get().asFile.apply { parentFile.mkdirs() }.writeText(text)
}
}
tasks.named("check") { dependsOn(m3Audit) }
/**
* Bennu named only in comments (docs/giza-rebrand.md, Phase 6). The `bennu/` derivation tags
* that were also allowed were all the wallets', and went with them (docs/giza-wallet-removal.md).
* Anything else is a leftover of the fork, or a Bennu string that came in with a fix taken
* from Bennu, and fails `check` before it ships.
*
* Reads tracked files with git grep, so it has no inputs gradle could track; it is cheap
* enough to run every time.
*/
val brandAudit = tasks.register("brandAudit") {
group = "verification"
description = "Checks that the pre-fork name appears only in comments."
val script = rootProject.layout.projectDirectory.file("docs/scripts/brand-audit.sh").asFile
val projectDirectory = rootProject.layout.projectDirectory.asFile
doLast {
val bash = listOf("/bin/bash", "/usr/bin/bash").firstOrNull { File(it).canExecute() }
if (bash == null) {
logger.warn("brandAudit: no bash found, skipping. Run docs/scripts/brand-audit.sh --check by hand.")
return@doLast
}
val result = providers.exec {
commandLine(bash, script.absolutePath, "--check")
workingDir = projectDirectory
isIgnoreExitValue = true
}
logger.lifecycle(result.standardOutput.asText.get())
if (result.result.get().exitValue != 0) {
throw GradleException("The pre-fork name appears outside a comment. See the report above.")
}
}
}
tasks.named("check") { dependsOn(brandAudit) }
/**
* That the wallets stay removed (docs/giza-wallet-removal.md, Phase 8): no retired wallet
* kind in the app's code, no lightning-kmp import, no file named for a wallet's pieces, and
* no amount in sats in the strings. A fix taken from Bennu that brings a wallet back fails
* `check` before it ships, as a Bennu string does under [brandAudit].
*/
val walletAudit = tasks.register("walletAudit") {
group = "verification"
description = "Checks that no wallet has come back."
val script = rootProject.layout.projectDirectory.file("docs/scripts/wallet-audit.sh").asFile
val projectDirectory = rootProject.layout.projectDirectory.asFile
doLast {
val bash = listOf("/bin/bash", "/usr/bin/bash").firstOrNull { File(it).canExecute() }
if (bash == null) {
logger.warn("walletAudit: no bash found, skipping. Run docs/scripts/wallet-audit.sh --check by hand.")
return@doLast
}
val result = providers.exec {
commandLine(bash, script.absolutePath, "--check")
workingDir = projectDirectory
isIgnoreExitValue = true
}
logger.lifecycle(result.standardOutput.asText.get())
if (result.result.get().exitValue != 0) {
throw GradleException("A wallet has come back. See the report above.")
}
}
}
tasks.named("check") { dependsOn(walletAudit) }
/**
* That the Marmot engine stays marmot-kmp's (docs/marmot-kmp.md, Phase 7): no import of a
* class quartz 2.3.0 dropped. quartz keeps the event classes -- `KeyPackageEvent`,
* `WelcomeEvent`, `GroupEvent`, the MIP-05 push events -- and those are not reported; the
* engine around them is not quartz's at any version the app can resolve, so an import of
* it does not compile here anyway.
*
* It is in `check` for the same reason [brandAudit] is: the fork cherry-picks from a
* Bennu that is still on quartz 1.15.2 with the engine inside it, and every line this
* guards is a line such a pick will conflict in. The audit is what turns "resolve it by
* re-running the rule" from advice into a build failure if somebody doesn't.
*/
val marmotAudit = tasks.register("marmotAudit") {
group = "verification"
description = "Checks that the Marmot engine still comes from marmot-kmp."
val script = rootProject.layout.projectDirectory.file("docs/scripts/marmot-kmp-imports.sh").asFile
val projectDirectory = rootProject.layout.projectDirectory.asFile
doLast {
val bash = listOf("/bin/bash", "/usr/bin/bash").firstOrNull { File(it).canExecute() }
if (bash == null) {
logger.warn("marmotAudit: no bash found, skipping. Run docs/scripts/marmot-kmp-imports.sh --check by hand.")
return@doLast
}
val result = providers.exec {
commandLine(bash, script.absolutePath, "--check")
workingDir = projectDirectory
isIgnoreExitValue = true
}
logger.lifecycle(result.standardOutput.asText.get())
if (result.result.get().exitValue != 0) {
throw GradleException("quartz's Marmot engine is back. See the report above, and docs/marmot-kmp.md.")
}
}
}
tasks.named("check") { dependsOn(marmotAudit) }
compose.desktop {
application {
mainClass = "mobi.giza.desktop.MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
// The installers' product name, which is what the OS shows. It was the package
// name, `com.machankura.bennu.desktop`, until the Giza fork.
packageName = "Giza"
packageVersion = "1.0.0"
linux {
packageName = "giza"
}
windows {
// Fixed, so one Giza MSI upgrades another, and its own, so it never upgrades
// a Bennu MSI (docs/giza-rebrand.md, Phase 4). Never change it: a new value
// makes the next release install beside the old one instead of over it.
upgradeUuid = "43e5b023-66d9-4c8c-ad31-efe28a96286b"
}
}
}
}