Skip to content

Commit

Permalink
Added missing env var CXX_<triple>
Browse files Browse the repository at this point in the history
This is important also specify appropriate C++ compiler
for building bundled C++ libraries and/or bindings.

For example cmake fails compile rust bindings for liboboe
without it.
  • Loading branch information
katyo authored and thomcc committed Feb 7, 2020
1 parent 16a12c2 commit 3dc5511
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ open class CargoBuildTask : DefaultTask() {
// Be aware that RUSTFLAGS can have problems with embedded
// spaces, but that shouldn't be a problem here.
val cc = File(toolchainDirectory, "${toolchain.cc(apiLevel)}").path;
val cxx = File(toolchainDirectory, "${toolchain.cxx(apiLevel)}").path;
val ar = File(toolchainDirectory, "${toolchain.ar(apiLevel)}").path;

// For cargo: like "CARGO_TARGET_I686_LINUX_ANDROID_CC". This is really weakly
Expand All @@ -181,6 +182,7 @@ open class CargoBuildTask : DefaultTask() {
// For build.rs in `cc` consumers: like "CC_i686-linux-android". See
// https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables.
environment("CC_${toolchain.target}", cc)
environment("CXX_${toolchain.target}", cxx)
environment("AR_${toolchain.target}", ar)

// Configure our linker wrapper.
Expand Down Expand Up @@ -233,4 +235,3 @@ fun getDefaultTargetTriple(project: Project, rustc: String): String? {
}
return triple
}

15 changes: 15 additions & 0 deletions plugin/src/main/kotlin/com/nishtahir/RustAndroidPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ data class Toolchain(val platform: String,
}
}

fun cxx(apiLevel: Int): File =
if (System.getProperty("os.name").startsWith("Windows")) {
if (type == ToolchainType.ANDROID_PREBUILT) {
File("bin", "$compilerTriple$apiLevel-clang++.cmd")
} else {
File("$platform-$apiLevel/bin", "$compilerTriple-clang++.cmd")
}
} else {
if (type == ToolchainType.ANDROID_PREBUILT) {
File("bin", "$compilerTriple$apiLevel-clang++")
} else {
File("$platform-$apiLevel/bin", "$compilerTriple-clang++")
}
}

fun ar(apiLevel: Int): File =
if (type == ToolchainType.ANDROID_PREBUILT) {
File("bin", "$binutilsTriple-ar")
Expand Down

0 comments on commit 3dc5511

Please sign in to comment.