Skip to content

Commit a28d2e9

Browse files
author
imarkov
committed
Add Xtensa targets for the ESP-IDF framework
1 parent 3b9968b commit a28d2e9

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,9 @@ supported_targets! {
886886
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),
887887

888888
("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
889+
("xtensa-esp32-espidf", xtensa_esp32_espidf),
889890
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
891+
("xtensa-esp32s2-espidf", xtensa_esp32s2_espidf),
890892
("xtensa-esp8266-none-elf", xtensa_esp8266_none_elf),
891893
("xtensa-none-elf", xtensa_none_elf),
892894

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use crate::spec::{abi::Abi, LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel};
2+
use crate::abi::Endian;
3+
4+
pub fn target() -> Target {
5+
Target {
6+
llvm_target: "xtensa-none-elf".to_string(),
7+
pointer_width: 32,
8+
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".to_string(),
9+
arch: "xtensa".to_string(),
10+
11+
options: TargetOptions {
12+
endian: Endian::Little,
13+
c_int_width: "32".to_string(),
14+
families: vec!["unix".to_string()],
15+
os: "espidf".to_string(),
16+
env: "newlib".to_string(),
17+
vendor: "espressif".to_string(),
18+
linker_flavor: LinkerFlavor::Gcc,
19+
20+
executables: true,
21+
cpu: "esp32".to_string(),
22+
linker: Some("xtensa-esp32-elf-gcc".to_string()),
23+
24+
max_atomic_width: Some(32),
25+
26+
// Because these devices have very little resources having an
27+
// unwinder is too onerous so we default to "abort" because the
28+
// "unwind" strategy is very rare.
29+
panic_strategy: PanicStrategy::Abort,
30+
31+
// Similarly, one almost always never wants to use relocatable
32+
// code because of the extra costs it involves.
33+
relocation_model: RelocModel::Static,
34+
35+
emit_debug_gdb_scripts: false,
36+
37+
unsupported_abis: vec![
38+
Abi::Stdcall { unwind: false },
39+
Abi::Stdcall { unwind: true },
40+
Abi::Fastcall,
41+
Abi::Vectorcall,
42+
Abi::Thiscall { unwind: false },
43+
Abi::Thiscall { unwind: true },
44+
Abi::Win64,
45+
Abi::SysV64,
46+
],
47+
48+
..Default::default()
49+
},
50+
}
51+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use crate::spec::{abi::Abi, LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel};
2+
use crate::abi::Endian;
3+
4+
pub fn target() -> Target {
5+
Target {
6+
llvm_target: "xtensa-none-elf".to_string(),
7+
pointer_width: 32,
8+
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".to_string(),
9+
arch: "xtensa".to_string(),
10+
11+
options: TargetOptions {
12+
endian: Endian::Little,
13+
c_int_width: "32".to_string(),
14+
families: vec!["unix".to_string()],
15+
os: "espidf".to_string(),
16+
env: "newlib".to_string(),
17+
vendor: "espressif".to_string(),
18+
linker_flavor: LinkerFlavor::Gcc,
19+
20+
executables: true,
21+
cpu: "esp32-s2".to_string(),
22+
linker: Some("xtensa-esp32s2-elf-gcc".to_string()),
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(32)" **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(32),
35+
atomic_cas: true,
36+
37+
// Because these devices have very little resources having an
38+
// unwinder is too onerous so we default to "abort" because the
39+
// "unwind" strategy is very rare.
40+
panic_strategy: PanicStrategy::Abort,
41+
42+
// Similarly, one almost always never wants to use relocatable
43+
// code because of the extra costs it involves.
44+
relocation_model: RelocModel::Static,
45+
46+
emit_debug_gdb_scripts: false,
47+
48+
unsupported_abis: vec![
49+
Abi::Stdcall { unwind: false },
50+
Abi::Stdcall { unwind: true },
51+
Abi::Fastcall,
52+
Abi::Vectorcall,
53+
Abi::Thiscall { unwind: false },
54+
Abi::Thiscall { unwind: true },
55+
Abi::Win64,
56+
Abi::SysV64,
57+
],
58+
59+
..Default::default()
60+
},
61+
}
62+
}

0 commit comments

Comments
 (0)