# How to drive the rust compiler

**URL:** <https://internals.rust-lang.org/t/how-to-drive-the-rust-compiler/11542>\
**Category:** compiler\
**Created:** [December 26, 2019, 1:56pm UTC](https://internals.rust-lang.org/t/how-to-drive-the-rust-compiler/11542 "2019-12-26T13:56:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DevinR528](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/devinr528/32/5904_2.png) [@DevinR528](https://internals.rust-lang.org/u/DevinR528)\
**Post date:** [December 26, 2019, 1:56pm UTC](https://internals.rust-lang.org/t/how-to-drive-the-rust-compiler/11542/1 "2019-12-26T13:56:13Z")

</div>

I have forked [stupid-stats](https://github.com/DevinR528/stupid-stats/blob/b5df955a15204290dc338ae31c7860829fba1a27/src/mod.rs#L257-L272) 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.

```rust
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](https://users.rust-lang.org/t/how-to-drive-the-rust-compiler/36167/2) they thought it more appropriate here.

Thanks for any feedback in advanced!

---

<div class="post-metadata">

**Author:** ![vakaras](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vakaras/32/2156_2.png) [@vakaras](https://internals.rust-lang.org/u/vakaras)\
**Post date:** [December 26, 2019, 2:20pm UTC](https://internals.rust-lang.org/t/how-to-drive-the-rust-compiler/11542/2 "2019-12-26T14:20:57Z")

</div>

[MIRAI](https://github.com/facebookexperimental/MIRAI/blob/master/checker/src/main.rs#L79-L119) and [rerast](https://github.com/google/rerast/blob/master/src/lib.rs#L161-L163) 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](https://github.com/facebookexperimental/MIRAI/blob/master/checker/src/main.rs#L86-L95).

---

<div class="post-metadata">

**Author:** ![DevinR528](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/devinr528/32/5904_2.png) [@DevinR528](https://internals.rust-lang.org/u/DevinR528)\
**Post date:** [December 26, 2019, 2:44pm UTC](https://internals.rust-lang.org/t/how-to-drive-the-rust-compiler/11542/3 "2019-12-26T14:44:50Z")

</div>

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` 😆.

thanks again.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2020, 2:44pm UTC](https://internals.rust-lang.org/t/how-to-drive-the-rust-compiler/11542/4 "2020-03-25T14:44:53Z")

</div>

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