插入式编译器替换找不到标准板条箱



我正在尝试替换一个直接的编译器。这是我的源代码。

#![feature(rustc_private)]
#![feature(link_args)]
extern crate rustc_driver;
fn main() {
rustc_driver::set_sigpipe_handler();
rustc_driver::main();
}

这实际上是rustc源代码的精确副本。 我使用环境变量构建、安装和导出此工具。

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

我试图example1构建另一个项目. 这是example1的源代码。

fn main() {}

生成失败并出现错误。

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.

我确认example1用正常的cargo建造得很好.它只会被tool1打破.(export RUSTC=tool1(如果我unset RUSTC,它会再次工作。

似乎我犯了一些错,但我不知道是什么。我怎样才能让它工作?


这是我的工具信息。

rustc -V
rustc 1.28.0-nightly (a1d4a9503 2018-05-20)
cargo -V
cargo 1.28.0-nightly (f352115d5 2018-05-15)

下面是完整的示例源代码。

检查tool1共享库需求会发现系统找不到 Rust 共享库(我在 Linux 系统上,所以我使用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)

如果要通过cargo构建,请使用-L选项设置RUSTFLAGS,例如:

export RUSTFLAGS="-L $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"

如果要直接从命令行使用tool1,则必须使用ldconfig命令或 env 变量配置链接器库路径LD_LIBRARY_PATH

export LD_LIBRARY_PATH=$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib:$LD_LIBRARY_PATH

这里只是一个猜测,但我认为您的tool1没有安装在与rustc相同的文件夹中。请注意,您的 cargo bintool1文件夹中可能有一个名为rustc的可执行文件,但此rustc可能是一个rustup包装器,可重定向到工具链文件夹中某处的真实编译器(可能是$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc(。

您需要将tool1安装在工具链文件夹中,或者使用指向工具链库的-L参数调用它(可能$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib(。

最新更新