#![feature(rustc_private)]
#[macro_use]
extern crate rapx;
use rapx::utils::log::{init_log, rap_error_and_exit};
mod args;
mod help;
mod utils;
use crate::utils::*;
mod cargo_check;
fn phase_cargo_rap() {
rap_trace!("Start cargo-rapx.");
let Some(arg) = args::get_arg(2) else {
rap_error!("Expect command: e.g., `cargo rapx -help`.");
return;
};
match arg {
"-version" | "-v" | "--version" => {
println!("{}", help::RAPX_VERSION);
return;
}
"-help" | "-h" | "--help" => {
println!("{}", help::RAPX_HELP);
return;
}
_ => {}
}
cargo_check::run();
}
fn phase_rustc_wrapper() {
rap_trace!("Launch cargo-rapx again triggered by cargo check.");
let is_direct = args::is_current_compile_crate();
if is_direct && args::filter_crate_type() {
run_rap();
return;
}
run_rustc();
}
fn main() {
init_log().expect("Failed to init log.");
match args::get_arg(1).unwrap() {
s if s.ends_with("rapx") => phase_cargo_rap(),
s if s.ends_with("rustc") => phase_rustc_wrapper(),
_ => rap_error_and_exit(
"rapx must be called with either `rap` or `rustc` as first argument.",
),
}
}