@@ -12,6 +12,7 @@ import java.io.File
12
12
13
13
open class CargoBuildTask : DefaultTask () {
14
14
var toolchain: Toolchain ? = null
15
+ lateinit var cargoOutputDir: String
15
16
16
17
17
18
@Suppress(" unused" )
@@ -23,13 +24,6 @@ open class CargoBuildTask : DefaultTask() {
23
24
if (toolchain == null ) {
24
25
throw GradleException (" toolchain cannot be null" )
25
26
}
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
- }
33
27
// CARGO_TARGET_DIR can be used to force the use of a global, shared target directory
34
28
// across all rust projects on a machine. Use it if it's set, otherwise use the
35
29
// configured `targetDirectory` value, and fall back to `${module}/target`.
@@ -44,11 +38,19 @@ open class CargoBuildTask : DefaultTask() {
44
38
45
39
val defaultTargetTriple = getDefaultTargetTriple(project, rustcCommand)
46
40
47
- val cargoOutputDir = if (toolchain.target == defaultTargetTriple) {
41
+ cargoOutputDir = if (toolchain.target == defaultTargetTriple) {
48
42
" ${targetDirectory} /${profile} "
49
43
} else {
50
44
" ${targetDirectory} /${toolchain.target} /${profile} "
51
45
}
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
+
52
54
copy { spec ->
53
55
spec.from(File (project.projectDir, cargoOutputDir))
54
56
spec.into(File (buildDir, " rustJniLibs/${toolchain.folder} " ))
@@ -190,8 +192,7 @@ open class CargoBuildTask : DefaultTask() {
190
192
environment(" RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY" ,
191
193
File (project.rootProject.buildDir, " linker-wrapper/linker-wrapper.py" ).path)
192
194
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" )
195
196
}
196
197
197
198
cargoExtension.extraCargoBuildArguments?.let {
0 commit comments