set envvars

This commit is contained in:
Jana Dönszelmann 2026-02-20 12:40:07 +01:00
commit 3963fc50c3
No known key found for this signature in database
9 changed files with 3248 additions and 0 deletions

107
src/main.rs Normal file
View file

@ -0,0 +1,107 @@
use std::{
env::temp_dir,
ffi::OsString,
fs::{self, File},
path::PathBuf,
process::{Command, exit},
};
mod tui;
use clap::{Parser, Subcommand};
use jiff::Zoned;
#[derive(Subcommand, Debug)]
enum Preset {
/// Explore logs
Show,
/// Get all the typesystem related logs
Types,
/// Get all logs
All,
Crates {
#[arg(short, long)]
crates: Vec<String>,
},
}
fn default_tempdir() -> PathBuf {
temp_dir().join("rustc-logviz")
}
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[command(subcommand)]
preset: Preset,
#[arg(default_value_os_t = default_tempdir())]
#[arg(global = true)]
#[arg(long = "logs-dir")]
logs_dir: PathBuf,
#[arg(trailing_var_arg = true)]
#[arg(allow_hyphen_values = true)]
#[arg(global = true)]
rest: Vec<OsString>,
}
fn main() {
let Args {
preset,
logs_dir,
rest,
} = Args::parse();
let rustc_log = match preset {
Preset::Show => {
tui::run(logs_dir);
exit(0);
}
Preset::Types => {
"rustc_hir_typeck,rustc_infer,rustc_next_trait_solver,rustc_middle,rustc_traits,rustc_trait_selection,rustc_type_ir,rustc_ty_utils".to_string()
}
Preset::All => "debug".to_string(),
Preset::Crates { crates } => format!("{}", crates.join(",")),
};
let (first, rest) = {
let mut rest = rest.into_iter();
let Some(first) = rest.next() else {
eprintln!("no command given, exiting");
exit(0);
};
(first, rest.collect::<Vec<_>>())
};
if let Err(e) = fs::create_dir_all(&logs_dir) {
eprintln!("failed to create logs dir at {}: {e:?}", logs_dir.display());
exit(1)
}
let now = Zoned::now().strftime("%b %e %H:%M:%S");
let log_file_path = logs_dir.join(format!("{now}.log"));
let log_file = match File::create(&log_file_path) {
Ok(i) => i,
Err(e) => {
eprintln!(
"failed to create logfile at {}: {e:?}",
log_file_path.display()
);
exit(1)
}
};
eprintln!("outputting json logs to {}", log_file_path.display());
if let Err(e) = Command::new(first)
.args(rest)
.env("RUSTC_LOG", rustc_log)
.env("RUSTC_LOG_FORMAT_JSON", "1")
.env("RUSTC_LOG_OUTPUT_TARGET", log_file_path)
.status()
{
eprintln!("failed to spawn command: {e:?}, exiting");
exit(1);
}
}