How to drive the rust compiler

I have forked stupid-stats in hopes of updating it to work with the latest compiler API (1.40) but I was only able to compile core. Each time trying to compiler something other than core I get can't find crate std. I don't understand exactly how the "linking" of crates happens in the compiler but I'm assuming this is my problem.

fn main() {
    let _ = rustc_driver::catch_fatal_errors(|| {
        let args: Vec<_> = std::env::args_os().flat_map(|s| s.into_string()).collect();
        rustc_driver::run_compiler(&args, &mut StupidCalls::new(), None, None)
    }).map_err(|e| println!("{:?}", e));
}

I have also tried passing the args that are used for cargo run by making an array of them copied from cargo run -vv.

I asked this question on the users forum they thought it more appropriate here.

Thanks for any feedback in advanced!

1 Like

MIRAI and rerast use the compiler driver and are regularly updated to work with the latest API, so you could use them as an example.

Regarding the error, I suspect that rustc fails to find the sysroot. You can see how MIRAI solves this problem here.

3 Likes

Thank you for the help.

I was attempting to tack on the --sysroot but instead of using option_env! i ran it as a Command::new and it was sticking a \n on the end, WOW 4 days and all it was was a \n :laughing:.

thanks again.

5 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.