File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
plugin/src/main/kotlin/com/nishtahir Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -215,14 +215,21 @@ cargo {
215
215
216
216
### targetDirectory
217
217
218
- The target directory into which Cargo writes built outputs.
218
+ The target directory into which Cargo writes built outputs. You will likely need to specify this
219
+ if you are using a [ cargo virtual workspace] ( https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html ) ,
220
+ as our default will likely fail to locate the correct target directory.
219
221
220
222
Defaults to ` ${module}/target ` . ` targetDirectory ` is interpreted as a relative path to the Gradle
221
223
` projectDir ` .
222
224
225
+ Note that if ` CARGO_TARGET_DIR ` (see https://doc.rust-lang.org/cargo/reference/environment-variables.html )
226
+ is specified in the environment, it takes precedence over ` targetDirectory ` , as cargo will output
227
+ all build artifacts to it, regardless of what is being built, or where it was invoked.
228
+
223
229
``` groovy
224
230
cargo {
225
- targetDirectory = 'release'
231
+ // Note: path is relative to the gradle project root.
232
+ targetDirectory = 'path/to/workspace/root/target'
226
233
}
227
234
```
228
235
Original file line number Diff line number Diff line change @@ -31,8 +31,12 @@ open class CargoBuildTask : DefaultTask() {
31
31
is LibraryPlugin -> buildProjectForTarget<LibraryExtension >(project, toolchain, this )
32
32
}
33
33
}
34
-
35
- val targetDirectory = targetDirectory ? : " ${module!! } /target"
34
+ // CARGO_TARGET_DIR can be used to force the use of a global, shared target directory
35
+ // across all rust projects on a machine. Use it if it's set, otherwise use the
36
+ // configured `targetDirectory` value, and fall back to `${module}/target`.
37
+ val targetDirectory = System .getenv(" CARGO_TARGET_DIR" )
38
+ ? : targetDirectory
39
+ ? : " ${module!! } /target"
36
40
37
41
val cargoOutputDir = if (toolchain.target == defaultTargetTriple) {
38
42
" ${targetDirectory} /${profile} "
You can’t perform that action at this time.
0 commit comments