Skip to content

Commit

Permalink
Add Xtensa targets for the ESP-IDF framework
Browse files Browse the repository at this point in the history
  • Loading branch information
imarkov authored and MabezDev committed May 16, 2023
1 parent 5c64241 commit f20b838
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,12 @@ supported_targets! {
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),

("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
("xtensa-esp32-espidf", xtensa_esp32_espidf),
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
("xtensa-esp32s2-espidf", xtensa_esp32s2_espidf),
("xtensa-esp8266-none-elf", xtensa_esp8266_none_elf),
("xtensa-esp32s3-none-elf", xtensa_esp32s3_none_elf),
("xtensa-esp32s3-espidf", xtensa_esp32s3_espidf),

("i686-wrs-vxworks", i686_wrs_vxworks),
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
Expand Down
31 changes: 31 additions & 0 deletions compiler/rustc_target/src/spec/xtensa_esp32_espidf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::spec::{cvs, Target, TargetOptions};
use crate::abi::Endian;

pub fn target() -> Target {
Target {
llvm_target: "xtensa-none-elf".into(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-i64:64-i128:128-n32".into(),
arch: "xtensa".into(),

options: TargetOptions {
endian: Endian::Little,
c_int_width: "32".into(),
families: cvs!["unix"],
os: "espidf".into(),
env: "newlib".into(),
vendor: "espressif".into(),

executables: true,
cpu: "esp32".into(),
linker: Some("xtensa-esp32-elf-gcc".into()),

// The esp32 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
// so we claim a max atomic width of 64 here.
max_atomic_width: Some(64),
atomic_cas: true,

..super::xtensa_base::opts()
},
}
}
39 changes: 39 additions & 0 deletions compiler/rustc_target/src/spec/xtensa_esp32s2_espidf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::spec::{cvs, Target, TargetOptions};
use crate::abi::Endian;

pub fn target() -> Target {
Target {
llvm_target: "xtensa-none-elf".into(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-i64:64-i128:128-n32".into(),
arch: "xtensa".into(),

options: TargetOptions {
endian: Endian::Little,
c_int_width: "32".into(),
families: cvs!["unix"],
os: "espidf".into(),
env: "newlib".into(),
vendor: "espressif".into(),

executables: true,
cpu: "esp32-s2".into(),
linker: Some("xtensa-esp32s2-elf-gcc".into()),

// See https://github.com/espressif/rust-esp32-example/issues/3#issuecomment-861054477
//
// Unlike the original ESP32 chip, ESP32-S2 does not really support atomics.
// If the missing hardware instruction ends up being emulated in ESP-IDF, we might want to revert
// this change and claim that atomics are supported "in hardware" (even though they would be emulated
// by actually trapping the illegal instruction exception handler and calling into an ESP-IDF C emulation code).
//
// However, for now we simultaneously claim "max_atomic_width: Some(64)" **and** atomic_cas: true,
// which should force the compiler to generate libcalls to functions that emulate atomics
// and which are already implemented in the ESP-IDF main branch anyway.
max_atomic_width: Some(64),
atomic_cas: true,

..super::xtensa_base::opts()
},
}
}
31 changes: 31 additions & 0 deletions compiler/rustc_target/src/spec/xtensa_esp32s3_espidf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::spec::{cvs, Target, TargetOptions};
use crate::abi::Endian;

pub fn target() -> Target {
Target {
llvm_target: "xtensa-none-elf".into(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-i64:64-i128:128-n32".into(),
arch: "xtensa".into(),

options: TargetOptions {
endian: Endian::Little,
c_int_width: "32".into(),
families: cvs!["unix"],
os: "espidf".into(),
env: "newlib".into(),
vendor: "espressif".into(),

executables: true,
cpu: "esp32-s3".into(),
linker: Some("xtensa-esp32s3-elf-gcc".into()),

// The esp32s3 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
// so we claim a max atomic width of 64 here.
max_atomic_width: Some(64),
atomic_cas: true,

..super::xtensa_base::opts()
},
}
}

0 comments on commit f20b838

Please sign in to comment.