Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / everysync-core / build.gradle.kts
build.gradle.kts122 lines · 5.6 KiBRaw
| 1 | import org.gradle.api.tasks.testing.Test |
| 2 | |
| 3 | plugins { |
| 4 | id("common-conventions-kmp") |
| 5 | } |
| 6 | |
| 7 | dependencies { |
| 8 | // OkHttp lives only in platform actuals: pinned TLS + WS on Android/JVM |
| 9 | // (Phase 1C), Darwin/sec-trust on iOS (Phase 3). commonMain stays |
| 10 | // engine-free behind the RelayHttpClient interface so no HTTP API leaks |
| 11 | // into the shared merge/vault policy. |
| 12 | add("androidMainImplementation", libs.okhttp) |
| 13 | add("androidMainImplementation", project(":library:e2ee-p2p")) |
| 14 | add("jvmMainImplementation", libs.okhttp) |
| 15 | add("jvmMainImplementation", libs.jna) |
| 16 | } |
| 17 | |
| 18 | // Pinning DERs (FIRST_PARTY bundle: ISRG X1/X2 + GTS R1-R4) as KMP resources. |
| 19 | // The copy runs as a task dependency so a fresh checkout self-heals. |
| 20 | val syncCaResources = tasks.register("syncCaResources", Copy::class.java) { |
| 21 | description = "Copies FIRST_PARTY pinning DERs from :library:network assets into common resources." |
| 22 | val caDir = rootProject.file("library/network/src/main/assets/ca") |
| 23 | val firstParty = listOf( |
| 24 | "isrgrootx1.der", |
| 25 | "isrgrootx2.der", |
| 26 | "gts-root-r1.der", |
| 27 | "gts-root-r2.der", |
| 28 | "gts-root-r3.der", |
| 29 | "gts-root-r4.der", |
| 30 | ) |
| 31 | onlyIf { caDir.isDirectory } |
| 32 | from(caDir) { include(firstParty) } |
| 33 | into(layout.projectDirectory.dir("src/commonMain/resources/ca")) |
| 34 | } |
| 35 | |
| 36 | // BC test vectors (ML-KEM + ML-DSA DER lens/hex, CT, SS, sig) are owned by |
| 37 | // :library:e2ee-p2p's Rust crate; jvmTest consumes a synced copy so the file |
| 38 | // has exactly one source of truth. |
| 39 | val syncPqcVectors = tasks.register("syncPqcVectors", Copy::class.java) { |
| 40 | description = "Syncs BC PQC vectors into jvmTest resources." |
| 41 | val vectors = rootProject.file("library/e2ee-p2p/src/main/rust/testvectors/bc_pqc_vectors.txt") |
| 42 | onlyIf { vectors.isFile } |
| 43 | from(vectors) |
| 44 | into(layout.projectDirectory.dir("src/jvmTest/resources")) |
| 45 | } |
| 46 | |
| 47 | // Host build of the e2ee_pqc C ABI for desktop JVM (JNA) + JVM tests. |
| 48 | // Android .so packaging is untouched (rustNativeLib in :library:e2ee-p2p): |
| 49 | // this builds the SAME crate for the host target into build/rustHostLibs, |
| 50 | // which jvmTest/jvmRun consume via -Djna.library.path (never a hardcoded path). |
| 51 | // |
| 52 | // Toolchain note: Windows hosts use the GNU triple (x86_64-pc-windows-gnu, |
| 53 | // MinGW — matches the installed toolchain; MSVC would need |
| 54 | // `rustup target add x86_64-pc-windows-msvc` + VS Build Tools). The cdylib |
| 55 | // loads identically under JNA. See rust-toolchain.toml for the pin. |
| 56 | // Config-cache compatible: only plain strings cross into the task action. |
| 57 | val hostRustTriple: String = run { |
| 58 | val os = System.getProperty("os.name").lowercase() |
| 59 | val arch = System.getProperty("os.arch").lowercase() |
| 60 | val isArm = arch.contains("aarch64") || arch.startsWith("arm") |
| 61 | when { |
| 62 | os.contains("win") -> if (isArm) "aarch64-pc-windows-gnullvm" else "x86_64-pc-windows-gnu" |
| 63 | os.contains("mac") -> if (isArm) "aarch64-apple-darwin" else "x86_64-apple-darwin" |
| 64 | else -> if (isArm) "aarch64-unknown-linux-gnu" else "x86_64-unknown-linux-gnu" |
| 65 | } |
| 66 | } |
| 67 | val hostLibFileName: String = when { |
| 68 | System.getProperty("os.name").lowercase().contains("win") -> "e2ee_pqc.dll" |
| 69 | System.getProperty("os.name").lowercase().contains("mac") -> "libe2ee_pqc.dylib" |
| 70 | else -> "libe2ee_pqc.so" |
| 71 | } |
| 72 | |
| 73 | val hostLibRelPath: String = "rustHostLibs/$hostLibFileName" |
| 74 | val builtLibRelPath: String = "target/$hostRustTriple/release/$hostLibFileName" |
| 75 | |
| 76 | val buildHostPqcLib = tasks.register("buildHostPqcLib", Exec::class.java) { |
| 77 | description = "Builds the e2ee_pqc C ABI for the host (JNA/cinterop consumers)." |
| 78 | workingDir = rootProject.file("library/e2ee-p2p/src/main/rust") |
| 79 | val cargoBin = "${System.getProperty("user.home")}/.cargo/bin" |
| 80 | val rustSrc = rootProject.file("library/e2ee-p2p/src/main/rust").absolutePath |
| 81 | inputs.dir("$rustSrc/src") |
| 82 | inputs.file("$rustSrc/Cargo.toml") |
| 83 | inputs.file(rootProject.file("Cargo.toml")) |
| 84 | inputs.file(rootProject.file("Cargo.lock")) |
| 85 | inputs.file(rootProject.file("rust-toolchain.toml")) |
| 86 | outputs.file(layout.buildDirectory.file(hostLibRelPath)) |
| 87 | val isWindowsHost = System.getProperty("os.name").lowercase().contains("win") |
| 88 | val pathSep = if (isWindowsHost) ";" else ":" |
| 89 | val exeExt = if (isWindowsHost) ".exe" else "" |
| 90 | environment("PATH", "$cargoBin$pathSep${System.getenv("PATH")}") |
| 91 | environment("RUSTC", "$cargoBin/rustc$exeExt") |
| 92 | environment( |
| 93 | "RUSTFLAGS", |
| 94 | "--remap-path-prefix=${System.getenv("CARGO_HOME") ?: "${System.getProperty("user.home")}/.cargo"}=/cargo" + |
| 95 | " --remap-path-prefix=$rustSrc=/e2ee-pqc", |
| 96 | ) |
| 97 | environment("CARGO_INCREMENTAL", "0") |
| 98 | commandLine("$cargoBin/cargo$exeExt", "build", "--locked", "--release", "--target", hostRustTriple) |
| 99 | // Config-cache safe: no Project/File captured — the copy runs in a |
| 100 | // separate cache-safe task below. |
| 101 | } |
| 102 | |
| 103 | val installHostPqcLib = tasks.register("installHostPqcLib", Copy::class.java) { |
| 104 | description = "Copies the built host e2ee_pqc lib into build/rustHostLibs." |
| 105 | dependsOn(buildHostPqcLib) |
| 106 | from(rootProject.file(builtLibRelPath)) |
| 107 | into(layout.buildDirectory.dir("rustHostLibs")) |
| 108 | } |
| 109 | |
| 110 | tasks.matching { it.name.startsWith("compile") || it.name.contains("ProcessResources") }.configureEach { |
| 111 | dependsOn(syncCaResources) |
| 112 | dependsOn(syncPqcVectors) |
| 113 | } |
| 114 | |
| 115 | tasks.withType<Test>().matching { it.name == "jvmTest" || it.name == "jvmRun" }.configureEach { |
| 116 | dependsOn("installHostPqcLib") |
| 117 | dependsOn(syncPqcVectors) |
| 118 | val hostLibDir = layout.buildDirectory.dir("rustHostLibs").get().asFile.absolutePath |
| 119 | // systemProperty resolves the dir at execution time; the plain string keeps |
| 120 | // the configuration cache happy. |
| 121 | systemProperty("jna.library.path", hostLibDir) |
| 122 | } |