编译Rust源代码时遇到未知特性`llvm_asm`。

3
我尝试使用cargo xbuild编译rust-src,但遇到了以下错误:
error[E0635]: unknown feature `llvm_asm`
-> .cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.28/src/lib.rs:3:12
3 | #![feature(llvm_asm)]

如何修复这个错误?看起来xbuild试图用旧的rustc编译新的rust-src。我希望它也使用旧的rust-src。

我无法更新到新版本的rustc,因为它会导致大量的“R_x86_32 relocation”错误,所以我更喜欢使用2020-03-24版本。

最小示例

命令

cargo new --bin test

rustup component add rust-src

cargo install cargo-xbuild

cd test

ls test
Cargo.toml  rust-toolchain  src  x86_64-unknown-none.json

Rust工具链
nightly-2020-03-24

x86_64-unknown-none.json

{
  "llvm-target": "x86_64-unknown-none",
  "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
  "arch": "x86_64",
  "target-endian": "little",
  "target-pointer-width": "64",
  "target-c-int-width": "32",
  "os": "none",
  "executables": true,
  "linker-flavor": "ld.lld",
  "linker": "rust-lld",
  "panic-strategy": "abort",
  "disable-redzone": true,
  "features": "-mmx,-sse,+soft-float"
}

src/main.rs

#![no_std]                // don't link the Rust standard library
#![no_main]               // disable all Rust-level entry points
#![allow(non_snake_case)] // disable non snake case name warning

use core::panic::PanicInfo;

#[no_mangle]
pub extern "C" fn _start() -> ! {
    loop {}
}

#[panic_handler]
pub fn MyPacnicHandler(_panicInfo: &PanicInfo) -> ! {
    loop {}
}

编译

cargo xbuild --target x86_64-unknown-none

rustc --version

rustc 1.44.0-nightly (1edd389cc 2020-03-23)

你不能使用旧的夜间编译器编译新的夜间代码——对于夜间构建,没有稳定性保证。你需要使用新的代码和新的编译器或旧的代码和旧的编译器。你已经排除了其中一种可能性,只剩下另一种。 - Shepmaster
我该如何使用旧代码呢?我需要从GitHub下载旧代码并将其复制到特定文件夹中吗? - William Taylor
如何指定依赖项的确切版本?(https://dev59.com/hlcO5IYBdhLWcg3wy0n6);在Cargo.toml或Cargo.lock中设置项目依赖项的特定版本(https://dev59.com/gV4c5IYBdhLWcg3wj7F6) - Shepmaster
在我的情况下,它是一个叫做'rust-src'的组件,而不是某个crate或依赖项。 - William Taylor
很难回答你的问题,因为它没有包含一个 [MRE]。我们无法确定代码中存在哪些 crates(及其版本)、types、traits、fields等。如果可能的话,您可以在Rust Playground上尝试重现错误,否则可以在全新的Cargo项目中进行,然后[编辑]您的问题以包括额外的信息。这里有一些Rust特定的MRE提示,您可以使用它们来缩小您的原始代码以便在此处发布。谢谢! - Shepmaster
2个回答

4

是的,这确实是xbuild中的一个bug。新的xbuild工作得很完美! - William Taylor
该问题中提到的命令几乎可以使用,但是所提到的分支已不存在。对我来说,“master”可行:cargo install cargo-xbuild --git https://github.com/rust-osdev/cargo-xbuild.git --branch master --debug --force - phs
请注意,此更改现已合并到 cargo xbuild 版本 0.5.32 中。不幸的是,该版本还会导致 xbuild 使用在 2020 年 3 月底引入的 embed-bitcode 选项到 rustc。如果您使用较旧的 rustc 版本,则需要使用此提交从源代码构建 cargo xbuild:https://github.com/rust-osdev/cargo-xbuild/commit/cf1128abaaa61a6f73d1276d30bbda530a188e76 - sjero

-1

从OP:注意:我无法更新到更新的rustc版本 - Shepmaster
1
@Shepmaster 很抱歉没有看到你的评论,你是对的。这个答案在这里不合适,但也许其他人可以看到它。 - zebin Li

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接