Skip to content

Commit f500a2b

Browse files
committed
Greatly simplify the driver
- Remove sysroot handling. Since rust-lang/rust#103660 this is detected automatically! - Update to a newer toolchain; in particular `install_ice_hook` has changed its signature. - Remove the wrapper code; it only matters for cargo plugins, but ubrustc only has an equivalent of clippy-driver, not cargo-clippy.
1 parent 5ab8b63 commit f500a2b

File tree

1 file changed

+3
-84
lines changed

1 file changed

+3
-84
lines changed

src/main.rs

+3-84
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ use rustc_driver::Callbacks;
99
use rustc_hir::def_id::LocalDefId;
1010
use rustc_interface::interface;
1111
use rustc_middle::mir::BorrowCheckResult;
12-
use rustc_middle::ty::query::{ExternProviders, Providers};
12+
use rustc_middle::query::{ExternProviders, Providers};
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::Session;
15-
use std::ffi::OsStr;
16-
use std::path::{Path, PathBuf};
1715

1816
struct UbrustcCallbacks;
1917

@@ -37,93 +35,14 @@ fn not_a_borrowchecker(cx: TyCtxt<'_>, _: LocalDefId) -> &'_ BorrowCheckResult<'
3735
}
3836

3937
fn main() {
40-
rustc_driver::install_ice_hook();
38+
rustc_driver::install_ice_hook("https://github.com/thomcc/ubrustc/issues/new", |_| ());
4139
rustc_driver::init_rustc_env_logger();
4240
std::process::exit(rustc_driver::catch_with_exit_code(move || {
43-
let orig_args: Vec<String> = std::env::args().collect();
44-
45-
let sysroot_arg = arg_value(&orig_args, "--sysroot");
46-
let have_sysroot_arg = sysroot_arg.is_some();
47-
let sysroot = sysroot_arg
48-
.map(ToString::to_string)
49-
.or_else(|| sysroot().map(|p| p.display().to_string()))
50-
.expect("Failed to find sysroot");
51-
52-
let mut args: Vec<String> = orig_args.clone();
53-
54-
if !have_sysroot_arg {
55-
args.extend(["--sysroot".to_string(), sysroot.to_string()]);
56-
}
57-
58-
let our_exe_filename = std::env::current_exe()
59-
.ok()
60-
.and_then(|p| p.file_stem().map(ToOwned::to_owned))
61-
.unwrap_or_else(|| "ubrustc".into());
62-
63-
// This is probably wrong.
64-
let wrapper_mode = orig_args
65-
.get(1)
66-
.map(std::path::Path::new)
67-
.and_then(std::path::Path::file_stem)
68-
.map_or(false, |name| {
69-
name == our_exe_filename || name == "ubrustc" || name == "rustc"
70-
});
71-
72-
if wrapper_mode {
73-
args.remove(1);
74-
}
41+
let args: Vec<String> = std::env::args().collect();
7542
run_compiler(args, &mut UbrustcCallbacks);
7643
}))
7744
}
7845

79-
fn arg_value<'a, T: AsRef<str>>(args: &'a [T], find_arg: &str) -> Option<&'a str> {
80-
let mut args = args.iter().map(|s| s.as_ref());
81-
while let Some(arg) = args.next() {
82-
let mut arg = arg.splitn(2, '=');
83-
if arg.next() != Some(find_arg) {
84-
continue;
85-
}
86-
87-
if let Some(a) = arg.next().or_else(|| args.next()) {
88-
return Some(a);
89-
}
90-
}
91-
None
92-
}
93-
94-
fn sysroot() -> Option<PathBuf> {
95-
fn rustup_sysroot<H: ?Sized + AsRef<OsStr>, T: ?Sized + AsRef<Path>>(
96-
home: &H,
97-
toolchain: &T,
98-
) -> PathBuf {
99-
let mut path = PathBuf::from(home);
100-
path.push("toolchains");
101-
path.push(toolchain);
102-
path
103-
}
104-
fn runtime_rustup_sysroot() -> Option<PathBuf> {
105-
let home = std::env::var_os("RUSTUP_HOME")?;
106-
let toolchain = std::env::var_os("RUSTUP_TOOLCHAIN")?;
107-
Some(rustup_sysroot(&home, &toolchain))
108-
}
109-
fn compiletime_rustup_sysroot() -> Option<PathBuf> {
110-
let home: &str = option_env!("RUSTUP_HOME")?;
111-
let toolchain: &str = option_env!("RUSTUP_TOOLCHAIN")?;
112-
Some(rustup_sysroot(&home, &toolchain))
113-
}
114-
fn rustc_on_path_sysroot() -> Option<PathBuf> {
115-
std::process::Command::new("rustc")
116-
.arg("--print=sysroot")
117-
.output()
118-
.ok()
119-
.and_then(|out| String::from_utf8(out.stdout).ok())
120-
.map(|s| PathBuf::from(s.trim()))
121-
}
122-
runtime_rustup_sysroot()
123-
.or_else(rustc_on_path_sysroot)
124-
.or_else(compiletime_rustup_sysroot)
125-
}
126-
12746
fn run_compiler<CB: Callbacks + Send>(mut args: Vec<String>, callbacks: &mut CB) -> ! {
12847
args.splice(1..1, std::iter::once("--cfg=ubrustc".to_string()));
12948
std::process::exit(rustc_driver::catch_with_exit_code(move || {

0 commit comments

Comments
 (0)