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.
Inspecting tool1
shared libraries requirements reveals that the system can not locate Rust shared libraries (I'm on a Linux system so I use ldd
):
> ldd /home/adona/.cargo/bin/tool1
linux-vdso.so.1 => (0x00007ffed5938000)
librustc_driver-aabc67f1ff8e0e97.so => not found
libstd-46fff00efefae8a8.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa2d6f54000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa2d7521000)
Set RUSTFLAGS
with the -L
option if you want build through cargo
, for example:
export RUSTFLAGS="-L $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
If you want use tool1
directly from command line you have to configure the linker library path with ldconfig
command or with LD_LIBRARY_PATH
env variable:
export LD_LIBRARY_PATH=$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib:$LD_LIBRARY_PATH
Just a guess here, but I think your tool1
is not installed in the same folder as rustc
. Note that you may have an executable called rustc
in your cargo bin folder alongside your tool1
, but this rustc
is probably a rustup
wrapper that redirects to the real compiler somewhere in your toolchain folder (probably $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc
).
You will need to either install your tool1
inside the toolchain folder or call it with a -L
argument pointing to the toolchain libraries (probably $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With