Rust ESP32-S3 构建问题:无法编译 xtensa-lx-rt (lib)

在为 ESP32-S3 编译 Rust 项目时,您可能会遇到以下错误:

cargo build --release
Compiling xtensa-lx-rt v0.16.0
Compiling esp-hal-common v0.14.1
LLVM ERROR: Global variable 'save_context' has an invalid section specifier '.rwtext': mach-o section specifier requires a segment and section separated by a comma.
error: could not compile xtensa-lx-rt (lib)
warning: build failed, waiting for other jobs to finish...
error: invalid instruction mnemonic 'rsr.ccount'
--> /Users/georgik/.cargo/registry/src/index.crates.io-6f17d22bba15001f/xtensa-lx-0.8.0/src/timer.rs:81:20
|
81 | unsafe { asm!("rsr.ccount {0}", out(reg) x, options(nostack)) };

尽管 Rust 对错误消息非常有帮助,但很难确定出了什么问题。

基本上,当您为 ESP32-S3 构建使用 Xtensa 目标的项目时,如果项目缺少以下文件,则会出现此问题:.cargo/config.toml

[target.'cfg(target_arch = "xtensa")']
runner = "espflash flash --monitor"
rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-nostartfiles",
]

[build]
target = "xtensa-esp32s3-none-elf"

[unstable]
build-std = [ "core", "alloc" ]