Skip to content

Commit 21e924e

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

File tree

12 files changed

+141
-2
lines changed

12 files changed

+141
-2
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).

src/tools/build-manifest/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ static TARGETS: &[&str] = &[
174174
"x86_64-unknown-redox",
175175
"x86_64-unknown-hermit",
176176
"x86_64-unknown-uefi",
177+
"xtensa-esp32-none-elf",
178+
"xtensa-esp32s2-none-elf",
179+
"xtensa-esp32s3-none-elf",
177180
];
178181

179182
/// This allows the manifest to contain rust-docs for hosts that don't build

src/tools/tidy/src/target_policy.rs

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const EXCEPTIONS: &[&str] = &[
1212
// FIXME: disabled since it fails on CI saying the csky component is missing
1313
"csky_unknown_linux_gnuabiv2",
1414
"csky_unknown_linux_gnuabiv2hf",
15+
// 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)
16+
"xtensa_esp32_none_elf",
17+
"xtensa_esp32s2_none_elf",
18+
"xtensa_esp32s3_none_elf",
1519
];
1620

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

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)]

tests/ui/check-cfg/well-known-values.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
129129
LL | target_arch = "_UNEXPECTED_VALUE",
130130
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131131
|
132-
= note: expected values for `target_arch` are: `aarch64`, `arm`, `arm64ec`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
132+
= note: expected values for `target_arch` are: `aarch64`, `arm`, `arm64ec`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`, `xtensa`
133133
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
134134

135135
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`

0 commit comments

Comments
 (0)