Skip to content

Commit b93c5ea

Browse files
committed
feat: Add std Xtensa targets support
1 parent f6b4b71 commit b93c5ea

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,11 @@ supported_targets! {
17671767
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),
17681768

17691769
("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
1770+
("xtensa-esp32-espidf", xtensa_esp32_espidf),
17701771
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
1772+
("xtensa-esp32s2-espidf", xtensa_esp32s2_espidf),
17711773
("xtensa-esp32s3-none-elf", xtensa_esp32s3_none_elf),
1774+
("xtensa-esp32s3-espidf", xtensa_esp32s3_espidf),
17721775

17731776
("i686-wrs-vxworks", i686_wrs_vxworks),
17741777
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{base::xtensa, cvs, Target, TargetOptions};
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-v1:8:8-i64:64-i128:128-n32".into(),
9+
arch: "xtensa".into(),
10+
metadata: crate::spec::TargetMetadata {
11+
description: None,
12+
tier: None,
13+
host_tools: None,
14+
std: None,
15+
},
16+
17+
options: TargetOptions {
18+
endian: Endian::Little,
19+
c_int_width: "32".into(),
20+
families: cvs!["unix"],
21+
os: "espidf".into(),
22+
env: "newlib".into(),
23+
vendor: "espressif".into(),
24+
25+
executables: true,
26+
cpu: "esp32".into(),
27+
linker: Some("xtensa-esp32-elf-gcc".into()),
28+
29+
// The esp32 only supports native 32bit atomics.
30+
max_atomic_width: Some(32),
31+
atomic_cas: true,
32+
33+
..xtensa::opts()
34+
},
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{base::xtensa, cvs, Target, TargetOptions};
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-v1:8:8-i64:64-i128:128-n32".into(),
9+
arch: "xtensa".into(),
10+
metadata: crate::spec::TargetMetadata {
11+
description: None,
12+
tier: None,
13+
host_tools: None,
14+
std: None,
15+
},
16+
17+
options: TargetOptions {
18+
endian: Endian::Little,
19+
c_int_width: "32".into(),
20+
families: cvs!["unix"],
21+
os: "espidf".into(),
22+
env: "newlib".into(),
23+
vendor: "espressif".into(),
24+
25+
executables: true,
26+
cpu: "esp32-s2".into(),
27+
linker: Some("xtensa-esp32s2-elf-gcc".into()),
28+
29+
// See https://github.com/espressif/rust-esp32-example/issues/3#issuecomment-861054477
30+
//
31+
// While the ESP32-S2 chip does not natively support atomics, ESP-IDF does support
32+
// the __atomic* and __sync* compiler builtins. Setting `max_atomic_width` and `atomic_cas`
33+
// and `atomic_cas: true` will cause the compiler to emit libcalls to these builtins. On the
34+
// ESP32-S2, these are guaranteed to be lock-free.
35+
//
36+
// Support for atomics is necessary for the Rust STD library, which is supported by ESP-IDF.
37+
max_atomic_width: Some(32),
38+
atomic_cas: true,
39+
40+
..xtensa::opts()
41+
},
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{base::xtensa, cvs, Target, TargetOptions};
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-v1:8:8-i64:64-i128:128-n32".into(),
9+
arch: "xtensa".into(),
10+
metadata: crate::spec::TargetMetadata {
11+
description: None,
12+
tier: None,
13+
host_tools: None,
14+
std: None,
15+
},
16+
17+
options: TargetOptions {
18+
endian: Endian::Little,
19+
c_int_width: "32".into(),
20+
families: cvs!["unix"],
21+
os: "espidf".into(),
22+
env: "newlib".into(),
23+
vendor: "espressif".into(),
24+
25+
executables: true,
26+
cpu: "esp32-s3".into(),
27+
linker: Some("xtensa-esp32s3-elf-gcc".into()),
28+
29+
// The esp32s3 only supports native 32bit atomics.
30+
max_atomic_width: Some(32),
31+
atomic_cas: true,
32+
33+
..xtensa::opts()
34+
},
35+
}
36+
}

0 commit comments

Comments
 (0)