Skip to content

Add DevkitPPC support #1851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ newer Rust features are only available on newer Rust toolchains:
| `extra_traits` | 1.25.0 |
| `core::ffi::c_void` | 1.30.0 |
| `repr(packed(N))` | 1.33.0 |
| `cfg(target_vendor)` | 1.33.0 |

## Platform support

Expand Down
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ fn main() {
println!("cargo:rustc-cfg=libc_core_cvoid");
}

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

// #[thread_local] is currently unstable
Expand Down
16 changes: 16 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,13 @@ extern "C" {
pub fn getchar_unlocked() -> ::c_int;
pub fn putchar_unlocked(c: ::c_int) -> ::c_int;

#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")]
pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
link_name = "connect$UNIX2003"
Expand All @@ -614,6 +618,8 @@ extern "C" {
link_name = "listen$UNIX2003"
)]
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
link_name = "accept$UNIX2003"
Expand All @@ -623,6 +629,8 @@ extern "C" {
address: *mut sockaddr,
address_len: *mut socklen_t,
) -> ::c_int;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
link_name = "getpeername$UNIX2003"
Expand All @@ -632,6 +640,8 @@ extern "C" {
address: *mut sockaddr,
address_len: *mut socklen_t,
) -> ::c_int;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
link_name = "getsockname$UNIX2003"
Expand Down Expand Up @@ -659,6 +669,8 @@ extern "C" {
protocol: ::c_int,
socket_vector: *mut ::c_int,
) -> ::c_int;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
link_name = "sendto$UNIX2003"
Expand Down Expand Up @@ -1234,13 +1246,17 @@ extern "C" {
pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;

#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_getaddrinfo")]
pub fn getaddrinfo(
node: *const c_char,
service: *const c_char,
hints: *const addrinfo,
res: *mut *mut addrinfo,
) -> ::c_int;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
pub fn freeaddrinfo(res: *mut addrinfo);
pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
#[cfg_attr(
Expand Down
13 changes: 13 additions & 0 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ s! {
pub ai_protocol: ::c_int,
pub ai_addrlen: socklen_t,

#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg(target_arch = "xtensa")]
pub ai_addr: *mut sockaddr,

pub ai_canonname: *mut ::c_char,

#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
#[cfg(not(target_arch = "xtensa"))]
pub ai_addr: *mut sockaddr,

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

#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t)
-> ::c_int;
pub fn clock_settime(
Expand All @@ -614,6 +620,8 @@ extern "C" {
) -> ::c_int;
pub fn closesocket(sockfd: ::c_int) -> ::c_int;
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
pub fn recvfrom(
fd: ::c_int,
buf: *mut ::c_void,
Expand All @@ -622,6 +630,8 @@ extern "C" {
addr: *mut sockaddr,
addr_len: *mut socklen_t,
) -> isize;
#[cfg(not(all(libc_cfg_target_vendor, target_arch = "powerpc",
target_vendor = "nintendo")))]
pub fn getnameinfo(
sa: *const sockaddr,
salen: socklen_t,
Expand Down Expand Up @@ -700,6 +710,9 @@ cfg_if! {
} else if #[cfg(target_arch = "xtensa")] {
mod xtensa;
pub use self::xtensa::*;
} else if #[cfg(target_arch = "powerpc")] {
mod powerpc;
pub use self::powerpc::*;
} else {
// Only tested on ARM so far. Other platforms might have different
// definitions for types and constants.
Expand Down
14 changes: 14 additions & 0 deletions src/unix/newlib/powerpc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub type clock_t = ::c_ulong;
pub type c_char = u8;
pub type wchar_t = ::c_int;

pub type c_long = i32;
pub type c_ulong = u32;

// the newlib shipped with devkitPPC does not support the following components:
// - sockaddr
// - AF_INET6
// - FIONBIO
// - POLL*
// - SOL_SOCKET
// - MSG_*