I'm trying to compile a program that uses std
for a Cortex-M3. I downloaded the cortex-m-quickstart template and made a few minor changes:
- Switch the
target
in.cargo/config
totarget = "thumbv7m-unknown-eabi.json"
- Comment out all of the dependencies in
Cargo.toml
(some of the cortex crates don't like theunknown
in the target triple). - Strip down the code to literally just this (I think this will need to be changed later but I wanted to simplify things):
fn main() -> ! {
loop {}
}
- Add a
thumv7m-unknown-eabi-json
target like this:
{
"os": "unknown",
"arch": "arm",
"data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
"eliminate-frame-pointer": false,
"emit-debug-gdb-scripts": false,
"executables": true,
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"llvm-target": "thumbv7m-unknown-eabi",
"max-atomic-width": 32,
"panic-strategy": "abort",
"relocation-model": "static",
"target-pointer-width": "32",
"unsupported-abis": [
"stdcall",
"fastcall",
"vectorcall",
"thiscall",
"win64",
"sysv64"
]
}
- Finally built it like this:
cargo +nightly build -Z build-std --verbose
Unfortunately I get this mysterious error:
Compiling cortex-m-quickstart v0.1.0 (/Users/tim/cortex-m-quickstart)
Running `rustc --crate-name cortex_m_quickstart --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=b6fe60e222dc389a -C extra-filename=-b6fe60e222dc389a --out-dir /Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps --target /Users/tim/cortex-m-quickstart/thumbv7m-unknown-eabi.json -C incremental=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/incremental -L dependency=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps -L dependency=/Users/tim/cortex-m-quickstart/target/debug/deps --extern 'noprelude:alloc=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/liballoc-8c9ec352989a5f35.rlib' --extern 'noprelude:compiler_builtins=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/libcompiler_builtins-0851db5ec8bb1a25.rlib' --extern 'noprelude:core=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/libcore-f11f9c4b8f6340f7.rlib' --extern 'noprelude:panic_unwind=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/libpanic_unwind-e981032e31382246.rlib' --extern 'noprelude:proc_macro=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/libproc_macro-be91720a901aa031.rlib' --extern 'noprelude:std=/Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/libstd-22fb39c90a0b0c7b.rlib' -Z unstable-options -L /Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/build/cortex-m-quickstart-1a85fd60572a4cc2/out`
error[E0463]: can't find crate for `panic_abort`
error: aborting due to previous error
Ok weird, maybe I need to add panic-abort = "0.3.2"
to my dependencies? But then I get these errors:
error: the crate `panic_abort` is not a panic runtime
error: duplicate lang item in crate `panic_abort`: `panic_impl`.
|
= note: the lang item is first defined in crate `std` (which `cortex_m_quickstart` depends on)
= note: first definition in `std` loaded from /Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/libstd-22fb39c90a0b0c7b.rlib
= note: second definition in `panic_abort` loaded from /Users/tim/cortex-m-quickstart/target/thumbv7m-unknown-eabi/debug/deps/libpanic_abort-501bea4b917c9dfc.rlib
error[E0658]: use of unstable library feature 'restricted_std'
|
= help: add `#![feature(restricted_std)]` to the crate attributes to enable
error: aborting due to 3 previous errors
Does anyone know what is going on here? It seems to me like std
provides its own panic handler, but then I can't figure out why something is trying to find the panic_abort
crate. It doesn't help that it doesn't tell me what is trying to find panic_abort
. :-/
There's a similar thread here but it seems like they solved it by adding panic-abort
as a dependency.