Skip to content

Commit 3954b74

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

File tree

8 files changed

+144
-1
lines changed

8 files changed

+144
-1
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+
}

src/doc/rustc/src/platform-support.md

+3
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,10 @@ target | std | host | notes
384384
[`x86_64h-apple-darwin`](platform-support/x86_64h-apple-darwin.md) | ✓ | ✓ | macOS with late-gen Intel (at least Haswell)
385385
[`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc
386386
`xtensa-esp32-none-elf` | | | Xtensa ESP32
387+
`xtensa-esp32-espidf` | | | Xtensa ESP32
387388
`xtensa-esp32s2-none-elf` | | | Xtensa ESP32-S2
389+
`xtensa-esp32s2-espidf` | | | Xtensa ESP32-S2
388390
`xtensa-esp32s3-none-elf` | | | Xtensa ESP32-S3
391+
`xtensa-esp32s3-espidf` | | | Xtensa ESP32-S3
389392

390393
[runs on NVIDIA GPUs]: https://github.com/japaric-archived/nvptx#targets

src/doc/rustc/src/platform-support/xtensa.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@ Targets for Xtensa CPUs.
1313

1414
The target names follow this format: `xtensa-$CPU`, where `$CPU` specifies the target chip. The following targets are currently defined:
1515

16+
17+
### `no_std`
18+
1619
| Target name | Target CPU(s) |
1720
| ------------------------- | --------------------------------------------------------------- |
1821
| `xtensa-esp32-none-elf` | [ESP32](https://www.espressif.com/en/products/socs/esp32) |
1922
| `xtensa-esp32s2-none-elf` | [ESP32-S2](https://www.espressif.com/en/products/socs/esp32-s2) |
2023
| `xtensa-esp32s3-none-elf` | [ESP32-S3](https://www.espressif.com/en/products/socs/esp32-s3) |
2124

25+
### `std`
26+
27+
| Target name | Target CPU(s) |
28+
| ----------------------- | --------------------------------------------------------------- |
29+
| `xtensa-esp32-espidf` | [ESP32](https://www.espressif.com/en/products/socs/esp32) |
30+
| `xtensa-esp32s2-espidf` | [ESP32-S2](https://www.espressif.com/en/products/socs/esp32-s2) |
31+
| `xtensa-esp32s3-espidf` | [ESP32-S3](https://www.espressif.com/en/products/socs/esp32-s3) |
2232

23-
## Building the target
33+
## Building the targets
2434

2535
The targets can be built by installing the [Xtensa enabled Rust channel](https://github.com/esp-rs/rust/). See instructions in the [RISC-V and Xtensa Targets section of the The Rust on ESP Book](https://docs.esp-rs.org/book/installation/riscv-and-xtensa.html).

src/tools/tidy/src/target_policy.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ const EXCEPTIONS: &[&str] = &[
1414
"csky_unknown_linux_gnuabiv2hf",
1515
// FIXME: disabled since it requires a custom LLVM until the upstream LLVM adds support for the target (https://github.com/espressif/llvm-project/issues/4)
1616
"xtensa_esp32_none_elf",
17+
"xtensa_esp32_espidf",
1718
"xtensa_esp32s2_none_elf",
19+
"xtensa_esp32s2_espidf",
1820
"xtensa_esp32s3_none_elf",
21+
"xtensa_esp32s3_espidf",
1922
];
2023

2124
pub fn check(root_path: &Path, bad: &mut bool) {

tests/assembly/targets/targets-elf.rs

+9
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,21 @@
578578
revisions: xtensa_esp32_none_elf
579579
[xtensa_esp32_none_elf] compile-flags: --target xtensa-esp32-none-elf
580580
[xtensa_esp32_none_elf] needs-llvm-components: xtensa
581+
revisions: xtensa_esp32_espidf
582+
[xtensa_esp32_espidf] compile-flags: --target xtensa-esp32s2-espidf
583+
[xtensa_esp32_espidf] needs-llvm-components: xtensa
581584
revisions: xtensa_esp32s2_none_elf
582585
[xtensa_esp32s2_none_elf] compile-flags: --target xtensa-esp32s2-none-elf
583586
[xtensa_esp32s2_none_elf] needs-llvm-components: xtensa
587+
revisions: xtensa_esp32s2_espidf
588+
[xtensa_esp32s2_espidf] compile-flags: --target xtensa-esp32s2-espidf
589+
[xtensa_esp32s2_espidf] needs-llvm-components: xtensa
584590
revisions: xtensa_esp32s3_none_elf
585591
[xtensa_esp32s3_none_elf] compile-flags: --target xtensa-esp32s3-none-elf
586592
[xtensa_esp32s3_none_elf] needs-llvm-components: xtensa
593+
revisions: xtensa_esp32s3_espidf
594+
[xtensa_esp32s3_espidf] compile-flags: --target xtensa-esp32s3-espidf
595+
[xtensa_esp32s3_espidf] needs-llvm-components: xtensa
587596
*/
588597
// Sanity-check that each target can produce assembly code.
589598

0 commit comments

Comments
 (0)