Rust build error: unknown `--json` option `future-incompat` - rust

I am trying to build a basic application for the Adafruit CLUE using Rust.
When using the peripheral access crate (PAC) everything works fine, but I would like to use the HAL crate from Nordic Semiconductors.
I set up a very basic project which uses their nrf52840-hal crate. When running cargo build, I get the following error (full build log with --verbose):
Updating crates.io index
Compiling semver-parser v0.7.0
Compiling cortex-m v0.7.4
Compiling proc-macro2 v1.0.37
Compiling nb v1.0.0
Compiling unicode-xid v0.2.3
Compiling syn v1.0.92
Compiling vcell v0.1.3
Compiling void v1.0.2
Compiling bitfield v0.13.2
Compiling cortex-m-rt v0.7.1
Compiling critical-section v0.2.7
Compiling typenum v1.15.0
info: syncing channel updates for 'nightly-2021-08-18-x86_64-unknown-linux-gnu'
Compiling az v1.2.0
Compiling nrf52840-pac v0.11.0
info: latest update on 2021-08-18, rust version 1.56.0-nightly (30a0a9b69 2021-08-17)
Compiling fixed v1.15.0
Compiling cfg-if v1.0.0
info: component 'rust-src' is up to date
info: component 'rust-std' for target 'riscv32imac-unknown-none-elf' is up to date
info: component 'rust-std' for target 'riscv32imc-unknown-none-elf' is up to date
info: component 'rust-std' for target 'thumbv6m-none-eabi' is up to date
info: component 'rust-std' for target 'thumbv7em-none-eabi' is up to date
info: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is up to date
warning: Force-skipping unavailable component 'rust-std-avr-specs/avr-atmpeg328p.json'
Compiling bare-metal v1.0.0
error: unknown `--json` option `future-incompat`
Compiling half v1.8.2
error: could not compile `critical-section`
warning: build failed, waiting for other jobs to finish...
error: build failed
I am using rustup with the stable toolchain on Ubuntu 20.04 (using nighly 2022-05-03 does not change anything to the error message). Rustup version output is:
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.60.0 (7737e0b5c 2022-04-04)`
The full project is available here.
My .cargo/config.toml file is:
[build]
target = "thumbv7em-none-eabihf"
rustflags = [
"-C", "link-arg=-Tlink.x",
]
The Cargo.toml is:
[package]
name = "hal-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cortex-m-rt = "0.7.1"
nrf52840-hal = "0.15.0"
panic-halt = "0.2.0"
and the src/main.rs file is:
#![no_std]
#![no_main]
use panic_halt as _;
#[cortex_m_rt::entry]
fn main() -> ! {
loop {}
}
I tried to go through the dependency tree but I failed to find where this future-incompat option is added, given that it is passed plenty of times to rustc and it succeeds.
I would appreciate any pointers as to where to look further.
Update 2022-05-06: building the project with the exact same toolchain version on Ubuntu 21.04 works, I'll have to investigate further.

The issue was fixed by switching away from the rustup snap and using the recommended installation method of running the shell script (https://www.rust-lang.org/tools/install).

Related

cargo run/build is stuck on last file

When running cargo build or cargo run on a specific rust project (base_names), it gets stuck on the last file. Output:
Compiling autocfg v1.1.0
Compiling proc-macro2 v1.0.47
Compiling quote v1.0.21
Compiling unicode-ident v1.0.5
Compiling proc-macro-hack v0.5.19
Compiling syn v1.0.102
Compiling radium v0.6.2
Compiling tap v1.0.1
Compiling funty v1.2.0
Compiling lazy_static v1.4.0
Compiling primes v0.3.0
Compiling wyz v0.4.0
Compiling num-traits v0.2.15
Compiling num-integer v0.1.45
Compiling num-bigint v0.4.3
Compiling num-rational v0.4.1
Compiling num-iter v0.1.43
Compiling bitvec v0.22.3
Compiling num-complex v0.4.2
Compiling num v0.4.0
Compiling fraction v0.12.0
Compiling arr_macro_impl v0.1.3
Compiling arr_macro v0.1.3
Compiling base_names v0.1.0 (/home/max/Documents/Projects/base_names)
Building [=========================> ] 43/44: base_names(bin)
I've tried:
cargo clean
rustup update
pkill cargo
pkill rls
running from vscode and terminal
trying existing rust projects (they work fine, so it's project-specific)
creating a new rust project and copying in Cargo.toml + the contents of src
Environment: Linux (Fedora Workstation 36)
Cargo.toml contents:
[package]
name = "base_names"
version = "0.1.0"
edition = "2021"
[dependencies]
primes = "0.3.0"
fraction = "0.12.0"
bitvec = "0.22.3"
arr_macro = "0.1.3"
Thanks to Locke for figuring it out. I used the arr_macro package to write
arr![Default::default(); 100_000]
which expands into 100 000 instances of Default::default(), making compilation take too long.
For cases where:
you need a list of structs
the generator needs access to the previous structs
the trait Copy can't be implemented on your struct
you should use a Vec instead.

Build fails with Error: Pear requires a 'dev' or 'nightly' version of rustc even after a successful rustup override set nightly

Windows 10
rustup 1.23.1 (3df2264a9 2020-11-30)
default rustc 1.50.0 (cb75ad5db 2021-02-10)
project rustc 1.52.0-nightly (4a8b6f708 2021-03-11)
rocket = "0.4.4"
I'm trying to build a rust project with rocket but I always get this error when compiling, even after successfully overwriting the project's toolchain:
D:\GitHub\Learning-Rust\poke_api> rustup override set nightly
info: using existing install for 'nightly-x86_64-pc-windows-msvc'
info: override toolchain for 'D:\GitHub\Learning-Rust\poke_api' set to 'nightly-x86_64-pc-windows-msvc'
nightly-x86_64-pc-windows-msvc unchanged - rustc 1.52.0-nightly (4a8b6f708 2021-03-11)
PS D:\GitHub\Learning-Rust\poke_api> cargo build
Compiling winapi v0.3.9
Compiling serde_derive v1.0.124
Compiling rocket v0.4.7
Compiling pear_codegen v0.1.4
Compiling rocket_codegen v0.4.7
Compiling proc-macro2 v1.0.24
Compiling pq-sys v0.4.6
Compiling aho-corasick v0.6.10
Compiling serde_json v1.0.64
error: failed to run custom build command for `pear_codegen v0.1.4`
Caused by:
process didn't exit successfully: `D:\GitHub\Learning-Rust\poke_api\target\debug\build\pear_codegen-e182711746033ac9\build-script-build` (exit code: 101)
--- stderr
Error: Pear requires a 'dev' or 'nightly' version of rustc.
Installed version: 1.48.0 (2020-11-16)
Minimum required: 1.31.0-nightly (2018-10-05)
thread 'main' panicked at 'Aborting compilation due to incompatible compiler.', C:\Users\gabre\.cargo\registry\src\github.com-1ecc6299db9ec823\pear_codegen-0.1.4\build.rs:24:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
I had a similar issue while using rocket. Same error message too, Error: Pear requires a 'dev' or 'nightly' version of rustc.
If you get to the get-started page on rocket framework website. It says, "Rocket makes abundant use of Rust's syntax extensions and other advanced, unstable features. Because of this, we'll need to use a nightly version of Rust."
My issue was I was not using a nightly version of rust. Running this on my terminal in my project directory did it for me.
rustup override set nightly
If you check the cargo version for that directory after,
cargo version
you will confirm it has switched to nightly version
Failed compilation even with nightly
It looks like you have some outdated dependencies (pear-codegen probably being the one that causes trouble), updating these may resolve the compilation issues.
General notes on how to override the toolchain
Using rustups override works fine, but it is bound to your local rustup configuration and not specified inside the project.
In order to achieve this, thereby making the project more portable and allowing others to always use the correct toolchain, I would recommend the toolchain file. It can look something like this (example taken from linked page) and will accurately specify the required toolchain only for the containing project.
# rust-toolchain.toml
[toolchain]
channel = "nightly-2020-07-10"
components = [ "rustfmt", "rustc-dev" ]
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
profile = "minimal"
For your purposes a simple configuration like this will most likely be all you need, although adding the components you want to use would be beneficial.
[toolchain]
channel = "nightly"
My issue was with rust-analyser that wouldn't start because multiple rocket dependencies needed nightly or dev version of rustc.
These steps fixed my issue:
Switch to nightly for my rocket project by running rustup override set nightly inside the app folder.
Remove all target folders in my project. (I also had one in root)
Manually remove the faulty cached packages from cargo cache. cd ~/.cargo/registry/cache/github.com-xxxxxxxxxxxx && rm -r pear_codegen-0.1.5/

error[E0463]: can't find crate for `core` note: the `thumbv7m-none-eabi` target may not be installed

I'm trying to blink the led on a bluepill (arm STM32) and followed the instructions from this tutorial, but i run into this error when i try to compile the code. i use ubuntu.
i just installed rust / cargo as figured in the tutorial.
i have stlink installed, i have no experience with rust, cargo or bluepil.
$ cargo build --release:
error[E0463]: can't find crate for `core`
|
= note: the `thumbv7m-none-eabi` target may not be installed
does it depend on the ./cargo/config file?
$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/marco/snap/rustup/common/rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
installed targets for active toolchain
--------------------------------------
thumbv7m-none-eabi
x86_64-unknown-linux-gnu
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.46.0 (04488afe3 2020-08-24)
$ rustup target add thumbv7em-none-eabi
info: downloading component 'rust-std' for 'thumbv7em-none-eabi'
info: installing component 'rust-std' for 'thumbv7em-none-eabi'
info: Defaulting to 500.0 MiB unpack ram
$ cargo build --release
Compiling semver-parser v0.7.0
Compiling typenum v1.12.0
Compiling proc-macro2 v1.0.19
Compiling unicode-xid v0.2.1
Compiling syn v1.0.39
Compiling stable_deref_trait v1.2.0
error[E0463]: can't find crate for `core`
|
= note: the `thumbv7m-none-eabi` target may not be installed
Does it depend on the name in the "Cargo.toml" file? What am i doing wrong?
export PATH="$HOME/.cargo/bin:$PATH"

llvm-sys - Didn't find usable system-wide LLVM

I'm trying to learn LLVM to make a programming language using Rust. I am using the llvm-sys crate that wraps around the LLVM API.
I have installed LLVM : LLVM-8.0.0-win64
My dependencies in cargo.toml
[dependencies]
llvm-sys = "80.1.1"
When I run cargo run I get the following error,
Updating crates.io index
Compiling memchr v2.2.1
Compiling lazy_static v1.4.0
Compiling regex-syntax v0.6.12
Compiling semver-parser v0.7.0
Compiling libc v0.2.65
Compiling cc v1.0.47
Compiling thread_local v0.3.6
Compiling semver v0.9.0
Compiling aho-corasick v0.7.6
Compiling regex v1.3.1
Compiling llvm-sys v80.1.1
error: failed to run custom build command for `llvm-sys v80.1.1`
Caused by:
process didn't exit successfully: `C:\Users\Name\Desktop\Carbon\carbon-lang\target\debug\build\llvm-sys-ed5d351b1ae6a41b\build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=LLVM_SYS_80_PREFIX
cargo:rerun-if-env-changed=LLVM_SYS_80_IGNORE_BLACKLIST
cargo:rerun-if-env-changed=LLVM_SYS_80_STRICT_VERSIONING
cargo:rerun-if-env-changed=LLVM_SYS_80_NO_CLEAN_CFLAGS
cargo:rerun-if-env-changed=LLVM_SYS_80_USE_DEBUG_MSVCRT
cargo:rerun-if-env-changed=LLVM_SYS_80_FFI_WORKAROUND
Didn't find usable system-wide LLVM.
--- stderr
thread 'main' panicked at 'Failed to execute "C:\\Program Files\\LLVM\\bin\\llvm-config": Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', src\libcore\result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
But I have set the LLVM_SYS_80_PREFIX as C:\Program Files\LLVM which is where the bin folder is.
Should the llvm-config file be separately installed? I could not find it anywhere.
FYI: I'm on Windows 10
Thanks for the help!
llvm-config is a developer-side tool, it is not shipped with binaries. You need to build LLVM from sources.
LLVM is not shipped with a component called llvm-config.exe, I am not sure how to bypass though.

According to xargo my code has built successfully, but there's no binary in target, why?

I'm brand new to Rust so forgive me if I don't know the lingo/tools yet. I'm trying to get an STM32F4 to blink an LED, and I think the code is right, but when I build it xargo doesn't generate a binary or any sort of error. My code is:
#![feature(proc_macro)] // <- IMPORTANT! Feature gate for procedural macros
#![no_std]
extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f40x;
use cortex_m::peripheral::SystClkSource;
use rtfm::{app, Threshold};
app! {
device: stm32f40x,
resources: {},
tasks: {
SYS_TICK: {
path: toggle,
resources: [GPIOC],
},
},
}
fn init(p: init::Peripherals, _r: init::Resources) {
// TODO: initialize the GPIO
p.SYST.set_clock_source(SystClkSource::Core);
p.SYST.set_reload(8_000_000); // 1s?
p.SYST.enable_interrupt();
p.SYST.enable_counter();
}
fn idle() -> ! {
loop {
rtfm::wfi();
}
}
fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) {
**r.GPIOC.odr.modify(|r, w| w.odr13().bit(!r.odr13().bit()));
}
The Cargo.toml file is
[package]
name = "sign_firmware"
version = "0.0.1"
authors = ["teryret"]
categories = ["embedded", "no-std"]
description = "With any luck this will cause an STM32F4 based board to drive a few thousand LEDs."
keywords = ["arm", "cortex-m"]
license = "MIT OR Apache-2.0"
repository = "TODO"
[dependencies]
cortex-m = "*"
cortex-m-rt = "*"
cortex-m-rtfm = "*"
stm32f40x = "*"
[profile]
[profile.release]
debug = true
lto = true
[target.arm-none-linux-gnueabihf]
ar = "arm-linux-gnueabihf-gcc-ar"
linker = "arm-linux-gnueabihf-gcc"
And when I run xargo build --release in the docker image I set up to contain all the dependencies and whatnot it says:
teryret#bee ~/d/rtfm> ./build
Compiling core v0.0.0 (file:///usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
Finished release [optimized + debuginfo] target(s) in 12.82 secs
Updating git repository `https://github.com/rust-lang-nursery/compiler-builtins`
Compiling compiler_builtins v0.1.0 (https://github.com/rust-lang-nursery/compiler-builtins#f5532b22)
Finished release [optimized + debuginfo] target(s) in 2.12 secs
warning: unused manifest key: target.arm-none-linux-gnueabihf.ar
warning: unused manifest key: target.arm-none-linux-gnueabihf.linker
Downloading cortex-m-rtfm v0.2.1
Downloading stm32f40x v0.5.0
Downloading cortex-m-rt v0.3.6
Downloading cortex-m v0.3.1
Downloading rtfm-core v0.1.0
Downloading static-ref v0.2.1
Downloading cortex-m-rtfm-macros v0.2.0
Downloading error-chain v0.10.0
Downloading quote v0.3.15
Downloading rtfm-syntax v0.1.0
Downloading syn v0.11.11
Downloading unicode-xid v0.0.4
Downloading synom v0.11.3
Downloading volatile-register v0.2.0
Downloading bare-metal v0.1.1
Downloading aligned v0.1.1
Downloading vcell v0.1.0
Downloading r0 v0.2.2
Compiling r0 v0.2.2
Compiling libc v0.2.33
Compiling vcell v0.1.0
Compiling quote v0.3.15
Compiling cc v1.0.3
Compiling sign_firmware v0.0.1 (file:///usr/src/myapp)
Compiling cortex-m-rt v0.3.6
Compiling cortex-m-rtfm v0.2.1
Compiling cfg-if v0.1.2
Compiling rustc-demangle v0.1.5
Compiling bare-metal v0.1.1
Compiling unicode-xid v0.0.4
Compiling aligned v0.1.1
Compiling cortex-m v0.3.1
Compiling static-ref v0.2.1
Compiling volatile-register v0.2.0
Compiling synom v0.11.3
Compiling rtfm-core v0.1.0
Compiling syn v0.11.11
Compiling stm32f40x v0.5.0
Compiling backtrace-sys v0.1.16
Compiling backtrace v0.3.4
Compiling error-chain v0.10.0
Compiling rtfm-syntax v0.1.0
Compiling cortex-m-rtfm-macros v0.2.0
Finished release [optimized + debuginfo] target(s) in 47.2 secs
While lots of stuff is generated in target/ none of it is a binary I can flash onto the board. Any idea why? I mean, it's got to be something simple, but I don't have the experience to know where to look.
In the tutorial you were following, all of the examples are in an "examples" directory. You can build these using the --example argument, as shown in the tutorial:
xargo build --example hello
If this is your primary program, however, you will want to put your code in "src/main.rs", allowing just:
xargo build
If you have multiple executables, you can also specify that.

Resources