Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / build.gradle.kts
build.gradle.kts229 lines · 9.8 KiBRaw
| 1 | import java.util.Locale |
| 2 | import javax.inject.Inject |
| 3 | import org.gradle.api.DefaultTask |
| 4 | import org.gradle.api.file.DirectoryProperty |
| 5 | import org.gradle.api.file.RegularFileProperty |
| 6 | import org.gradle.api.tasks.InputDirectory |
| 7 | import org.gradle.api.tasks.InputFile |
| 8 | import org.gradle.api.tasks.OutputDirectory |
| 9 | import org.gradle.api.tasks.TaskAction |
| 10 | import org.gradle.process.ExecOperations |
| 11 | |
| 12 | plugins { |
| 13 | id("common-conventions-library") |
| 14 | id("com.google.devtools.ksp") |
| 15 | } |
| 16 | |
| 17 | // Dev-build-only companion library for :communicate (see AGENTS.md). |
| 18 | // The host app links this module only from its `dev` variant |
| 19 | // (`devImplementation`), so nothing in here is compiled or packaged |
| 20 | // into release builds. Package names under |
| 21 | // com.vayunmathur.communicate.* are kept where JNI symbol names and |
| 22 | // wire/persisted formats freeze them. |
| 23 | |
| 24 | // ---------------------------------------------------------------- |
| 25 | // Protobuf code generation (manual) |
| 26 | // ---------------------------------------------------------------- |
| 27 | // |
| 28 | // Both `com.squareup.wire` and `com.google.protobuf` Gradle plugins fail |
| 29 | // to apply under AGP 9 (they cast `ApplicationExtensionImpl` to the legacy |
| 30 | // `BaseExtension`, which AGP 9 removed). Until those plugins catch up, we |
| 31 | // resolve `protoc` from Maven Central and invoke it directly. The resulting |
| 32 | // Java classes (lite runtime) are added to the variant's Java sources via |
| 33 | // the `androidComponents` extension below. Moved from :communicate with the |
| 34 | // 11 Signal/WhatsApp protos; the generated packages |
| 35 | // (`com.vayunmathur.communicate.data.whatsapp.proto`, |
| 36 | // `org.whispersystems.signalservice...`, ...) are wire-frozen. |
| 37 | |
| 38 | val osClassifier: String = run { |
| 39 | val osName = System.getProperty("os.name").lowercase(Locale.US) |
| 40 | val arch = System.getProperty("os.arch").lowercase(Locale.US) |
| 41 | val os = when { |
| 42 | osName.contains("mac") || osName.contains("darwin") -> "osx" |
| 43 | osName.contains("win") -> "windows" |
| 44 | else -> "linux" |
| 45 | } |
| 46 | val cpu = when { |
| 47 | arch.contains("aarch64") || arch.contains("arm64") -> "aarch_64" |
| 48 | arch.contains("64") -> "x86_64" |
| 49 | else -> "x86_32" |
| 50 | } |
| 51 | "$os-$cpu" |
| 52 | } |
| 53 | |
| 54 | val protocConfig: Configuration = configurations.create("protocBinary") { |
| 55 | isCanBeResolved = true |
| 56 | isCanBeConsumed = false |
| 57 | } |
| 58 | |
| 59 | // Catalog coordinate (libs.protobuf.protoc) with the platform-classified |
| 60 | // exe artifact selected programmatically instead of a string coordinate |
| 61 | // with an appended classifier. |
| 62 | val protocDependency = |
| 63 | dependencies.create(libs.protobuf.protoc.get()) as org.gradle.api.artifacts.ExternalModuleDependency |
| 64 | protocDependency.artifact { |
| 65 | classifier = osClassifier |
| 66 | type = "exe" |
| 67 | } |
| 68 | |
| 69 | dependencies { |
| 70 | "protocBinary"(protocDependency) |
| 71 | } |
| 72 | |
| 73 | val protoSrcDir = layout.projectDirectory.dir("src/main/proto") |
| 74 | val protoGenDir = layout.buildDirectory.dir("generated/source/proto/java") |
| 75 | |
| 76 | // Custom task class so we can inject ExecOperations cleanly (the |
| 77 | // configuration cache rejects capturing the Project at execution time). |
| 78 | abstract class GenerateProtoTask @Inject constructor( |
| 79 | private val exec: ExecOperations, |
| 80 | ) : DefaultTask() { |
| 81 | @get:InputFile |
| 82 | abstract val protocBinary: RegularFileProperty |
| 83 | |
| 84 | @get:InputDirectory |
| 85 | abstract val protoSourceDir: DirectoryProperty |
| 86 | |
| 87 | @get:OutputDirectory |
| 88 | abstract val outputDir: DirectoryProperty |
| 89 | |
| 90 | @TaskAction |
| 91 | fun run() { |
| 92 | val binary = protocBinary.get().asFile |
| 93 | binary.setExecutable(true) |
| 94 | val out = outputDir.get().asFile |
| 95 | out.deleteRecursively() |
| 96 | out.mkdirs() |
| 97 | val srcDir = protoSourceDir.get().asFile |
| 98 | val protoFiles = srcDir.walkTopDown() |
| 99 | .filter { it.isFile && it.extension == "proto" } |
| 100 | .toList() |
| 101 | if (protoFiles.isEmpty()) return |
| 102 | exec.exec { |
| 103 | commandLine = buildList { |
| 104 | add(binary.absolutePath) |
| 105 | add("--java_out=${out.absolutePath}") |
| 106 | add("-I=${srcDir.absolutePath}") |
| 107 | addAll(protoFiles.map { it.absolutePath }) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | val generateProto = tasks.register<GenerateProtoTask>("generateProto") { |
| 114 | protocBinary.set(layout.file(protocConfig.elements.map { it.single().asFile })) |
| 115 | protoSourceDir.set(protoSrcDir) |
| 116 | outputDir.set(protoGenDir) |
| 117 | } |
| 118 | |
| 119 | // Make Kotlin/Java/KSP compilation wait on protoc. KSP runs ahead of |
| 120 | // compileKotlin so it has to be in this list too. |
| 121 | tasks.matching { |
| 122 | it.name.startsWith("compile") && |
| 123 | (it.name.endsWith("Kotlin") || it.name.endsWith("JavaWithJavac")) || |
| 124 | it.name.startsWith("ksp") |
| 125 | }.configureEach { |
| 126 | dependsOn(generateProto) |
| 127 | } |
| 128 | |
| 129 | androidComponents { |
| 130 | onVariants { variant -> |
| 131 | // Wire proto gen sources + Rust JNI libs into each variant. |
| 132 | variant.sources.java?.addStaticSourceDirectory(protoGenDir.get().asFile.absolutePath) |
| 133 | val rustDir = layout.buildDirectory.dir("rustJniLibs").get().asFile.absolutePath |
| 134 | variant.sources.jniLibs?.addStaticSourceDirectory(rustDir) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Classic Signal protocol v3 (X3DH + Double Ratchet + Sender Keys) for the WhatsApp |
| 139 | // primary client — Rust impl. Unique crate name to avoid workspace collision with |
| 140 | // messages' whatsapp_signal. |
| 141 | rustNativeLib("communicate_signal", "communicate_signal") |
| 142 | |
| 143 | // MLS (RFC 9420, OpenMLS) for the RCS line's closed-loop E2EE — separate crate |
| 144 | // (own dependency tree) with its own JNI lib. |
| 145 | rustNativeLib("communicate_mls", "communicate_mls", srcDir = "src/main/rust-mls") |
| 146 | |
| 147 | // Native-loading and shared-JVM-polluting test classes moved here with the |
| 148 | // line code (quarantine rationale inherited from :communicate's split: JNI |
| 149 | // libs bind to one classloader per JVM, and the *LineSession / |
| 150 | // WhatsAppClient-singleton classes leak process-wide state when batched). |
| 151 | rustNativeTests { |
| 152 | nativeClasses.addAll( |
| 153 | listOf( |
| 154 | "com.vayunmathur.communicate.rcs.MlsLifecycleRcsPass3Test", |
| 155 | "com.vayunmathur.communicate.rcs.RcsSlice3E2ESupportTest", |
| 156 | "com.vayunmathur.communicate.rcs.RcsSlice3Pass2E2ETest", |
| 157 | "com.vayunmathur.communicate.rcs.RcsSlice3Pass2FakeTransportTest", |
| 158 | "com.vayunmathur.communicate.rcs.RcsSlice3Pass2UiTest", |
| 159 | "com.vayunmathur.communicate.signal.RegistrationHttpClientSignalPass3Test", |
| 160 | "com.vayunmathur.communicate.signal.RustSignalCryptoSignalPass3Test", |
| 161 | "com.vayunmathur.communicate.signal.SignalAuthAndServiceDataTest", |
| 162 | "com.vayunmathur.communicate.signal.SignalCallAndTransportParseTest", |
| 163 | "com.vayunmathur.communicate.signal.SignalCdsiTest", |
| 164 | "com.vayunmathur.communicate.signal.SignalGroupsAndSyncTest", |
| 165 | "com.vayunmathur.communicate.signal.SignalIdentitySignalPass3Test", |
| 166 | "com.vayunmathur.communicate.signal.SignalInboundPollW1Test", |
| 167 | "com.vayunmathur.communicate.signal.SignalSafetyNumberTest", |
| 168 | "com.vayunmathur.communicate.signal.SignalSealedSenderTest", |
| 169 | "com.vayunmathur.communicate.signal.SignalSlice2E2ETest", |
| 170 | "com.vayunmathur.communicate.signal.SignalSlice2InboundTest", |
| 171 | "com.vayunmathur.communicate.signal.SignalSlice2MessagingOfflineTest", |
| 172 | "com.vayunmathur.communicate.signal.SignalSlice2SealedCacheTest", |
| 173 | "com.vayunmathur.communicate.signal.Y1SignalMessagingGroupTest", |
| 174 | "com.vayunmathur.communicate.signal.Y1SignalSendPipelineTest", |
| 175 | "com.vayunmathur.communicate.signal.Y2SignalSocketRegTest", |
| 176 | "com.vayunmathur.communicate.signal.Y3SignalGroupOpsServerTest", |
| 177 | "com.vayunmathur.communicate.signal.Y3SignalPipelineServerTest", |
| 178 | "com.vayunmathur.communicate.signal.Y3SignalServerApiTest", |
| 179 | "com.vayunmathur.communicate.whatsapp.W5Slice1AttestationTest", |
| 180 | "com.vayunmathur.communicate.whatsapp.W5Slice1MexRouterTest", |
| 181 | "com.vayunmathur.communicate.whatsapp.W5Slice1RegBundleTest", |
| 182 | "com.vayunmathur.communicate.whatsapp.WhatsAppAttestationTest", |
| 183 | "com.vayunmathur.communicate.whatsapp.WhatsAppRegistrationBadParamRegressionTest", |
| 184 | "com.vayunmathur.communicate.whatsapp.Y1WaE2eSyncTest", |
| 185 | "com.vayunmathur.communicate.whatsapp.Y1WaInboundTest", |
| 186 | "com.vayunmathur.communicate.whatsapp.Y1WaRegistrationHttpTest", |
| 187 | "com.vayunmathur.communicate.whatsapp.Y2WaSocketSendTest", |
| 188 | "com.vayunmathur.communicate.whatsapp.Y3AppStatePageTest", |
| 189 | ) |
| 190 | ) |
| 191 | isolatedClasses.addAll( |
| 192 | listOf( |
| 193 | "com.vayunmathur.communicate.rcs.RcsSlice3Pass2DirectSipAuthTest", |
| 194 | "com.vayunmathur.communicate.rcs.RcsSlice3Pass2TlsAndFtTest", |
| 195 | "com.vayunmathur.communicate.rcs.RcsSlice3Pass2TransportTest", |
| 196 | "com.vayunmathur.communicate.whatsapp.W5Pass2ClientCoreTest", |
| 197 | "com.vayunmathur.communicate.whatsapp.W5Pass2ContactUtilsTest", |
| 198 | "com.vayunmathur.communicate.whatsapp.W5Pass2SyncHistoryTest", |
| 199 | ) |
| 200 | ) |
| 201 | } |
| 202 | |
| 203 | dependencies { |
| 204 | // Shared repo libraries the dev lines use (mirrors :communicate). |
| 205 | implementation(project(":library")) |
| 206 | implementation(project(":library:ui")) |
| 207 | implementation(project(":library:log")) |
| 208 | implementation(project(":library:network")) |
| 209 | implementation(project(":library:image")) |
| 210 | implementation(project(":library:room")) |
| 211 | |
| 212 | // Room - E2E state + message/thread/reaction/poll caches for the three lines. |
| 213 | implementRoom(libs) |
| 214 | |
| 215 | // Compile-only framework @SystemApi RCS stubs; never packaged. |
| 216 | compileOnly(project(":library:aosp-stubs")) |
| 217 | |
| 218 | implementation(libs.ringrtc.android) |
| 219 | implementation(libs.libsignal.android) |
| 220 | implementation(libs.protobuf.java) |
| 221 | implementation(libs.libphonenumber) |
| 222 | implementation(libs.kotlinx.serialization.json) |
| 223 | |
| 224 | testImplementation(libs.robolectric) |
| 225 | testImplementation(libs.androidx.test.core) |
| 226 | testImplementation(libs.kotlin.reflect) |
| 227 | testImplementation(libs.androidx.sqlite.bundled.jvm) |
| 228 | testImplementation(project(":library:aosp-stubs")) |
| 229 | } |