Skip to content

Commit 8d94e00

Browse files
committed
Auto merge of #1292 - hermitcore:master, r=gnzlbg
add HermitCore support even if it doesn't have a UNIX interface Currently, we redefine the interface between the HermitCore kernel (https://hermitcore.org) and Rust’s standard library. In the future, it will not depend on a POSIX-compatible C library. Consequently, we add the support of HermitCore if the "unix" environment isn’t set. It will be great to integrate this patch because it would simplify our development. The classical interface is still supported and part of the subdirectory "unix".
2 parents 234f9a6 + 14353e8 commit 8d94e00

File tree

6 files changed

+412
-61
lines changed

6 files changed

+412
-61
lines changed

ci/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ done
167167
# FIXME: https://github.com/rust-lang/rust/issues/58564
168168
# sparc-unknown-linux-gnu
169169
RUST_LINUX_NO_CORE_TARGETS="\
170+
x86_64-unknown-hermit \
170171
x86_64-unknown-dragonfly \
172+
aarch64-unknown-hermit \
171173
aarch64-pc-windows-msvc \
172174
aarch64-unknown-cloudabi \
173175
armebv7r-none-eabi \

src/hermit/aarch64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub type c_char = u8;
2+
pub type wchar_t = u32;

src/hermit/mod.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// libc port for HermitCore (https://hermitcore.org)
12+
//
13+
// Ported by Colin Fink <colin.finck@rwth-aachen.de>
14+
// and Stefan Lankes <slankes@eonerc.rwth-aachen.de>
15+
16+
pub type int8_t = i8;
17+
pub type int16_t = i16;
18+
pub type int32_t = i32;
19+
pub type int64_t = i64;
20+
pub type uint8_t = u8;
21+
pub type uint16_t = u16;
22+
pub type uint32_t = u32;
23+
pub type uint64_t = u64;
24+
25+
pub type c_schar = i8;
26+
pub type c_uchar = u8;
27+
pub type c_short = i16;
28+
pub type c_ushort = u16;
29+
pub type c_int = i32;
30+
pub type c_uint = u32;
31+
pub type c_float = f32;
32+
pub type c_double = f64;
33+
pub type c_longlong = i64;
34+
pub type c_ulonglong = u64;
35+
pub type intmax_t = i64;
36+
pub type uintmax_t = u64;
37+
38+
pub type size_t = usize;
39+
pub type ptrdiff_t = isize;
40+
pub type intptr_t = isize;
41+
pub type uintptr_t = usize;
42+
pub type ssize_t = isize;
43+
44+
pub type c_long = i64;
45+
pub type c_ulong = u64;
46+
47+
pub type wint_t = u32;
48+
pub type wctype_t = i64;
49+
50+
pub type regoff_t = size_t;
51+
pub type off_t = c_long;
52+
53+
cfg_if! {
54+
if #[cfg(target_arch = "aarch64")] {
55+
mod aarch64;
56+
pub use self::aarch64::*;
57+
} else if #[cfg(target_arch = "x86_64")] {
58+
mod x86_64;
59+
pub use self::x86_64::*;
60+
} else {
61+
// Unknown target_arch
62+
}
63+
}
64+
65+
cfg_if! {
66+
if #[cfg(libc_core_cvoid)] {
67+
pub use ::ffi::c_void;
68+
} else {
69+
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
70+
// enable more optimization opportunities around it recognizing things
71+
// like malloc/free.
72+
#[repr(u8)]
73+
#[allow(missing_copy_implementations)]
74+
#[allow(missing_debug_implementations)]
75+
pub enum c_void {
76+
// Two dummy variants so the #[repr] attribute can be used.
77+
#[doc(hidden)]
78+
__variant1,
79+
#[doc(hidden)]
80+
__variant2,
81+
}
82+
}
83+
}

src/hermit/x86_64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub type c_char = i8;
2+
pub type wchar_t = i32;

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ cfg_if! {
106106
} else if #[cfg(unix)] {
107107
mod unix;
108108
pub use unix::*;
109+
} else if #[cfg(target_os = "hermit")] {
110+
mod hermit;
111+
pub use hermit::*;
109112
} else if #[cfg(target_env = "sgx")] {
110113
mod sgx;
111114
pub use sgx::*;

0 commit comments

Comments
 (0)