Skip to content

Commit e9a1268

Browse files
Dark KirbDarkKirb
Dark Kirb
authored andcommitted
Add DevkitPPC support
DevkitPPC does not support unix sockets natively, meaning that bindings to these functions was removed for powerpc targets with "nintendo" as vendor. Suggested target json files: Nintendo Gamecube: ``` { "arch": "powerpc", "data-layout": "E-m:e-p:32:32-i64:64-n32", "dynamic-linking": false, "env": "newlib", "executables": true, "has-elf-tls": false, "has-rpath": true, "linker-flavor": "gcc", "llvm-target": "powerpc-eabi", "max-atomic-width": 32, "os": "dolphin", "target-c-int-width": "32", "target-endian": "big", "target-family": "unix", "target-mcount": "_mcount", "target-pointer-width": "32", "vendor": "nintendo" } ``` Nintendo Wii: ``` { "arch": "powerpc", "data-layout": "E-m:e-p:32:32-i64:64-n32", "dynamic-linking": false, "env": "newlib", "executables": true, "has-elf-tls": false, "has-rpath": true, "linker-flavor": "gcc", "llvm-target": "powerpc-eabi", "max-atomic-width": 32, "os": "revolution", "target-c-int-width": "32", "target-endian": "big", "target-family": "unix", "target-mcount": "_mcount", "target-pointer-width": "32", "vendor": "nintendo" } ```
1 parent 510badd commit e9a1268

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ newer Rust features are only available on newer Rust toolchains:
5252
| `extra_traits` | 1.25.0 |
5353
| `core::ffi::c_void` | 1.30.0 |
5454
| `repr(packed(N))` | 1.33.0 |
55+
| `cfg(target_vendor)` | 1.33.0 |
5556

5657
## Platform support
5758

build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ fn main() {
6565
println!("cargo:rustc-cfg=libc_core_cvoid");
6666
}
6767

68-
// Rust >= 1.33 supports repr(packed(N))
68+
// Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor).
6969
if rustc_minor_ver >= 33 || rustc_dep_of_std {
7070
println!("cargo:rustc-cfg=libc_packedN");
71+
println!("cargo:rustc-cfg=libc_cfg_target_vendor");
7172
}
7273

7374
// #[thread_local] is currently unstable

src/unix/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,13 @@ extern "C" {
596596
pub fn getchar_unlocked() -> ::c_int;
597597
pub fn putchar_unlocked(c: ::c_int) -> ::c_int;
598598

599+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
600+
target_vendor = "nintendo")))]
599601
#[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
600602
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")]
601603
pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int;
604+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
605+
target_vendor = "nintendo")))]
602606
#[cfg_attr(
603607
all(target_os = "macos", target_arch = "x86"),
604608
link_name = "connect$UNIX2003"
@@ -614,6 +618,8 @@ extern "C" {
614618
link_name = "listen$UNIX2003"
615619
)]
616620
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
621+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
622+
target_vendor = "nintendo")))]
617623
#[cfg_attr(
618624
all(target_os = "macos", target_arch = "x86"),
619625
link_name = "accept$UNIX2003"
@@ -623,6 +629,8 @@ extern "C" {
623629
address: *mut sockaddr,
624630
address_len: *mut socklen_t,
625631
) -> ::c_int;
632+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
633+
target_vendor = "nintendo")))]
626634
#[cfg_attr(
627635
all(target_os = "macos", target_arch = "x86"),
628636
link_name = "getpeername$UNIX2003"
@@ -632,6 +640,8 @@ extern "C" {
632640
address: *mut sockaddr,
633641
address_len: *mut socklen_t,
634642
) -> ::c_int;
643+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
644+
target_vendor = "nintendo")))]
635645
#[cfg_attr(
636646
all(target_os = "macos", target_arch = "x86"),
637647
link_name = "getsockname$UNIX2003"
@@ -659,6 +669,8 @@ extern "C" {
659669
protocol: ::c_int,
660670
socket_vector: *mut ::c_int,
661671
) -> ::c_int;
672+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
673+
target_vendor = "nintendo")))]
662674
#[cfg_attr(
663675
all(target_os = "macos", target_arch = "x86"),
664676
link_name = "sendto$UNIX2003"
@@ -1234,13 +1246,17 @@ extern "C" {
12341246
pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
12351247
pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
12361248

1249+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
1250+
target_vendor = "nintendo")))]
12371251
#[cfg_attr(target_os = "illumos", link_name = "__xnet_getaddrinfo")]
12381252
pub fn getaddrinfo(
12391253
node: *const c_char,
12401254
service: *const c_char,
12411255
hints: *const addrinfo,
12421256
res: *mut *mut addrinfo,
12431257
) -> ::c_int;
1258+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
1259+
target_vendor = "nintendo")))]
12441260
pub fn freeaddrinfo(res: *mut addrinfo);
12451261
pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
12461262
#[cfg_attr(

src/unix/newlib/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ s! {
3333
pub ai_protocol: ::c_int,
3434
pub ai_addrlen: socklen_t,
3535

36+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
37+
target_vendor = "nintendo")))]
3638
#[cfg(target_arch = "xtensa")]
3739
pub ai_addr: *mut sockaddr,
3840

3941
pub ai_canonname: *mut ::c_char,
4042

43+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
44+
target_vendor = "nintendo")))]
4145
#[cfg(not(target_arch = "xtensa"))]
4246
pub ai_addr: *mut sockaddr,
4347

@@ -598,6 +602,8 @@ extern "C" {
598602
pub fn rand() -> ::c_int;
599603
pub fn srand(seed: ::c_uint);
600604

605+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
606+
target_vendor = "nintendo")))]
601607
pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t)
602608
-> ::c_int;
603609
pub fn clock_settime(
@@ -614,6 +620,8 @@ extern "C" {
614620
) -> ::c_int;
615621
pub fn closesocket(sockfd: ::c_int) -> ::c_int;
616622
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
623+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
624+
target_vendor = "nintendo")))]
617625
pub fn recvfrom(
618626
fd: ::c_int,
619627
buf: *mut ::c_void,
@@ -622,6 +630,8 @@ extern "C" {
622630
addr: *mut sockaddr,
623631
addr_len: *mut socklen_t,
624632
) -> isize;
633+
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
634+
target_vendor = "nintendo")))]
625635
pub fn getnameinfo(
626636
sa: *const sockaddr,
627637
salen: socklen_t,
@@ -700,6 +710,9 @@ cfg_if! {
700710
} else if #[cfg(target_arch = "xtensa")] {
701711
mod xtensa;
702712
pub use self::xtensa::*;
713+
} else if #[cfg(target_arch = "powerpc")] {
714+
mod powerpc;
715+
pub use self::powerpc::*;
703716
} else {
704717
// Only tested on ARM so far. Other platforms might have different
705718
// definitions for types and constants.

src/unix/newlib/powerpc/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub type clock_t = ::c_ulong;
2+
pub type c_char = u8;
3+
pub type wchar_t = ::c_int;
4+
5+
pub type c_long = i32;
6+
pub type c_ulong = u32;
7+
8+
// the newlib shipped with devkitPPC does not support the following components:
9+
// - sockaddr
10+
// - AF_INET6
11+
// - FIONBIO
12+
// - POLL*
13+
// - SOL_SOCKET
14+
// - MSG_*

0 commit comments

Comments
 (0)