forked from cross-rs/cross
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrustc.rs
62 lines (51 loc) · 1.29 KB
/
rustc.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
57
58
59
60
61
62
use std::path::PathBuf;
use std::process::Command;
use rustc_version::{Version, VersionMeta};
use Host;
use errors::*;
use extensions::CommandExt;
pub struct TargetList {
triples: Vec<String>,
}
impl TargetList {
pub fn contains(&self, triple: &str) -> bool {
self.triples.iter().any(|t| t == triple)
}
}
pub trait VersionMetaExt {
fn host(&self) -> Host;
fn needs_interpreter(&self) -> bool;
}
impl VersionMetaExt for VersionMeta {
fn host(&self) -> Host {
Host::from(&*self.host)
}
fn needs_interpreter(&self) -> bool {
!(self.semver >= Version {
major: 1,
minor: 19,
patch: 0,
pre: vec![],
build: vec![],
})
}
}
pub fn target_list(verbose: bool) -> Result<TargetList> {
Command::new("rustc")
.args(&["--print", "target-list"])
.run_and_get_stdout(verbose)
.map(|s| {
TargetList {
triples: s.lines().map(|l| l.to_owned()).collect(),
}
})
}
pub fn sysroot(verbose: bool) -> Result<PathBuf> {
let mut stdout = Command::new("rustc")
.args(&["--print", "sysroot"])
.run_and_get_stdout(verbose)?;
if stdout.ends_with('\n') {
stdout.pop();
}
Ok(PathBuf::from(stdout))
}