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

Eon*_*nil 5 rust rust-cargo

我正在尝试替换嵌入式编译器。这是我的源代码。

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

extern crate rustc_driver;

fn main() {
    rustc_driver::set_sigpipe_handler();
    rustc_driver::main();
}
Run Code Online (Sandbox Code Playgroud)

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

cargo install
export RUSTC=tool1    # `tool1` is name of binary
Run Code Online (Sandbox Code Playgroud)

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

fn main() {}
Run Code Online (Sandbox Code Playgroud)

构建因错误而失败。

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.
Run Code Online (Sandbox Code Playgroud)

我确认example1建造正常cargo。它只被打破tool1。(export RUSTC=tool1)如果是I unset RUSTC,它将再次起作用。

看来我犯了一些错,但我不知道该怎么办。我该如何运作?


这是我的工具信息。

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

cargo -V
cargo 1.28.0-nightly (f352115d5 2018-05-15)
Run Code Online (Sandbox Code Playgroud)

这是完整的示例源代码。

att*_*ona 4

检查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)
Run Code Online (Sandbox Code Playgroud)

如果您想通过 构建,请RUSTFLAGS使用该选项进行设置,例如:-Lcargo

export RUSTFLAGS="-L $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
Run Code Online (Sandbox Code Playgroud)

如果您想tool1直接从命令行使用,则必须使用ldconfig命令或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
Run Code Online (Sandbox Code Playgroud)