Skip to content

Commit 5d46bd9

Browse files
committed
Add x86_64-unknown-linux-ohos target
This complements the existing `aarch64-unknown-linux-ohos` and `armv7-unknown-linux-ohos` targets.
1 parent fe37f37 commit 5d46bd9

File tree

8 files changed

+79
-10
lines changed

8 files changed

+79
-10
lines changed

compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use crate::spec::{Target, TargetOptions};
33
use super::SanitizerSet;
44

55
pub fn target() -> Target {
6-
let mut base = super::linux_musl_base::opts();
7-
base.env = "ohos".into();
8-
base.crt_static_default = false;
6+
let mut base = super::linux_ohos_base::opts();
97
base.max_atomic_width = Some(128);
108

119
Target {
@@ -17,8 +15,6 @@ pub fn target() -> Target {
1715
options: TargetOptions {
1816
features: "+reserve-x18".into(),
1917
mcount: "\u{1}_mcount".into(),
20-
force_emulated_tls: true,
21-
has_thread_local: false,
2218
supported_sanitizers: SanitizerSet::ADDRESS
2319
| SanitizerSet::CFI
2420
| SanitizerSet::LEAK

compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ pub fn target() -> Target {
1717
abi: "eabi".into(),
1818
features: "+v7,+thumb2,+soft-float,-neon".into(),
1919
max_atomic_width: Some(64),
20-
env: "ohos".into(),
21-
crt_static_default: false,
2220
mcount: "\u{1}mcount".into(),
23-
force_emulated_tls: true,
24-
has_thread_local: false,
25-
..super::linux_musl_base::opts()
21+
..super::linux_ohos_base::opts()
2622
},
2723
}
2824
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::spec::TargetOptions;
2+
3+
pub fn opts() -> TargetOptions {
4+
let mut base = super::linux_base::opts();
5+
6+
base.env = "ohos".into();
7+
base.crt_static_default = false;
8+
base.force_emulated_tls = true;
9+
base.has_thread_local = false;
10+
11+
base
12+
}

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod l4re_base;
7373
mod linux_base;
7474
mod linux_gnu_base;
7575
mod linux_musl_base;
76+
mod linux_ohos_base;
7677
mod linux_uclibc_base;
7778
mod msvc_base;
7879
mod netbsd_base;
@@ -1365,6 +1366,7 @@ supported_targets! {
13651366

13661367
("aarch64-unknown-linux-ohos", aarch64_unknown_linux_ohos),
13671368
("armv7-unknown-linux-ohos", armv7_unknown_linux_ohos),
1369+
("x86_64-unknown-linux-ohos", x86_64_unknown_linux_ohos),
13681370
}
13691371

13701372
/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target};
2+
3+
pub fn target() -> Target {
4+
let mut base = super::linux_ohos_base::opts();
5+
base.cpu = "x86-64".into();
6+
base.max_atomic_width = Some(64);
7+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
8+
base.stack_probes = StackProbeType::X86;
9+
base.static_position_independent_executables = true;
10+
base.supported_sanitizers = SanitizerSet::ADDRESS
11+
| SanitizerSet::CFI
12+
| SanitizerSet::LEAK
13+
| SanitizerSet::MEMORY
14+
| SanitizerSet::THREAD;
15+
base.supports_xray = true;
16+
17+
Target {
18+
// LLVM 15 doesn't support OpenHarmony yet, use a linux target instead.
19+
llvm_target: "x86_64-unknown-linux-musl".into(),
20+
pointer_width: 64,
21+
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
22+
.into(),
23+
arch: "x86_64".into(),
24+
options: base,
25+
}
26+
}

src/bootstrap/llvm.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,9 @@ fn supported_sanitizers(
10531053
"s390x-unknown-linux-musl" => {
10541054
common_libs("linux", "s390x", &["asan", "lsan", "msan", "tsan"])
10551055
}
1056+
"x86_64-unknown-linux-ohos" => {
1057+
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
1058+
}
10561059
_ => Vec::new(),
10571060
}
10581061
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ target | std | host | notes
326326
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
327327
`x86_64-unknown-hermit` | ✓ | | HermitCore
328328
`x86_64-unknown-l4re-uclibc` | ? | |
329+
[`x86_64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | x86_64 OpenHarmony |
329330
[`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD
330331
`x86_64-uwp-windows-gnu` | ✓ | |
331332
`x86_64-uwp-windows-msvc` | ✓ | |

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

+33
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ exec /path/to/ohos-sdk/linux/native/llvm/bin/clang++ \
7171
"$@"
7272
```
7373

74+
`x86_64-unknown-linux-ohos-clang.sh`
75+
76+
```sh
77+
#!/bin/sh
78+
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang \
79+
-target x86_64-linux-ohos \
80+
--sysroot=/path/to/ohos-sdk/linux/native/sysroot \
81+
-D__MUSL__ \
82+
"$@"
83+
```
84+
85+
`x86_64-unknown-linux-ohos-clang++.sh`
86+
87+
```sh
88+
#!/bin/sh
89+
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang++ \
90+
-target x86_64-linux-ohos \
91+
--sysroot=/path/to/ohos-sdk/linux/native/sysroot \
92+
-D__MUSL__ \
93+
"$@"
94+
```
95+
7496
Future versions of the OpenHarmony SDK will avoid the need for this process.
7597

7698
## Building the target
@@ -98,6 +120,13 @@ cxx = "/path/to/armv7-unknown-linux-ohos-clang++.sh"
98120
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar"
99121
ranlib = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ranlib"
100122
linker = "/path/to/armv7-unknown-linux-ohos-clang.sh"
123+
124+
[target.x86_64-unknown-linux-ohos]
125+
cc = "/path/to/x86_64-unknown-linux-ohos-clang.sh"
126+
cxx = "/path/to/x86_64-unknown-linux-ohos-clang++.sh"
127+
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar"
128+
ranlib = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ranlib"
129+
linker = "/path/to/x86_64-unknown-linux-ohos-clang.sh"
101130
```
102131

103132
## Building Rust programs
@@ -116,6 +145,10 @@ linker = "/path/to/aarch64-unknown-linux-ohos-clang.sh"
116145
[target.armv7-unknown-linux-ohos]
117146
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar"
118147
linker = "/path/to/armv7-unknown-linux-ohos-clang.sh"
148+
149+
[target.x86_64-unknown-linux-ohos]
150+
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar"
151+
linker = "/path/to/x86_64-unknown-linux-ohos-clang.sh"
119152
```
120153

121154
## Testing

0 commit comments

Comments
 (0)