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

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"

Related

Could not compile `lazy_static`

I'm having a hard time cross-compiling an embedded Rust project that worked before for a raspberry pi. I have all the needed deps in Cargo.toml but on doing:
$ cargo build --target thumbv7m-none-eabi
I get the following error.
error[E0463]: can't find crate for `std`
--> /home/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/inline_lazy.rs:9:1
|
9 | extern crate std;
| ^^^^^^^^^^^^^^^^^ can't find crate
|
= note: the `thumbv7m-none-eabi` target may not support the standard library
= help: consider building the standard library from source with `cargo build -Zbuild-std`
For more information about this error, try `rustc --explain E0463`.
error: could not compile `lazy_static` due to previous error
$ rustup show
installed targets for active toolchain
--------------------------------------
thumbv7m-none-eabi
x86_64-unknown-linux-gnu
active toolchain
----------------
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.64.0-nightly (38b72154d 2022-07-11)
Compilation used to work previously without lazy_static as a dependency in cargo.toml,now I don't understand why this is happening.
By default lazy_static depends on the rust standard library, which as the compiler told you
may not be supported on the thumbv7m-none-eabi target
If you do not need the standard library in your project you can enable the no-std feature of lazy_static like this:
lazy_static = { version = "1.5.0", features = ["spin_no_std"] }
as described here.

error: the option `Z` is only accepted on the nightly compiler is not solved

I'm trying to use Address sanitizer in rust with this manual(https://github.com/japaric/rust-san),
but when I build this code with command RUSTFLAGS="-Z sanitier=address" cargo rustc -- --emit=llvm-ir, it cause error like this;
error: failed to run rustc to learn about target-specific information
Caused by:
process didn't exit successfully: rustc - --crate-name ___ --print=file-names -Z sanitier=address --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg (exit status: 1)
--- stderr
error: the option Z is only accepted on the nightly compiler'
I think that "the option Z is only accepted on the nightly compiler" is problem, so I set up to nightly compiler with
rustup install nightly, rustup default nightly, but it cause same error when I build with that command.
How should I do?
Perhaps you should build your code with command:
RUSTFLAGS="-Z sanitier=address" cargo run ${your-binary-name} --target x86_64-unknown-linux-gnu -- --emit=llvm-ir
This works for me to check example in manual:
RUSTFLAGS="-Z sanitizer=address" cargo run --example out-of-bounds --target x86_64-unknown-linux-gnu -- --emit=llvm-ir
**==618620==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffbcbf1250 at pc 0x55adfda84e90 bp 0x7fffbcbf1210 sp 0x7fffbcbf1208
READ of size 4 at 0x7fffbcbf1250 thread T0
#0 0x55adfda84e8f in out_of_bounds::main::hf228b092630ab849 /tmp/rust-san/asan/examples/out-of-bounds.rs:3:22
#1 0x55adfda846fa in core::ops::function::FnOnce::call_once::h84454ea25b7d75ab /rustc/f1f721e64014863f41c1a386b04af04c2de25321/library/core/src/ops/function.rs:248:5
#2 0x55adfda84a94 in std::sys_common::backtrace::__rust_begin_short_backtrace::hbc7697f2c0b7e35d /rustc/f1f721e64014863f41c1a386b04af04c2de25321/library/std/src/sys_common/backtrace.rs:122:18
#3 0x55adfda853a3 in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h01c2d6f3a231ead0 /rustc/f1f721e64014863f41c1a386b04af04c2de25321/library/std/src/rt.rs:145:18
#4 0x55adfda9704d in core::ops::function::impls::_$LT$impl$u20$core..ops..function..FnOnce$LT$A$GT$$u20$for$u20$$RF$F$GT$::call_once::hfce3f72e51a03fc4 /rustc/f1f721e64014863f41c1a386b04af04c2de25321/library/core/src/ops/function.rs:280:13
**
According to the manual, you should always pass --target x86_64-unknown-linux-gnu to Cargo.
Be sure to always pass --target x86_64-unknown-linux-gnu to Cargo or else you'll end up sanitizing the build scripts that Cargo runs or run into compilation error if your crate depends on a dylib.
And you could check your toolchain version with:
> rustup default
nightly-x86_64-unknown-linux-gnu (default)

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

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

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/

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.

Resources