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.

Thanks for any feedback in advanced!

This is better asked on internals.rust-lang.org, there are lots of people there who know how the compiler works

1 Like

Re-posted at:

1 Like

You should check out the rustc_driver crate, in particular the Callbacks trait (as called by rustc_driver::run_compiler()) is the easiest way to hook into the compiler.

The nightly-rustc docs are invaluable for finding your way around.

You may also find The Rustc Guide useful for understanding how it all fits together at a high level.

2 Likes

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