[Solved] Drop-in compiler replacement can't find std

I am trying to make a drop-in compiler replacement. Here's my source code.

#![feature(rustc_private)]
#![feature(link_args)]

extern crate rustc_driver;

fn main() {
    rustc_driver::set_sigpipe_handler();
    rustc_driver::main();
}

This is actually an exact copy of rustc source code.
I built, installed and exported this tool using an environment variable.

cargo install
export RUSTC=tool1    # `tool1` is name of binary

And I tried to build another project example1.
Here's source code of example1.

fn main() {}

Build failed with an error.

error[E0463]: can't find crate for `std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `foo2`.

To learn more, run the command again with --verbose.

I confirmed example1 got built well with normal cargo. It gets broken only with tool1. (export RUSTC=tool1) If I unset RUSTC, it works again.

It seems I made some fault, but I can't figure out what. How can I make it work?


Here're my tool informations.

rustc -V
rustc 1.28.0-nightly (a1d4a9503 2018-05-20)

cargo -V
cargo 1.28.0-nightly (f352115d5 2018-05-15)

Here's full example source code.


  • Cross-posted to many sites for maximum visibility.

There's a solution for this in StackOverflow