forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#108792 - Amanieu:ohos, r=petrochenkov
Add OpenHarmony targets - `aarch64-unknown-linux-ohos` - `armv7-unknown-linux-ohos` Compiler team MCP: rust-lang/compiler-team#568
- Loading branch information
Showing
15 changed files
with
238 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::spec::{Target, TargetOptions}; | ||
|
||
use super::SanitizerSet; | ||
|
||
pub fn target() -> Target { | ||
let mut base = super::linux_musl_base::opts(); | ||
base.env = "ohos".into(); | ||
base.crt_static_default = false; | ||
base.max_atomic_width = Some(128); | ||
|
||
Target { | ||
// LLVM 15 doesn't support OpenHarmony yet, use a linux target instead. | ||
llvm_target: "aarch64-unknown-linux-musl".into(), | ||
pointer_width: 64, | ||
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), | ||
arch: "aarch64".into(), | ||
options: TargetOptions { | ||
features: "+reserve-x18".into(), | ||
mcount: "\u{1}_mcount".into(), | ||
force_emulated_tls: true, | ||
supported_sanitizers: SanitizerSet::ADDRESS | ||
| SanitizerSet::CFI | ||
| SanitizerSet::LEAK | ||
| SanitizerSet::MEMORY | ||
| SanitizerSet::MEMTAG | ||
| SanitizerSet::THREAD | ||
| SanitizerSet::HWADDRESS, | ||
..base | ||
}, | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::spec::{Target, TargetOptions}; | ||
|
||
// This target is for OpenHarmony on ARMv7 Linux with thumb-mode, but no NEON or | ||
// hardfloat. | ||
|
||
pub fn target() -> Target { | ||
// Most of these settings are copied from the armv7_unknown_linux_musleabi | ||
// target. | ||
Target { | ||
// LLVM 15 doesn't support OpenHarmony yet, use a linux target instead. | ||
llvm_target: "armv7-unknown-linux-gnueabi".into(), | ||
pointer_width: 32, | ||
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), | ||
arch: "arm".into(), | ||
|
||
options: TargetOptions { | ||
abi: "eabi".into(), | ||
features: "+v7,+thumb2,+soft-float,-neon".into(), | ||
max_atomic_width: Some(64), | ||
env: "ohos".into(), | ||
crt_static_default: false, | ||
mcount: "\u{1}mcount".into(), | ||
force_emulated_tls: true, | ||
..super::linux_musl_base::opts() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# `*-linux-ohos*` | ||
|
||
**Tier: 3** | ||
|
||
Targets for the [OpenHarmony](https://gitee.com/openharmony/docs/) operating | ||
system. | ||
|
||
## Target maintainers | ||
|
||
- Amanieu d'Antras ([@Amanieu](https://github.com/Amanieu)) | ||
|
||
## Setup | ||
|
||
The OpenHarmony SDK doesn't currently support Rust compilation directly, so | ||
some setup is required. | ||
|
||
First, you must obtain the OpenHarmony SDK from [this page](https://gitee.com/openharmony/docs/tree/master/en/release-notes). | ||
Select the version of OpenHarmony you are developing for and download the "Public SDK package for the standard system". | ||
|
||
Create the following shell scripts that wrap Clang from the OpenHarmony SDK: | ||
|
||
`aarch64-unknown-linux-ohos-clang.sh` | ||
|
||
```sh | ||
#!/bin/sh | ||
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang \ | ||
-target aarch64-linux-ohos \ | ||
--sysroot=/path/to/ohos-sdk/linux/native/sysroot \ | ||
-D__MUSL__ \ | ||
"$@" | ||
``` | ||
|
||
`aarch64-unknown-linux-ohos-clang++.sh` | ||
|
||
```sh | ||
#!/bin/sh | ||
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang++ \ | ||
-target aarch64-linux-ohos \ | ||
--sysroot=/path/to/ohos-sdk/linux/native/sysroot \ | ||
-D__MUSL__ \ | ||
"$@" | ||
``` | ||
|
||
`armv7-unknown-linux-ohos-clang.sh` | ||
|
||
```sh | ||
#!/bin/sh | ||
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang \ | ||
-target arm-linux-ohos \ | ||
--sysroot=/path/to/ohos-sdk/linux/native/sysroot \ | ||
-D__MUSL__ \ | ||
-march=armv7-a \ | ||
-mfloat-abi=softfp \ | ||
-mtune=generic-armv7-a \ | ||
-mthumb \ | ||
"$@" | ||
``` | ||
|
||
`armv7-unknown-linux-ohos-clang++.sh` | ||
|
||
```sh | ||
#!/bin/sh | ||
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang++ \ | ||
-target arm-linux-ohos \ | ||
--sysroot=/path/to/ohos-sdk/linux/native/sysroot \ | ||
-D__MUSL__ \ | ||
-march=armv7-a \ | ||
-mfloat-abi=softfp \ | ||
-mtune=generic-armv7-a \ | ||
-mthumb \ | ||
"$@" | ||
``` | ||
|
||
Future versions of the OpenHarmony SDK will avoid the need for this process. | ||
|
||
## Building the target | ||
|
||
To build a rust toolchain, create a `config.toml` with the following contents: | ||
|
||
```toml | ||
profile = "compiler" | ||
changelog-seen = 2 | ||
|
||
[build] | ||
sanitizers = true | ||
profiler = true | ||
|
||
[target.aarch64-unknown-linux-ohos] | ||
cc = "/path/to/aarch64-unknown-linux-ohos-clang.sh" | ||
cxx = "/path/to/aarch64-unknown-linux-ohos-clang++.sh" | ||
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar" | ||
ranlib = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ranlib" | ||
linker = "/path/to/aarch64-unknown-linux-ohos-clang.sh" | ||
|
||
[target.armv7-unknown-linux-ohos] | ||
cc = "/path/to/armv7-unknown-linux-ohos-clang.sh" | ||
cxx = "/path/to/armv7-unknown-linux-ohos-clang++.sh" | ||
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar" | ||
ranlib = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ranlib" | ||
linker = "/path/to/armv7-unknown-linux-ohos-clang.sh" | ||
``` | ||
|
||
## Building Rust programs | ||
|
||
Rust does not yet ship pre-compiled artifacts for this target. To compile for | ||
this target, you will either need to build Rust with the target enabled (see | ||
"Building the target" above), or build your own copy of `core` by using | ||
`build-std` or similar. | ||
|
||
You will need to configure the linker to use in `~/.cargo/config`: | ||
```toml | ||
[target.aarch64-unknown-linux-ohos] | ||
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar" | ||
linker = "/path/to/aarch64-unknown-linux-ohos-clang.sh" | ||
|
||
[target.armv7-unknown-linux-ohos] | ||
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar" | ||
linker = "/path/to/armv7-unknown-linux-ohos-clang.sh" | ||
``` | ||
|
||
## Testing | ||
|
||
Running the Rust testsuite is possible, but currently difficult due to the way | ||
the OpenHarmony emulator is set up (no networking). | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
You can use the shell scripts above to compile C code for the target. |