Skip to content

Commit 3dc5511

Browse files
katyothomcc
authored andcommitted
Added missing env var CXX_<triple>
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.
1 parent 16a12c2 commit 3dc5511

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ open class CargoBuildTask : DefaultTask() {
162162
// Be aware that RUSTFLAGS can have problems with embedded
163163
// spaces, but that shouldn't be a problem here.
164164
val cc = File(toolchainDirectory, "${toolchain.cc(apiLevel)}").path;
165+
val cxx = File(toolchainDirectory, "${toolchain.cxx(apiLevel)}").path;
165166
val ar = File(toolchainDirectory, "${toolchain.ar(apiLevel)}").path;
166167

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

186188
// Configure our linker wrapper.
@@ -233,4 +235,3 @@ fun getDefaultTargetTriple(project: Project, rustc: String): String? {
233235
}
234236
return triple
235237
}
236-

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ data class Toolchain(val platform: String,
113113
}
114114
}
115115

116+
fun cxx(apiLevel: Int): File =
117+
if (System.getProperty("os.name").startsWith("Windows")) {
118+
if (type == ToolchainType.ANDROID_PREBUILT) {
119+
File("bin", "$compilerTriple$apiLevel-clang++.cmd")
120+
} else {
121+
File("$platform-$apiLevel/bin", "$compilerTriple-clang++.cmd")
122+
}
123+
} else {
124+
if (type == ToolchainType.ANDROID_PREBUILT) {
125+
File("bin", "$compilerTriple$apiLevel-clang++")
126+
} else {
127+
File("$platform-$apiLevel/bin", "$compilerTriple-clang++")
128+
}
129+
}
130+
116131
fun ar(apiLevel: Int): File =
117132
if (type == ToolchainType.ANDROID_PREBUILT) {
118133
File("bin", "$binutilsTriple-ar")

0 commit comments

Comments
 (0)