我正在尝试遵循#![no-STD] 程序,但对于新架构上的新目标。
- 该体系结构是在LLVM上以实验目标(“ ARC”)上游的,但Rustc不使用它,因此首先我在LLVM中启用了Rust的LLVM,如说明
[llvm]
download-ci-llvm = false
ninja = true
targets = "X86"
experimental-targets = "ARC"
- 然后,我按照解释的步骤手动添加对拱门的支持,(使用此提交作为示例):
- 创建/src/abi/call/arc.rs
- 更新rustc_llvm/src/lib.rs
- 等,
- 然后我添加了目标文件
arc-pc-inknown-gnu.json
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-inknown-gnu library/core
。它成功完成了,我可以看到 stage1
libs的 arc-pc-pc-inknown-gnu
target
- 我认为这足够了,但是由于以下内容,代码没有编译问题:
$ 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
这很奇怪,因为在上一步,我应该为我的目标编译这些液体...
- 然后,我可能需要使用
cargo build build std
再次重建libcore(尽管我不喜欢't知道为什么确切,但是网上有人提到了这一点)吗?我尝试了此操作,但是现在有以下错误:
$ 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进行交叉编译,然后在我的#![no_std]示例编译中捡起。任何指导将不胜感激。
I'm trying to follow the steps explained in Embeddonomicon to compile the smallest #![no-std]
program, but for a new target on a new architecture.
- The architecture is upstreamed in LLVM as an experimental target ("ARC") but its not used by rustc, so first I enabled it in the LLVM that comes with Rust as explained here: run
./x.py setup
then update the config.toml:
[llvm]
download-ci-llvm = false
ninja = true
targets = "X86"
experimental-targets = "ARC"
- Then I manually added the support for the arch following the steps explained here (using this commit as an example):
- created rustc_target/src/abi/call/arc.rs
- updated rustc_llvm/src/lib.rs
- etc
- Then I added the target file
arc-pc-unknown-gnu.json
and made it visible through 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"
}
- Built the compiler:
./x.py build -i --target=arc-pc-unknown-gnu library/core
. It finished successfully, I could see stage1
libs for the arc-pc-unknown-gnu
target
- I thought this would be enough, but the code was not compiling because of the following issues:
$ 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
This is weird because on the previous step I should have compiled these very libs for my target...
- Then I though that perhaps I needed to rebuild libcore again using
cargo build-std
(although I don't know why exactly, but someone on the web mentioned this)? I tried this, but now there are the following errors:
$ 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")
| ^^^^^^^
...
How come that libcore
needs std
? I just want to have it cross-compiled using the stage1 rustc, and then picked up during my #![no_std] example compilation. Any guidance is appreciated.
发布评论
评论(1)
这就是我解决问题的方式:
使用正确的Rustc源代码。我从一个稳定的版本开始,该版本的libcore与最新的
Compiler_builtins
不兼容。请参阅此处有关更多详细信息。然后我需要升级到最新的每晚。构建编译器时,不要要求为最后阶段构建libcore,而仅构建Rustc:
.cargo/config.toml
,请勿使用XARGO < /code>或
-z build-std = core
。编译器builtins-mem
解释了此处。货物构建
构建代码。它的编译还不错,尽管稍后链接失败了 - 但这是另一个故事。That's how I solved the issue:
Use the right rustc source code. I started with a stable version whose libcore was not compatible with the latest
compiler_builtins
. See here for more details. Then I needed to upgrade to the latest nightly.When building the compiler, don't ask to build libcore for the final stage, instead build rustc only:
.cargo/config.toml
, don't useXargo
or-Z build-std=core
. Thecompiler-builtins-mem
thing is explained here.cargo build
. It compiled just fine, although it failed at linking later - but that's another story.