-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathcross.rs
52 lines (48 loc) · 2.01 KB
/
cross.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
#![deny(missing_debug_implementations, rust_2018_idioms)]
use std::{
env,
io::{self, Write},
};
use cross::{
cargo, cli, rustc,
shell::{self, Verbosity},
CargoConfig, CargoToml, OutputExt, Subcommand,
};
pub fn main() -> cross::Result<()> {
cross::install_panic_hook()?;
cross::install_termination_hook()?;
let target_list = rustc::target_list(&mut Verbosity::Quiet.into())?;
let cargo_toml = CargoToml::read()?;
let cargo_config = CargoConfig::new(cargo_toml);
let args = cli::parse(&target_list, &cargo_config)?;
let subcommand = args.subcommand;
let mut msg_info = shell::MessageInfo::create(args.verbose, args.quiet, args.color.as_deref())?;
let status = match cross::run(args, target_list, cargo_config, &mut msg_info)? {
Some(status) => status,
None => {
// if we fallback to the host cargo, use the same invocation that was made to cross
let argv: Vec<String> = env::args().skip(1).collect();
msg_info.note("Falling back to `cargo` on the host.")?;
match subcommand {
Some(Subcommand::List) => {
// this won't print in order if we have both stdout and stderr.
let out = cargo::run_and_get_output(&argv, &mut msg_info)?;
let stdout = out.stdout()?;
if out.status.success() && cli::is_subcommand_list(&stdout) {
cli::fmt_subcommands(&stdout, &mut msg_info)?;
} else {
// Not a list subcommand, which can happen with weird edge-cases.
print!("{}", stdout);
io::stdout().flush().expect("could not flush");
}
out.status
}
_ => cargo::run(&argv, &mut msg_info)?,
}
}
};
let code = status
.code()
.ok_or_else(|| eyre::Report::msg("Cargo process terminated by signal"))?;
std::process::exit(code)
}