forked from cross-rs/cross
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrustup.rs
56 lines (47 loc) · 1.52 KB
/
rustup.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::process::Command;
use Target;
use errors::*;
use extensions::CommandExt;
pub struct AvailableTargets {
triples: Vec<String>,
}
impl AvailableTargets {
pub fn contains(&self, target: &Target) -> bool {
let target = target.triple();
self.triples.iter().any(|t| t == target)
}
}
pub fn available_targets(verbose: bool) -> Result<AvailableTargets> {
let out = Command::new("rustup").args(&["target", "list"])
.run_and_get_stdout(verbose)?;
Ok(AvailableTargets {
triples: out.lines()
.filter_map(|line| if line.contains("installed") ||
line.contains("default") {
None
} else {
Some(line.to_owned())
})
.collect(),
})
}
pub fn install(target: &Target, verbose: bool) -> Result<()> {
let target = target.triple();
Command::new("rustup")
.args(&["target", "install", target])
.run(verbose)
.chain_err(|| format!("couldn't install `std` for {}", target))
}
pub fn install_rust_src(verbose: bool) -> Result<()> {
Command::new("rustup")
.args(&["component", "add", "rust-src"])
.run(verbose)
.chain_err(|| format!("couldn't install the `rust-src` component"))
}
pub fn rust_src_is_installed(verbose: bool) -> Result<bool> {
Ok(Command::new("rustup")
.args(&["component", "list"])
.run_and_get_stdout(verbose)?
.lines()
.any(|l| l.starts_with("rust-src") && l.contains("installed")))
}