Skip to content

Commit 16eda93

Browse files
imarkovMabezDev
imarkov
authored andcommitted
Add Xtensa targets for the ESP-IDF framework
1 parent f2b87ec commit 16eda93

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

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

16681668
("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
1669+
("xtensa-esp32-espidf", xtensa_esp32_espidf),
16691670
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
1671+
("xtensa-esp32s2-espidf", xtensa_esp32s2_espidf),
16701672
("xtensa-esp8266-none-elf", xtensa_esp8266_none_elf),
16711673
("xtensa-esp32s3-none-elf", xtensa_esp32s3_none_elf),
1674+
("xtensa-esp32s3-espidf", xtensa_esp32s3_espidf),
16721675

16731676
("i686-wrs-vxworks", i686_wrs_vxworks),
16741677
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::spec::{cvs, Target, TargetOptions, base::xtensa};
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.
24+
max_atomic_width: Some(32),
25+
atomic_cas: true,
26+
27+
..xtensa::opts()
28+
},
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use crate::spec::{cvs, Target, TargetOptions, base::xtensa};
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+
// While the ESP32-S2 chip does not natively support atomics, ESP-IDF does support
26+
// the __atomic* and __sync* compiler builtins. Setting `max_atomic_width` and `atomic_cas`
27+
// and `atomic_cas: true` will cause the compiler to emit libcalls to these builtins. On the
28+
// ESP32-S2, these are guaranteed to be lock-free.
29+
//
30+
// Support for atomics is necessary for the Rust STD library, which is supported by ESP-IDF.
31+
max_atomic_width: Some(32),
32+
atomic_cas: true,
33+
34+
..xtensa::opts()
35+
},
36+
}
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::spec::{cvs, Target, TargetOptions, base::xtensa};
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.
24+
max_atomic_width: Some(32),
25+
atomic_cas: true,
26+
27+
..xtensa::opts()
28+
},
29+
}
30+
}

0 commit comments

Comments
 (0)