forked from topjohnwu/Magisk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch rustup_wrapper to Rust implementation
For better Windows portability
- Loading branch information
Showing
6 changed files
with
155 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "rustup_wrapper" | ||
version = "0.0.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
home = "0.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::env; | ||
use std::process::{Command, Stdio}; | ||
|
||
use home::cargo_home; | ||
|
||
/******************************** | ||
* Why do we need this wrapper? | ||
******************************** | ||
* | ||
* The command `rustup component list` does not work with custom toolchains: | ||
* > error: toolchain 'magisk' does not support components | ||
* | ||
* However, this command is used by several IDEs to determine available | ||
* components that can be used, such as clippy, rustfmt etc. | ||
* In this script, we simply redirect the output when using the nightly | ||
* channel if any `component` command failed. | ||
*/ | ||
|
||
fn main() -> std::io::Result<()> { | ||
let rustup = cargo_home()?.join("bin").join("rustup"); | ||
let argv: Vec<String> = env::args().skip(1).collect(); | ||
|
||
if argv.iter().any(|s| s == "component") { | ||
let status = Command::new(&rustup) | ||
.args(&argv) | ||
.stdout(Stdio::null()) | ||
.stderr(Stdio::null()) | ||
.status()?; | ||
if !status.success() { | ||
let mut cmd = Command::new(&rustup); | ||
cmd.arg("+nightly"); | ||
if argv[0].starts_with('+') { | ||
cmd.args(argv.iter().skip(1)); | ||
} else { | ||
cmd.args(&argv); | ||
} | ||
return cmd.status().map(|_| ()); | ||
} | ||
} | ||
|
||
// Simply pass through | ||
Command::new(&rustup).args(argv.iter()).status().map(|_| ()) | ||
} |