Skip to content

Commit 6ebd8c7

Browse files
imarkovMabezDev
imarkov
authored andcommitted
Add Xtensa targets for the ESP-IDF framework
1 parent a12584a commit 6ebd8c7

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,9 +1222,12 @@ supported_targets! {
12221222
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),
12231223

12241224
("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
1225+
("xtensa-esp32-espidf", xtensa_esp32_espidf),
12251226
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
1227+
("xtensa-esp32s2-espidf", xtensa_esp32s2_espidf),
12261228
("xtensa-esp8266-none-elf", xtensa_esp8266_none_elf),
12271229
("xtensa-esp32s3-none-elf", xtensa_esp32s3_none_elf),
1230+
("xtensa-esp32s3-espidf", xtensa_esp32s3_espidf),
12281231

12291232
("i686-wrs-vxworks", i686_wrs_vxworks),
12301233
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::spec::{cvs, Target, TargetOptions};
2+
use crate::abi::Endian;
3+
4+
pub fn target() -> Target {
5+
Target {
6+
llvm_target: "xtensa-none-elf".into(),
7+
pointer_width: 32,
8+
data_layout: "e-m:e-p:32:32-i64:64-i128:128-n32".into(),
9+
arch: "xtensa".into(),
10+
11+
options: TargetOptions {
12+
endian: Endian::Little,
13+
c_int_width: "32".into(),
14+
families: cvs!["unix"],
15+
os: "espidf".into(),
16+
env: "newlib".into(),
17+
vendor: "espressif".into(),
18+
19+
executables: true,
20+
cpu: "esp32".into(),
21+
linker: Some("xtensa-esp32-elf-gcc".into()),
22+
23+
// The esp32 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
24+
// so we claim a max atomic width of 64 here.
25+
max_atomic_width: Some(64),
26+
atomic_cas: true,
27+
28+
..super::xtensa_base::opts()
29+
},
30+
}
31+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use crate::spec::{cvs, Target, TargetOptions};
2+
use crate::abi::Endian;
3+
4+
pub fn target() -> Target {
5+
Target {
6+
llvm_target: "xtensa-none-elf".into(),
7+
pointer_width: 32,
8+
data_layout: "e-m:e-p:32:32-i64:64-i128:128-n32".into(),
9+
arch: "xtensa".into(),
10+
11+
options: TargetOptions {
12+
endian: Endian::Little,
13+
c_int_width: "32".into(),
14+
families: cvs!["unix"],
15+
os: "espidf".into(),
16+
env: "newlib".into(),
17+
vendor: "espressif".into(),
18+
19+
executables: true,
20+
cpu: "esp32-s2".into(),
21+
linker: Some("xtensa-esp32s2-elf-gcc".into()),
22+
23+
// See https://github.com/espressif/rust-esp32-example/issues/3#issuecomment-861054477
24+
//
25+
// Unlike the original ESP32 chip, ESP32-S2 does not really support atomics.
26+
// If the missing hardware instruction ends up being emulated in ESP-IDF, we might want to revert
27+
// this change and claim that atomics are supported "in hardware" (even though they would be emulated
28+
// by actually trapping the illegal instruction exception handler and calling into an ESP-IDF C emulation code).
29+
//
30+
// However, for now we simultaneously claim "max_atomic_width: Some(64)" **and** atomic_cas: true,
31+
// which should force the compiler to generate libcalls to functions that emulate atomics
32+
// and which are already implemented in the ESP-IDF main branch anyway.
33+
max_atomic_width: Some(64),
34+
atomic_cas: true,
35+
36+
..super::xtensa_base::opts()
37+
},
38+
}
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::spec::{cvs, Target, TargetOptions};
2+
use crate::abi::Endian;
3+
4+
pub fn target() -> Target {
5+
Target {
6+
llvm_target: "xtensa-none-elf".into(),
7+
pointer_width: 32,
8+
data_layout: "e-m:e-p:32:32-i64:64-i128:128-n32".into(),
9+
arch: "xtensa".into(),
10+
11+
options: TargetOptions {
12+
endian: Endian::Little,
13+
c_int_width: "32".into(),
14+
families: cvs!["unix"],
15+
os: "espidf".into(),
16+
env: "newlib".into(),
17+
vendor: "espressif".into(),
18+
19+
executables: true,
20+
cpu: "esp32-s3".into(),
21+
linker: Some("xtensa-esp32s3-elf-gcc".into()),
22+
23+
// The esp32s3 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
24+
// so we claim a max atomic width of 64 here.
25+
max_atomic_width: Some(64),
26+
atomic_cas: true,
27+
28+
..super::xtensa_base::opts()
29+
},
30+
}
31+
}

0 commit comments

Comments
 (0)