Skip to content

Commit 75c254c

Browse files
imarkovMabezDev
authored andcommitted
Add Xtensa targets for the ESP-IDF framework
1 parent 5d931e1 commit 75c254c

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

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

10141014
("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
1015+
("xtensa-esp32-espidf", xtensa_esp32_espidf),
10151016
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
1017+
("xtensa-esp32s2-espidf", xtensa_esp32s2_espidf),
10161018
("xtensa-esp8266-none-elf", xtensa_esp8266_none_elf),
10171019
("xtensa-esp32s3-none-elf", xtensa_esp32s3_none_elf),
1020+
("xtensa-esp32s3-espidf", xtensa_esp32s3_espidf),
10181021

10191022
("i686-wrs-vxworks", i686_wrs_vxworks),
10201023
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::spec::{cvs, LinkerFlavor, 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-i8:8:32-i16:16: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+
linker_flavor: LinkerFlavor::Gcc,
19+
20+
executables: true,
21+
cpu: "esp32".into(),
22+
linker: Some("xtensa-esp32-elf-gcc".into()),
23+
24+
// The esp32 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
25+
// so we claim a max atomic width of 64 here.
26+
max_atomic_width: Some(64),
27+
atomic_cas: true,
28+
29+
..super::xtensa_base::opts()
30+
},
31+
}
32+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::spec::{cvs, LinkerFlavor, 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-i8:8:32-i16:16: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+
linker_flavor: LinkerFlavor::Gcc,
19+
20+
executables: true,
21+
cpu: "esp32-s2".into(),
22+
linker: Some("xtensa-esp32s2-elf-gcc".into()),
23+
24+
// See https://github.com/espressif/rust-esp32-example/issues/3#issuecomment-861054477
25+
//
26+
// Unlike the original ESP32 chip, ESP32-S2 does not really support atomics.
27+
// If the missing hardware instruction ends up being emulated in ESP-IDF, we might want to revert
28+
// this change and claim that atomics are supported "in hardware" (even though they would be emulated
29+
// by actually trapping the illegal instruction exception handler and calling into an ESP-IDF C emulation code).
30+
//
31+
// However, for now we simultaneously claim "max_atomic_width: Some(64)" **and** atomic_cas: true,
32+
// which should force the compiler to generate libcalls to functions that emulate atomics
33+
// and which are already implemented in the ESP-IDF main branch anyway.
34+
max_atomic_width: Some(64),
35+
atomic_cas: true,
36+
37+
..super::xtensa_base::opts()
38+
},
39+
}
40+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::spec::{cvs, LinkerFlavor, 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-i8:8:32-i16:16: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+
linker_flavor: LinkerFlavor::Gcc,
19+
20+
executables: true,
21+
cpu: "esp32-s3".into(),
22+
linker: Some("xtensa-esp32s3-elf-gcc".into()),
23+
24+
// The esp32s3 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
25+
// so we claim a max atomic width of 64 here.
26+
max_atomic_width: Some(64),
27+
atomic_cas: true,
28+
29+
..super::xtensa_base::opts()
30+
},
31+
}
32+
}

0 commit comments

Comments
 (0)