我试图按照Embeddonomicon中介绍的步骤编译最小的#![no-std]
程序,但要在新的体系 struct 上实现新的目标.
- 该体系 struct 在LLVM中作为实验目标("ARC")处于upstream ,但它没有被Rust C使用,因此首先我在与Rust一起提供的LLVM中启用了它,如here所述:运行
./x.py setup
,然后更新配置.汤姆:
[llvm]
download-ci-llvm = false
ninja = true
targets = "X86"
experimental-targets = "ARC"
- 然后,我按照步骤here(以this commit为例)手动添加了对 arch 的支持:
- 创建了rustc\u target/src/abi/call/arc.卢比
- 更新rustc llvm/src/lib.RS
- 等
- 然后,我添加了目标文件
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"
}
- 编译:
./x.py build -i --target=arc-pc-unknown-gnu library/core
.它成功完成了,我可以看到arc-pc-unknown-gnu
个目标的stage1
个libs - 我认为这就足够了,但由于以下问题,代码没有编译:
$ 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...
- 然后我想也许我需要用
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交叉编译,然后在我的#中提取![无标准]示例编译.感谢您的指导.