Skip to content

Commit 14a5a87

Browse files
authored
Fix Android Studio JDK 21 / Rust issues (#898)
Works around gradle/gradle#10483 by resolving the compiler paths at the start of the script, then passing them where they’re needed.
1 parent 25322db commit 14a5a87

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

native/kotlin/api/android/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ dependencies {
8686
val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot")!!
8787
val moduleName = "wp_api"
8888
cargo {
89+
cargoCommand = rootProject.ext.get("cargoBinaryPath").toString()
90+
rustcCommand = rootProject.ext.get("rustcBinaryPath").toString()
8991
module = "$cargoProjectRoot/$moduleName/"
9092
libname = moduleName
9193
profile = "release"

native/kotlin/api/kotlin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ val generateUniFFIBindingsTask = tasks.register<Exec>("generateUniFFIBindings")
9393
dependsOn(rootProject.tasks.named("cargoBuildLibraryRelease"))
9494
workingDir(project.rootDir)
9595
commandLine(
96-
"cargo",
96+
rootProject.ext.get("cargoBinaryPath")!!,
9797
"run",
9898
"--release",
9999
"--bin",

native/kotlin/build.gradle.kts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,17 @@ allprojects {
4747
}
4848
}
4949

50+
val cargoBinaryPath = resolveBinary("cargo")
51+
val rustcBinaryPath = resolveBinary("rustc")
5052
val cargoProjectRoot = "${project.rootDir}/../.."
5153
val jniLibsPath = "${layout.buildDirectory.get()}/jniLibs/"
5254
val generatedTestResourcesPath = "${layout.buildDirectory.get()}/generatedTestResources/"
5355
val rustModuleName = "wp_api"
5456
val nativeLibraryPath =
5557
"$cargoProjectRoot/target/release/lib${rustModuleName}${getNativeLibraryExtension()}"
58+
59+
rootProject.ext.set("cargoBinaryPath", cargoBinaryPath)
60+
rootProject.ext.set("rustcBinaryPath", rustcBinaryPath)
5661
rootProject.ext.set("cargoProjectRoot", cargoProjectRoot)
5762
rootProject.ext.set("jniLibsPath", jniLibsPath)
5863
rootProject.ext.set("generatedTestResourcesPath", generatedTestResourcesPath)
@@ -68,7 +73,7 @@ fun setupJniAndBindings() {
6873

6974
val cargoBuildLibraryReleaseTask = tasks.register<Exec>("cargoBuildLibraryRelease") {
7075
workingDir(rootProject.ext.get("cargoProjectRoot")!!)
71-
commandLine("cargo", "build", "--package", rustModuleName, "--release")
76+
commandLine(cargoBinaryPath, "build", "--package", rustModuleName, "--release")
7277
// No inputs.dir added, because we want to always re-run this task and let Cargo handle caching
7378
}
7479

@@ -101,6 +106,16 @@ fun setupJniAndBindings() {
101106
}
102107
}
103108

109+
fun resolveBinary(name: String): String {
110+
val process = ProcessBuilder().apply {
111+
command(listOf("which", name))
112+
}.start()
113+
114+
process.waitFor()
115+
116+
return process.inputReader().readText().trim()
117+
}
118+
104119
fun getNativeLibraryExtension(): String {
105120
val currentOS = org.gradle.internal.os.OperatingSystem.current()
106121
return if (currentOS.isLinux) {

0 commit comments

Comments
 (0)