Skip to content

Commit 1cb2e6f

Browse files
authored
Use cargoOutputDir
1 parent 3a551de commit 1cb2e6f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.io.File
1212

1313
open class CargoBuildTask : DefaultTask() {
1414
var toolchain: Toolchain? = null
15+
lateinit var cargoOutputDir: String
1516

1617

1718
@Suppress("unused")
@@ -23,13 +24,6 @@ open class CargoBuildTask : DefaultTask() {
2324
if (toolchain == null) {
2425
throw GradleException("toolchain cannot be null")
2526
}
26-
27-
project.plugins.all {
28-
when (it) {
29-
is AppPlugin -> buildProjectForTarget<AppExtension>(project, toolchain, this)
30-
is LibraryPlugin -> buildProjectForTarget<LibraryExtension>(project, toolchain, this)
31-
}
32-
}
3327
// CARGO_TARGET_DIR can be used to force the use of a global, shared target directory
3428
// across all rust projects on a machine. Use it if it's set, otherwise use the
3529
// configured `targetDirectory` value, and fall back to `${module}/target`.
@@ -44,11 +38,19 @@ open class CargoBuildTask : DefaultTask() {
4438

4539
val defaultTargetTriple = getDefaultTargetTriple(project, rustcCommand)
4640

47-
val cargoOutputDir = if (toolchain.target == defaultTargetTriple) {
41+
cargoOutputDir = if (toolchain.target == defaultTargetTriple) {
4842
"${targetDirectory}/${profile}"
4943
} else {
5044
"${targetDirectory}/${toolchain.target}/${profile}"
5145
}
46+
47+
project.plugins.all {
48+
when (it) {
49+
is AppPlugin -> buildProjectForTarget<AppExtension>(project, toolchain, this)
50+
is LibraryPlugin -> buildProjectForTarget<LibraryExtension>(project, toolchain, this)
51+
}
52+
}
53+
5254
copy { spec ->
5355
spec.from(File(project.projectDir, cargoOutputDir))
5456
spec.into(File(buildDir, "rustJniLibs/${toolchain.folder}"))
@@ -190,8 +192,7 @@ open class CargoBuildTask : DefaultTask() {
190192
environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY",
191193
File(project.rootProject.buildDir, "linker-wrapper/linker-wrapper.py").path)
192194
environment("RUST_ANDROID_GRADLE_CC", cc)
193-
environment("RUST_ANDROID_GRADLE_CC_LINK_ARG",
194-
"-o,target/${toolchain.target}/${cargoExtension.profile}/lib${cargoExtension.libname!!}.so")
195+
environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-o,$cargoOutputDir/lib${cargoExtension.libname!!}.so")
195196
}
196197

197198
cargoExtension.extraCargoBuildArguments?.let {

0 commit comments

Comments
 (0)