Skip to content

Commit 1de5b22

Browse files
committed
add riscv64gc-unknown-openbsd support (target riscv64-unknown-openbsd on OpenBSD)
- add platform-support documentation - add riscv64gc-unknown-openbsd spec - do not try to link with -latomic on openbsd
1 parent dacb6ee commit 1de5b22

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

compiler/rustc_llvm/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ fn main() {
342342
};
343343

344344
// RISC-V GCC erroneously requires libatomic for sub-word
345-
// atomic operations. FreeBSD uses Clang as its system
345+
// atomic operations. Some BSD uses Clang as its system
346346
// compiler and provides no libatomic in its base system so
347347
// does not want this.
348-
if !target.contains("freebsd") && target.starts_with("riscv") {
348+
if target.starts_with("riscv") && !target.contains("freebsd") && !target.contains("openbsd") {
349349
println!("cargo:rustc-link-lib=atomic");
350350
}
351351

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ supported_targets! {
895895
("i686-unknown-openbsd", i686_unknown_openbsd),
896896
("powerpc-unknown-openbsd", powerpc_unknown_openbsd),
897897
("powerpc64-unknown-openbsd", powerpc64_unknown_openbsd),
898+
("riscv64gc-unknown-openbsd", riscv64gc_unknown_openbsd),
898899
("sparc64-unknown-openbsd", sparc64_unknown_openbsd),
899900
("x86_64-unknown-openbsd", x86_64_unknown_openbsd),
900901

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::spec::{CodeModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "riscv64-unknown-openbsd".into(),
6+
pointer_width: 64,
7+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),
8+
arch: "riscv64".into(),
9+
options: TargetOptions {
10+
code_model: Some(CodeModel::Medium),
11+
cpu: "generic-rv64".into(),
12+
features: "+m,+a,+f,+d,+c".into(),
13+
llvm_abiname: "lp64d".into(),
14+
max_atomic_width: Some(64),
15+
..super::openbsd_base::opts()
16+
},
17+
}
18+
}

src/bootstrap/native.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,13 @@ impl Step for Llvm {
432432
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
433433
}
434434

435-
if target.starts_with("riscv") && !target.contains("freebsd") {
435+
if target.starts_with("riscv") && !target.contains("freebsd") && !target.contains("openbsd")
436+
{
436437
// RISC-V GCC erroneously requires linking against
437438
// `libatomic` when using 1-byte and 2-byte C++
438439
// atomics but the LLVM build system check cannot
439440
// detect this. Therefore it is set manually here.
440-
// FreeBSD uses Clang as its system compiler and
441+
// Some BSD uses Clang as its system compiler and
441442
// provides no libatomic in its base system so does
442443
// not want this.
443444
ldflags.exe.push(" -latomic");

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

+1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ target | std | host | notes
285285
`riscv32imc-esp-espidf` | ✓ | | RISC-V ESP-IDF
286286
`riscv64gc-unknown-freebsd` | | | RISC-V FreeBSD
287287
`riscv64gc-unknown-linux-musl` | | | RISC-V Linux (kernel 4.20, musl 1.2.0)
288+
[`riscv64gc-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/riscv64
288289
`s390x-unknown-linux-musl` | | | S390x Linux (kernel 3.2, MUSL)
289290
`sparc-unknown-linux-gnu` | ✓ | | 32-bit SPARC Linux
290291
`sparc64-unknown-netbsd` | ✓ | ✓ | NetBSD/sparc64

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

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The target names follow this format: `$ARCH-unknown-openbsd`, where `$ARCH` spec
1313
| `aarch64-unknown-openbsd` | libc++ | [64-bit ARM systems](https://www.openbsd.org/arm64.html) |
1414
| `i686-unknown-openbsd` | libc++ | [Standard PC and clones based on the Intel i386 architecture and compatible processors](https://www.openbsd.org/i386.html) |
1515
| `powerpc64-unknown-openbsd` | libc++ | [IBM POWER-based PowerNV systems](https://www.openbsd.org/powerpc64.html) |
16+
| `riscv64gc-unknown-openbsd` | libc++ | [64-bit RISC-V systems](https://www.openbsd.org/riscv64.html) |
1617
| `sparc64-unknown-openbsd` | estdc++ | [Sun UltraSPARC and Fujitsu SPARC64 systems](https://www.openbsd.org/sparc64.html) |
1718
| `x86_64-unknown-openbsd` | libc++ | [AMD64-based systems](https://www.openbsd.org/amd64.html) |
1819

0 commit comments

Comments
 (0)