Skip to content

Commit 9be97c9

Browse files
committed
Auto merge of #1050 - MegatonHammer:master, r=alexcrichton
Add libc definitions for Megaton-Hammer, a Switch Homebrew toolchain I'm working on a pure-rust toolchain to write homebrew for the Nintendo Switch called [Megaton-Hammer](http://github.com/megatonhammer/megaton-hammer). I'm hoping to get those definitions upstreamed to simplify my life :). This toolchain does not depend on a C compiler or a libc (it reimplements everything in rust) - but given many crates in the Rust ecosystem rely on the libc crate for the definition of various common types, this is what I came up with. I was wondering what a good target triple would be ? I currently gate the implementation behind `target_os = "switch"`, but if this goes upstream I figure that might cause trouble for people using the Nintendo SDK (they might already be using `target_os = "switch"` for some things). Would it be better to go with `target_env = "megatonhammer"`?
2 parents fc8db96 + 8ff70b6 commit 9be97c9

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ mod dox;
104104
cfg_if! {
105105
if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
106106
// empty ...
107+
} else if #[cfg(target_os = "switch")] {
108+
// On the Switch, we only define some useful universal types for
109+
// convenience. Those can be found in the switch.rs file.
107110
} else {
108111

109112
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
@@ -296,6 +299,9 @@ cfg_if! {
296299
} else if #[cfg(target_os = "fuchsia")] {
297300
mod fuchsia;
298301
pub use fuchsia::*;
302+
} else if #[cfg(target_os = "switch")] {
303+
mod switch;
304+
pub use switch::*;
299305
} else if #[cfg(unix)] {
300306
mod unix;
301307
pub use unix::*;

src/switch.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//! Switch C type definitions
2+
3+
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
4+
// more optimization opportunities around it recognizing things like
5+
// malloc/free.
6+
#[repr(u8)]
7+
pub enum c_void {
8+
// Two dummy variants so the #[repr] attribute can be used.
9+
#[doc(hidden)]
10+
__variant1,
11+
#[doc(hidden)]
12+
__variant2,
13+
}
14+
15+
pub type int8_t = i8;
16+
pub type int16_t = i16;
17+
pub type int32_t = i32;
18+
pub type int64_t = i64;
19+
pub type uint8_t = u8;
20+
pub type uint16_t = u16;
21+
pub type uint32_t = u32;
22+
pub type uint64_t = u64;
23+
24+
pub type c_schar = i8;
25+
pub type c_uchar = u8;
26+
pub type c_short = i16;
27+
pub type c_ushort = u16;
28+
pub type c_int = i32;
29+
pub type c_uint = u32;
30+
pub type c_float = f32;
31+
pub type c_double = f64;
32+
pub type c_longlong = i64;
33+
pub type c_ulonglong = u64;
34+
pub type intmax_t = i64;
35+
pub type uintmax_t = u64;
36+
37+
pub type size_t = usize;
38+
pub type ptrdiff_t = isize;
39+
pub type intptr_t = isize;
40+
pub type uintptr_t = usize;
41+
pub type ssize_t = isize;
42+
43+
// Arch specific
44+
pub type off_t = i64;
45+
pub type c_char = u8;
46+
pub type c_long = i64;
47+
pub type c_ulong = u64;
48+
pub type wchar_t = u32;

0 commit comments

Comments
 (0)