Skip to content

Commit d35dd9a

Browse files
committed
Allow to set cargo { rustupChannel = "..." }. Fixes #24.
1 parent 85dae59 commit d35dd9a

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,31 @@ On Linux,
410410
env RUST_ANDROID_GRADLE_CARGO_COMMAND=$HOME/.cargo/bin/cargo ./gradlew ...
411411
```
412412

413+
## Specifying Rust channel
414+
415+
Rust is released to three different "channels": stable, beta, and nightly (see
416+
https://rust-lang.github.io/rustup/concepts/channels.html). The `rustup` tool, which is how most
417+
people install Rust, allows multiple channels to be installed simultaneously and to specify which
418+
channel to use by invoking `cargo +channel ...`.
419+
420+
In order of preference, the plugin determines what channel to invoke `cargo` with by:
421+
422+
1. the value of `cargo { rustupChannel = "..." }`, if non-empty
423+
1. `rust.rustupChannel` in `${rootDir}/local.properties`
424+
1. the environment variable `RUST_ANDROID_GRADLE_RUSTUP_CHANNEL`
425+
1. the default, no channel specified (which `cargo` installed via `rustup` generally defaults to the
426+
`stable` channel)
427+
428+
The channel should be recognized by `cargo` installed via `rustup`, i.e.:
429+
- `"stable"`
430+
- `"beta"`
431+
- `"nightly"`
432+
433+
A single leading `'+'` will be stripped, if present.
434+
435+
(Note that Cargo installed by a method other than `rustup` will generally not understand `+channel`
436+
and builds will likely fail.)
437+
413438
## Passing arguments to cargo
414439

415440
The plugin passes project properties named like `RUST_ANDROID_GRADLE_target_..._KEY=VALUE` through

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ open class CargoBuildTask : DefaultTask() {
7878
standardOutput = System.out
7979
workingDir = File(project.project.projectDir, cargoExtension.module!!)
8080

81-
val theCommandLine = mutableListOf(cargoExtension.cargoCommand, "build");
81+
val theCommandLine = mutableListOf(cargoExtension.cargoCommand)
82+
83+
if (!cargoExtension.rustupChannel.isEmpty()) {
84+
val hasPlusSign = cargoExtension.rustupChannel.startsWith("+")
85+
val maybePlusSign = if (!hasPlusSign) "+" else ""
86+
87+
theCommandLine.add(maybePlusSign + cargoExtension.rustupChannel)
88+
}
89+
90+
theCommandLine.add("build")
8291

8392
// Respect `verbose` if it is set; otherwise, log if asked to
8493
// with `--info` or `--debug` from the command line.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ open class CargoExtension {
8383
}
8484
}
8585

86+
var rustupChannel: String = ""
87+
get() {
88+
return if (!field.isEmpty()) {
89+
field
90+
} else {
91+
getProperty("rust.rustupChannel", "RUST_ANDROID_GRADLE_RUSTUP_CHANNEL") ?: ""
92+
}
93+
}
94+
8695
var pythonCommand: String = ""
8796
get() {
8897
return if (!field.isEmpty()) {

0 commit comments

Comments
 (0)