Skip to content

Commit bcb2757

Browse files
author
imarkov
committed
Add Riscv32 targets for the ESP-IDF framework
1 parent a28d2e9 commit bcb2757

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,9 @@ supported_targets! {
867867

868868
("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
869869
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
870+
("riscv32imc-esp-espidf", riscv32imc_esp_espidf),
870871
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
872+
("riscv32imac-esp-espidf", riscv32imac_esp_espidf),
871873
("riscv32gc-unknown-linux-gnu", riscv32gc_unknown_linux_gnu),
872874
("riscv32gc-unknown-linux-musl", riscv32gc_unknown_linux_musl),
873875
("riscv64imac-unknown-none-elf", riscv64imac_unknown_none_elf),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crate::spec::{LinkerFlavor, PanicStrategy, RelocModel};
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
Target {
6+
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(),
7+
llvm_target: "riscv32".to_string(),
8+
pointer_width: 32,
9+
arch: "riscv32".to_string(),
10+
11+
options: TargetOptions {
12+
families: vec!["unix".to_string()],
13+
os: "espidf".to_string(),
14+
env: "newlib".to_string(),
15+
vendor: "espressif".to_string(),
16+
linker_flavor: LinkerFlavor::Gcc,
17+
linker: Some("riscv32-esp-elf-gcc".to_string()),
18+
cpu: "generic-rv32".to_string(),
19+
max_atomic_width: Some(32),
20+
features: "+m,+a,+c".to_string(),
21+
executables: true,
22+
panic_strategy: PanicStrategy::Abort,
23+
relocation_model: RelocModel::Static,
24+
emit_debug_gdb_scripts: false,
25+
eh_frame_header: false,
26+
..Default::default()
27+
},
28+
}
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::spec::{LinkerFlavor, PanicStrategy, RelocModel};
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
Target {
6+
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(),
7+
llvm_target: "riscv32".to_string(),
8+
pointer_width: 32,
9+
arch: "riscv32".to_string(),
10+
11+
options: TargetOptions {
12+
families: vec!["unix".to_string()],
13+
os: "espidf".to_string(),
14+
env: "newlib".to_string(),
15+
vendor: "espressif".to_string(),
16+
linker_flavor: LinkerFlavor::Gcc,
17+
linker: Some("riscv32-esp-elf-gcc".to_string()),
18+
cpu: "generic-rv32".to_string(),
19+
20+
// See https://github.com/espressif/rust-esp32-example/issues/3#issuecomment-861054477
21+
//
22+
// The RISCV32IMC architecture does not support atomics.
23+
// However, simultaneously claiming "max_atomic_width: Some(32)" **and** "atomic_cas: true",
24+
// forces the compiler to generate libcalls to functions that emulate atomics
25+
// and which are already implemented in the ESP-IDF main branch anyway.
26+
//
27+
// The plan forward is as follows:
28+
// - If the missing hardware instruction(s) end up being emulated in ESP-IDF, we will remove
29+
// this target altogether and use the riscv32imac-esp-espidf target with ESP-IDF
30+
// - Otherwise, we'll use this target and remove the riscv32imac-esp-espidf one
31+
max_atomic_width: Some(32),
32+
atomic_cas: true,
33+
34+
features: "+m,+c".to_string(),
35+
executables: true,
36+
panic_strategy: PanicStrategy::Abort,
37+
relocation_model: RelocModel::Static,
38+
emit_debug_gdb_scripts: false,
39+
eh_frame_header: false,
40+
..Default::default()
41+
},
42+
}
43+
}

0 commit comments

Comments
 (0)