From e0a4141bfde1a00d2be591dc3ec519154acd2566 Mon Sep 17 00:00:00 2001 From: Ben Dean-Kawamura Date: Tue, 31 Dec 2024 09:51:14 -0500 Subject: [PATCH] Add --build-id to the linker flags --- README.md | 4 ++++ plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt | 6 +++++- plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09c7c99..2cdee40 100644 --- a/README.md +++ b/README.md @@ -341,6 +341,10 @@ cargo { } ``` +### generateBuildId + +Generate a build-id for the shared library during the link phase. + ### exec This is a callback taking the `ExecSpec` we're going to use to invoke `cargo build`, and diff --git a/plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt b/plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt index 1d8a3f7..363f0ec 100644 --- a/plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt +++ b/plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt @@ -228,7 +228,11 @@ open class CargoBuildTask : DefaultTask() { environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", File(project.rootProject.buildDir, "linker-wrapper/linker-wrapper.py").path) environment("RUST_ANDROID_GRADLE_CC", cc) - environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-Wl,-soname,lib${cargoExtension.libname!!}.so") + if (cargoExtension.generateBuildId) { + environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-Wl,--build-id,-soname,lib${cargoExtension.libname!!}.so") + } else { + environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-Wl,-soname,lib${cargoExtension.libname!!}.so") + } } cargoExtension.extraCargoBuildArguments?.let { diff --git a/plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt b/plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt index 791d314..e0b0995 100644 --- a/plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt +++ b/plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt @@ -44,6 +44,7 @@ open class CargoExtension { var apiLevel: Int? = null var apiLevels: Map = mapOf() var extraCargoBuildArguments: List? = null + var generateBuildId: Boolean = false // It would be nice to use a receiver here, but there are problems interoperating with Groovy // and Kotlin that are just not worth working out. Another JVM language, yet another dynamic