Skip to content

Commit e06858f

Browse files
committed
feat: Add no_std Xtensa targets support
1 parent 31026b7 commit e06858f

File tree

9 files changed

+133
-1
lines changed

9 files changed

+133
-1
lines changed

compiler/rustc_target/src/spec/base/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ pub(crate) mod windows_gnullvm;
3535
pub(crate) mod windows_msvc;
3636
pub(crate) mod windows_uwp_gnu;
3737
pub(crate) mod windows_uwp_msvc;
38+
pub(crate) mod xtensa;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, TargetOptions};
3+
4+
pub fn opts() -> TargetOptions {
5+
TargetOptions {
6+
os: "none".into(),
7+
endian: Endian::Little,
8+
c_int_width: "32".into(),
9+
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
10+
executables: true,
11+
panic_strategy: PanicStrategy::Abort,
12+
relocation_model: RelocModel::Static,
13+
emit_debug_gdb_scripts: false,
14+
atomic_cas: false,
15+
..Default::default()
16+
}
17+
}

compiler/rustc_target/src/spec/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,10 @@ supported_targets! {
17251725

17261726
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),
17271727

1728+
("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
1729+
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
1730+
("xtensa-esp32s3-none-elf", xtensa_esp32s3_none_elf),
1731+
17281732
("i686-wrs-vxworks", i686_wrs_vxworks),
17291733
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
17301734
("armv7-wrs-vxworks-eabihf", armv7_wrs_vxworks_eabihf),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::spec::{base::xtensa, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "xtensa-none-elf".into(),
6+
pointer_width: 32,
7+
data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
8+
arch: "xtensa".into(),
9+
metadata: crate::spec::TargetMetadata {
10+
description: None,
11+
tier: None,
12+
host_tools: None,
13+
std: None,
14+
},
15+
16+
options: TargetOptions {
17+
cpu: "esp32".into(),
18+
linker: Some("xtensa-esp32-elf-gcc".into()),
19+
max_atomic_width: Some(32),
20+
atomic_cas: true,
21+
..xtensa::opts()
22+
},
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::spec::{base::xtensa, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "xtensa-none-elf".into(),
6+
pointer_width: 32,
7+
data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
8+
arch: "xtensa".into(),
9+
metadata: crate::spec::TargetMetadata {
10+
description: None,
11+
tier: None,
12+
host_tools: None,
13+
std: None,
14+
},
15+
16+
options: TargetOptions {
17+
cpu: "esp32-s2".into(),
18+
linker: Some("xtensa-esp32s2-elf-gcc".into()),
19+
max_atomic_width: Some(32),
20+
..xtensa::opts()
21+
},
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::spec::{base::xtensa, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "xtensa-none-elf".into(),
6+
pointer_width: 32,
7+
data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
8+
arch: "xtensa".into(),
9+
metadata: crate::spec::TargetMetadata {
10+
description: None,
11+
tier: None,
12+
host_tools: None,
13+
std: None,
14+
},
15+
16+
options: TargetOptions {
17+
cpu: "esp32-s3".into(),
18+
linker: Some("xtensa-esp32s3-elf-gcc".into()),
19+
max_atomic_width: Some(32),
20+
atomic_cas: true,
21+
..xtensa::opts()
22+
},
23+
}
24+
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -383,5 +383,8 @@ target | std | host | notes
383383
`x86_64-wrs-vxworks` | ? | |
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
386+
`xtensa-esp32-none-elf` | | | Xtensa ESP32
387+
`xtensa-esp32s2-none-elf` | | | Xtensa ESP32-S2
388+
`xtensa-esp32s3-none-elf` | | | Xtensa ESP32-S3
386389

387390
[runs on NVIDIA GPUs]: https://github.com/japaric-archived/nvptx#targets
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `xtensa-*`
2+
3+
**Tier: 3**
4+
5+
Targets for Xtensa CPUs.
6+
7+
## Target maintainers
8+
9+
- Scott Mabin [@MabezDev](https://github.com/MabezDev)
10+
- Sergio Gasquez [@SergioGasquez](https://github.com/SergioGasquez)
11+
12+
## Requirements
13+
14+
The target names follow this format: `xtensa-$CPU`, where `$CPU` specifies the target chip. The following targets are currently defined:
15+
16+
| Target name | Target CPU(s) |
17+
| ------------------------- | --------------------------------------------------------------- |
18+
| `xtensa-esp32-none-elf` | [ESP32](https://www.espressif.com/en/products/socs/esp32) |
19+
| `xtensa-esp32s2-none-elf` | [ESP32-S2](https://www.espressif.com/en/products/socs/esp32-s2) |
20+
| `xtensa-esp32s3-none-elf` | [ESP32-S3](https://www.espressif.com/en/products/socs/esp32-s3) |
21+
22+
23+
## Building the target
24+
25+
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).

tests/assembly/targets/targets-elf.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,18 @@
573573
//@ revisions: x86_64_wrs_vxworks
574574
//@ [x86_64_wrs_vxworks] compile-flags: --target x86_64-wrs-vxworks
575575
//@ [x86_64_wrs_vxworks] needs-llvm-components: x86
576-
576+
// 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)
577+
/*
578+
revisions: xtensa_esp32_none_elf
579+
[xtensa_esp32_none_elf] compile-flags: --target xtensa-esp32-none-elf
580+
[xtensa_esp32_none_elf] needs-llvm-components: xtensa
581+
revisions: xtensa_esp32s2_none_elf
582+
[xtensa_esp32s2_none_elf] compile-flags: --target xtensa-esp32s2-none-elf
583+
[xtensa_esp32s2_none_elf] needs-llvm-components: xtensa
584+
revisions: xtensa_esp32s3_none_elf
585+
[xtensa_esp32s3_none_elf] compile-flags: --target xtensa-esp32s3-none-elf
586+
[xtensa_esp32s3_none_elf] needs-llvm-components: xtensa
587+
*/
577588
// Sanity-check that each target can produce assembly code.
578589

579590
#![feature(no_core, lang_items)]

0 commit comments

Comments
 (0)