3

I tried to compile rust-src using cargo xbuild but get this error:

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)]

How can I fix this error? It's seem like xbuild tries to compile the new rust-src with an old rustc. I want it to also use the old rust-src.

I can't update to a newer rustc version as it results in lots of "R_x86_32 relocation" errors, so I would prefer to use the 2020-03-24 version.

Minimal example

command

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-toolchain

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 {}
}

compile

cargo xbuild --target x86_64-unknown-none

rustc --version

rustc 1.44.0-nightly (1edd389cc 2020-03-23)
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
William Taylor
  • 549
  • 3
  • 22
  • You cannot compile new nightly code with an old nightly compiler — there's no stability guarantees for nightly builds. You need to use new code and a new compiler or old code and an old compiler. You've already eliminated one of those possibilities, leaving you with only the other. – Shepmaster May 12 '20 at 15:29
  • how can i use old code then? should i download old code from github and copy it to specific folder? – William Taylor May 12 '20 at 15:31
  • [How to specify the exact version of a dependency?](https://stackoverflow.com/q/45224563/155423); [Set specific version of the dependency of a project's dependency in Cargo.toml or Cargo.lock](https://stackoverflow.com/q/27770031/155423) – Shepmaster May 12 '20 at 15:33
  • in my case, it a component called 'rust-src', not some crate or dependency. – William Taylor May 12 '20 at 15:35
  • It's hard to answer your question because it doesn't include a [MRE]. We can't tell what crates (and their versions), types, traits, fields, etc. are present in the code. It would make it easier for us to help you if you try to reproduce your error on the [Rust Playground](https://play.rust-lang.org) if possible, otherwise in a brand new Cargo project, then [edit] your question to include the additional info. There are [Rust-specific MRE tips](//stackoverflow.com/tags/rust/info) you can use to reduce your original code for posting here. Thanks! – Shepmaster May 12 '20 at 15:39

2 Answers2

4

This is a bug in cargo-xbuild. Basically, cargo xbuild unconditionally fetches the latest compiler_builtins.

A patch has been merged, but is not yet in the latest crates.io release. See this PR: https://github.com/rust-osdev/cargo-xbuild/pull/75/commits/eede1a1d4c08064763f1943c0920de2270260b33

sjero
  • 56
  • 1
  • Yeah, it's indeed a bug in xbuild. New xbuild work perfect! – William Taylor May 14 '20 at 02:19
  • The command linked in that issue almost works, though the mentioned branch no longer exists. `master` worked for me: `cargo install cargo-xbuild --git https://github.com/rust-osdev/cargo-xbuild.git --branch master --debug --force` – phs May 16 '20 at 00:13
  • Note that this change has now been pulled into `cargo xbuild` version `0.5.32`. Unfortunately, that version also causes xbuild to use the `embed-bitcode` option to `rustc`, which was introduced in late March 2020. If you are using an older `rustc` version, you will need to build `cargo xbuild` from source using this commit: https://github.com/rust-osdev/cargo-xbuild/commit/cf1128abaaa61a6f73d1276d30bbda530a188e76 – sjero May 21 '20 at 19:20
-1

Update your rust version by rustup update, which works for me.

The reason may be the feature rename in new version : https://github.com/rust-lang/rust/pull/71007

zebin Li
  • 1
  • 1