我试图按照Embeddonomicon中介绍的步骤编译最小的#![no-std]程序,但要在新的体系 struct 上实现新的目标.

  1. 该体系 struct 在LLVM中作为实验目标("ARC")处于upstream ,但它没有被Rust C使用,因此首先我在与Rust一起提供的LLVM中启用了它,如here所述:运行./x.py setup,然后更新配置.汤姆:
[llvm]
download-ci-llvm = false
ninja = true
targets = "X86"
experimental-targets = "ARC"
  1. 然后,我按照步骤here(以this commit为例)手动添加了对 arch 的支持:
  • 创建了rustc\u target/src/abi/call/arc.卢比
  • 更新rustc llvm/src/lib.RS
  1. 然后,我添加了目标文件arc-pc-unknown-gnu.json,并通过RUST_TARGET_PATH envvar使其可见:
{
  "arch": "arc",
  "cpu": "generic",
  "abi": "eabi",
  "c-enum-min-bits": 8,
  "data-layout": "e-m:e-p:32:32-i64:32-f64:32-v64:32-v128:32-a:0:32-n32",
  "eh-frame-header": false,
  "emit-debug-gdb-scripts": false,
  "executables": true,
  "features": "",
  "linker": "rust-lld",
  "linker-flavor": "ld.lld",
  "llvm-target": "arc-pc-unknown-gnu",
  "max-atomic-width": 32,
  "atomic-cas": false,
  "panic-strategy": "abort",
  "relocation-model": "static",
  "target-pointer-width": "32"
}
  1. 编译:./x.py build -i --target=arc-pc-unknown-gnu library/core.它成功完成了,我可以看到arc-pc-unknown-gnu个目标的stage1个libs
  2. 我认为这就足够了,但由于以下问题,代码没有编译:
$ rustc --emit=llvm-ir -o rust_main.ll -C panic=abort --target arc-pc-unknown-gnu src/main.rs
error[E0463]: can't find crate for `core`
  |
  = note: the `arc-pc-unknown-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add arc-pc-unknown-gnu`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

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

error[E0412]: cannot find type `PanicInfo` in this scope
  --> src/main.rs:18:18

这很奇怪,因为在上一步中,我应该为我的目标编译这些LIB...

  1. 然后我想也许我需要用cargo build-std重新构建libcore(虽然我不知道为什么,但网上有人提到了这一点)?我try 了此操作,但现在出现以下错误:
$ cargo build -Z build-std=core --target arc-pc-unknown-gnu
   Compiling compiler_builtins v0.1.70
   Compiling core v0.0.0 (/home/valeriyk/proj/rust-arc/1.60.0/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
error[E0463]: can't find crate for `std`

error: cannot find macro `println` in this scope
  --> /home/valeriyk/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/build.rs:88:9
   |
88 |         println!("cargo:rustc-cfg=kernel_user_helpers")
   |         ^^^^^^^

error: cannot find macro `println` in this scope
  --> /home/valeriyk/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/build.rs:78:9
   |
78 |         println!("cargo:rustc-cfg=thumb_1")
   |         ^^^^^^^
...

为什么libcore需要std?我只想让它使用stage1 rustc交叉编译,然后在我的#中提取![无标准]示例编译.感谢您的指导.

推荐答案

我就是这样解决这个问题的:

  1. 使用正确的rustc源代码.我从一个稳定的版本开始,它的libcore与最新的compiler_builtins不兼容.详见here.然后我需要每晚升级到最新版本.

  2. 构建编译器时,不要要求在最后阶段构建libcore,而是只构建rustc:

$ ./x.py build -i --stage=1 --target=arcv2-none-elf32 compiler/rustc
  1. 使用以下.cargo/config.toml,不要使用Xargo-Z build-std=core.compiler-builtins-mem的事情解释为here.
[unstable]
build-std = [
    "core",
    "compiler_builtins"
]
build-std-features = ["compiler-builtins-mem"]

[build]
target = "arcv2-none-elf32"
  1. 用一个简单的cargo build构建代码.它编译得很好,虽然后来链接失败了——但那是另一回事了.

Rust相关问答推荐

在actix—web中使用Redirect或NamedFile响应

为什么复印是豆荚的一个重要特征?

抽象RUST中的可变/不可变引用

在自身功能上实现类似移动的行为,以允许通过大小的所有者进行呼叫(&;mut;self)?

为潜在的下游实现使用泛型绑定而不是没有泛型绑定的trait

在不重写/专门化整个函数的情况下添加单个匹配手臂到特征的方法?

编译项目期间使用Cargo生成时出现rustc错误

在使用#[NO_STD]时,如何在Rust中收到紧急消息?

捕获FnMut闭包的时间不够长

无符号整数的Rust带符号差

unwrap 选项类型出现错误:无法移出共享引用后面的*foo

缺失serde的字段无法设置为默认值

按下 Ctrl + C 时优雅地停止命令并退出进程

如何在 nom 中构建负前瞻解析器?

Rust 跨同一文件夹中文件的可见性

为什么这个值在上次使用后没有下降?

编写 TOML 文件以反序列化为 struct 中的枚举

如何重写这个通用参数?

如何在 Rust 的内置函数上实现特征?

为什么我返回的 impl Trait 的生命周期限制在其输入的生命周期内?