Skip to content

Commit 3a7ea37

Browse files
committed
With NDK 23+, look for llvm-ar, not target triple-specific ...-ar. Fixes mozilla#91.
I'd prefer to do this by interrogating the binaries on disk, using something like `which`, but the current expression makes that a little hard to achieve, so we'll feed the NDK version into the relevant helper function for now.
1 parent 5bfc241 commit 3a7ea37

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ open class CargoBuildTask : DefaultTask() {
165165

166166
// Cross-compiling to Android requires toolchain massaging.
167167
if (toolchain.type != ToolchainType.DESKTOP) {
168+
val ndkPath = app.ndkDirectory
169+
val ndkVersion = ndkPath.name
170+
val ndkVersionMajor = ndkVersion.split(".").first().toInt()
171+
168172
val toolchainDirectory = if (toolchain.type == ToolchainType.ANDROID_PREBUILT) {
169-
val ndkPath = app.ndkDirectory
170-
val ndkVersion = ndkPath.name
171-
val ndkVersionMajor = ndkVersion.split(".").first()
172173
environment("CARGO_NDK_MAJOR_VERSION", ndkVersionMajor)
173174

174175
val hostTag = if (Os.isFamily(Os.FAMILY_WINDOWS)) {
@@ -197,7 +198,7 @@ open class CargoBuildTask : DefaultTask() {
197198

198199
val cc = File(toolchainDirectory, "${toolchain.cc(apiLevel)}").path;
199200
val cxx = File(toolchainDirectory, "${toolchain.cxx(apiLevel)}").path;
200-
val ar = File(toolchainDirectory, "${toolchain.ar(apiLevel)}").path;
201+
val ar = File(toolchainDirectory, "${toolchain.ar(apiLevel, ndkVersionMajor)}").path;
201202

202203
// For build.rs in `cc` consumers: like "CC_i686-linux-android". See
203204
// https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables.

plugin/src/main/kotlin/com/nishtahir/RustAndroidPlugin.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ data class Toolchain(val platform: String,
143143
}
144144
}
145145

146-
fun ar(apiLevel: Int): File =
147-
if (type == ToolchainType.ANDROID_PREBUILT) {
146+
fun ar(apiLevel: Int, ndkVersionMajor: Int): File =
147+
if (ndkVersionMajor >= 23) {
148+
File("bin", "llvm-ar")
149+
} else if (type == ToolchainType.ANDROID_PREBUILT) {
148150
File("bin", "$binutilsTriple-ar")
149151
} else {
150152
File("$platform-$apiLevel/bin", "$binutilsTriple-ar")

0 commit comments

Comments
 (0)