Skip to content

Commit

Permalink
add haiku support
Browse files Browse the repository at this point in the history
* enabled as much functionality and defines that match
  updated libc definitions for haiku
  • Loading branch information
Al Hoang committed May 10, 2022
1 parent db41e0b commit 55333e4
Show file tree
Hide file tree
Showing 31 changed files with 425 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ task:
- name: OpenBSD x86_64
env:
TARGET: x86_64-unknown-openbsd
- name: Haiku x86_64
env:
TARGET: x86_64-unknown-haiku
setup_script:
- rustup component add rust-src
<< : *BUILD
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- impl From<SockaddrIn> for std::net::SocketAddrV4 and
impl From<SockaddrIn6> for std::net::SocketAddrV6.
(#[1711](https://github.com/nix-rust/nix/pull/1711))
- Fixed compilation and updated support on Haiku
- Added support for the `x86_64-unknown-haiku` target.
(#[1703](https://github.com/nix-rust/nix/pull/1703))

### Changed
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ targets = [
]

[dependencies]
libc = { version = "0.2.121", features = [ "extra_traits" ] }
libc = { version = "0.2.125", features = [ "extra_traits" ] }
bitflags = "1.1"
cfg-if = "1.0"

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Tier 3:
* armv7-unknown-linux-uclibceabihf
* x86_64-fuchsia
* x86_64-unknown-dragonfly
* x86_64-unknown-haiku
* x86_64-unknown-linux-gnux32
* x86_64-unknown-openbsd
* x86_64-unknown-redox
Expand Down
1 change: 1 addition & 0 deletions bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ status = [
"iOS aarch64",
"iOS x86_64",
"Illumos",
"Haiku x86_64",
]

# Set bors's timeout to 1 hour
Expand Down
6 changes: 3 additions & 3 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl Entry {
/// notably, some Linux filesystems don't implement this. The caller should use `stat` or
/// `fstat` if this returns `None`.
pub fn file_type(&self) -> Option<Type> {
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
#[cfg(not(any(target_os = "illumos", target_os = "solaris", target_os = "haiku")))]
match self.0.d_type {
libc::DT_FIFO => Some(Type::Fifo),
libc::DT_CHR => Some(Type::CharacterDevice),
Expand All @@ -238,8 +238,8 @@ impl Entry {
/* libc::DT_UNKNOWN | */ _ => None,
}

// illumos and Solaris systems do not have the d_type member at all:
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
// illumos, Solaris, and Haiku systems do not have the d_type member at all:
#[cfg(any(target_os = "illumos", target_os = "solaris", target_os = "haiku"))]
None
}
}
209 changes: 198 additions & 11 deletions src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ cfg_if! {
unsafe fn errno_location() -> *mut c_int {
libc::___errno()
}
} else if #[cfg(any(target_os = "haiku",))] {
unsafe fn errno_location() -> *mut c_int {
libc::_errnop()
}
}
}

Expand Down Expand Up @@ -201,6 +205,7 @@ fn desc(errno: Errno) -> &'static str {
ENOMEM => "Out of memory",
EACCES => "Permission denied",
EFAULT => "Bad address",
#[cfg(not(target_os = "haiku"))]
ENOTBLK => "Block device required",
EBUSY => "Device or resource busy",
EEXIST => "File exists",
Expand Down Expand Up @@ -237,8 +242,11 @@ fn desc(errno: Errno) -> &'static str {
EPROTOTYPE => "Protocol wrong type for socket",
ENOPROTOOPT => "Protocol not available",
EPROTONOSUPPORT => "Protocol not supported",
#[cfg(not(target_os = "haiku"))]
ESOCKTNOSUPPORT => "Socket type not supported",
#[cfg(not(target_os = "haiku"))]
EPFNOSUPPORT => "Protocol family not supported",
#[cfg(not(target_os = "haiku"))]
EAFNOSUPPORT => "Address family not supported by protocol",
EADDRINUSE => "Address already in use",
EADDRNOTAVAIL => "Cannot assign requested address",
Expand All @@ -251,6 +259,7 @@ fn desc(errno: Errno) -> &'static str {
EISCONN => "Transport endpoint is already connected",
ENOTCONN => "Transport endpoint is not connected",
ESHUTDOWN => "Cannot send after transport endpoint shutdown",
#[cfg(not(target_os = "haiku"))]
ETOOMANYREFS => "Too many references: cannot splice",
ETIMEDOUT => "Connection timed out",
ECONNREFUSED => "Connection refused",
Expand Down Expand Up @@ -409,7 +418,7 @@ fn desc(errno: Errno) -> &'static str {
EBADMSG => "Trying to read unreadable message",

#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
target_os = "fuchsia", target_os = "haiku"))]
EOVERFLOW => "Value too large for defined data type",

#[cfg(any(target_os = "linux", target_os = "android",
Expand Down Expand Up @@ -516,7 +525,7 @@ fn desc(errno: Errno) -> &'static str {

#[cfg(any(target_os = "linux", target_os = "android",
target_os = "illumos", target_os = "solaris",
target_os = "fuchsia"))]
target_os = "fuchsia", target_os = "haiku"))]
ECANCELED => "Operation canceled",

#[cfg(any(target_os = "linux", target_os = "android",
Expand Down Expand Up @@ -587,24 +596,26 @@ fn desc(errno: Errno) -> &'static str {

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "netbsd", target_os = "redox"))]
target_os = "netbsd", target_os = "redox",
target_os = "haiku"))]
EILSEQ => "Illegal byte sequence",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "haiku"))]
ENOATTR => "Attribute not found",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
target_os = "redox", target_os = "haiku"))]
EBADMSG => "Bad message",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
target_os = "redox", target_os = "haiku"))]
EPROTO => "Protocol error",

#[cfg(any(target_os = "macos", target_os = "freebsd",
Expand All @@ -620,7 +631,8 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd",
target_os = "illumos", target_os = "solaris"))]
target_os = "illumos", target_os = "solaris",
target_os = "haiku"))]
ENOTSUP => "Operation not supported",

#[cfg(any(target_os = "macos", target_os = "freebsd",
Expand All @@ -638,14 +650,14 @@ fn desc(errno: Errno) -> &'static str {
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd",
target_os = "redox", target_os = "illumos",
target_os = "solaris"))]
target_os = "solaris", target_os = "haiku"))]
EDQUOT => "Disc quota exceeded",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd",
target_os = "redox", target_os = "illumos",
target_os = "solaris"))]
target_os = "solaris", target_os = "haiku"))]
ESTALE => "Stale NFS file handle",

#[cfg(any(target_os = "macos", target_os = "freebsd",
Expand Down Expand Up @@ -714,15 +726,15 @@ fn desc(errno: Errno) -> &'static str {
EBADMACHO => "Malformed Macho file",

#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "netbsd"))]
target_os = "netbsd", target_os = "haiku"))]
EMULTIHOP => "Reserved",

#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "netbsd", target_os = "redox"))]
ENODATA => "No message available on STREAM",

#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "netbsd"))]
target_os = "netbsd", target_os = "haiku"))]
ENOLINK => "Reserved",

#[cfg(any(target_os = "macos", target_os = "ios",
Expand Down Expand Up @@ -2725,3 +2737,178 @@ mod consts {
}
}
}

#[cfg(target_os = "haiku")]
mod consts {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
#[non_exhaustive]
pub enum Errno {
UnknownErrno = 0,
EPERM = libc::EPERM,
ENOENT = libc::ENOENT,
ESRCH = libc::ESRCH,
EINTR = libc::EINTR,
EIO = libc::EIO,
ENXIO = libc::ENXIO,
E2BIG = libc::E2BIG,
ENOEXEC = libc::ENOEXEC,
EBADF = libc::EBADF,
ECHILD = libc::ECHILD,
EDEADLK = libc::EDEADLK,
ENOMEM = libc::ENOMEM,
EACCES = libc::EACCES,
EFAULT = libc::EFAULT,
EBUSY = libc::EBUSY,
EEXIST = libc::EEXIST,
EXDEV = libc::EXDEV,
ENODEV = libc::ENODEV,
ENOTDIR = libc::ENOTDIR,
EISDIR = libc::EISDIR,
EINVAL = libc::EINVAL,
ENFILE = libc::ENFILE,
EMFILE = libc::EMFILE,
ENOTTY = libc::ENOTTY,
ETXTBSY = libc::ETXTBSY,
EFBIG = libc::EFBIG,
ENOSPC = libc::ENOSPC,
ESPIPE = libc::ESPIPE,
EROFS = libc::EROFS,
EMLINK = libc::EMLINK,
EPIPE = libc::EPIPE,
EDOM = libc::EDOM,
ERANGE = libc::ERANGE,
EAGAIN = libc::EAGAIN,
EINPROGRESS = libc::EINPROGRESS,
EALREADY = libc::EALREADY,
ENOTSOCK = libc::ENOTSOCK,
EDESTADDRREQ = libc::EDESTADDRREQ,
EMSGSIZE = libc::EMSGSIZE,
EPROTOTYPE = libc::EPROTOTYPE,
ENOPROTOOPT = libc::ENOPROTOOPT,
EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
ENOTSUP = libc::ENOTSUP,
EADDRINUSE = libc::EADDRINUSE,
EADDRNOTAVAIL = libc::EADDRNOTAVAIL,
ENETDOWN = libc::ENETDOWN,
ENETUNREACH = libc::ENETUNREACH,
ENETRESET = libc::ENETRESET,
ECONNABORTED = libc::ECONNABORTED,
ECONNRESET = libc::ECONNRESET,
ENOBUFS = libc::ENOBUFS,
EISCONN = libc::EISCONN,
ENOTCONN = libc::ENOTCONN,
ESHUTDOWN = libc::ESHUTDOWN,
ETIMEDOUT = libc::ETIMEDOUT,
ECONNREFUSED = libc::ECONNREFUSED,
ELOOP = libc::ELOOP,
ENAMETOOLONG = libc::ENAMETOOLONG,
EHOSTDOWN = libc::EHOSTDOWN,
EHOSTUNREACH = libc::EHOSTUNREACH,
ENOTEMPTY = libc::ENOTEMPTY,
EDQUOT = libc::EDQUOT,
ESTALE = libc::ESTALE,
ENOLCK = libc::ENOLCK,
ENOSYS = libc::ENOSYS,
EIDRM = libc::EIDRM,
ENOMSG = libc::ENOMSG,
EOVERFLOW = libc::EOVERFLOW,
ECANCELED = libc::ECANCELED,
EILSEQ = libc::EILSEQ,
ENOATTR = libc::ENOATTR,
EBADMSG = libc::EBADMSG,
EMULTIHOP = libc::EMULTIHOP,
ENOLINK = libc::ENOLINK,
EPROTO = libc::EPROTO,
}

impl Errno {
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
pub const EDEADLOCK: Errno = Errno::EDEADLK;
pub const EOPNOTSUPP: Errno = Errno::ENOTSUP;
}

pub const fn from_i32(e: i32) -> Errno {
use self::Errno::*;

match e {
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
libc::EINTR => EINTR,
libc::EIO => EIO,
libc::ENXIO => ENXIO,
libc::E2BIG => E2BIG,
libc::ENOEXEC => ENOEXEC,
libc::EBADF => EBADF,
libc::ECHILD => ECHILD,
libc::EDEADLK => EDEADLK,
libc::ENOMEM => ENOMEM,
libc::EACCES => EACCES,
libc::EFAULT => EFAULT,
libc::EBUSY => EBUSY,
libc::EEXIST => EEXIST,
libc::EXDEV => EXDEV,
libc::ENODEV => ENODEV,
libc::ENOTDIR => ENOTDIR,
libc::EISDIR => EISDIR,
libc::EINVAL => EINVAL,
libc::ENFILE => ENFILE,
libc::EMFILE => EMFILE,
libc::ENOTTY => ENOTTY,
libc::ETXTBSY => ETXTBSY,
libc::EFBIG => EFBIG,
libc::ENOSPC => ENOSPC,
libc::ESPIPE => ESPIPE,
libc::EROFS => EROFS,
libc::EMLINK => EMLINK,
libc::EPIPE => EPIPE,
libc::EDOM => EDOM,
libc::ERANGE => ERANGE,
libc::EAGAIN => EAGAIN,
libc::EINPROGRESS => EINPROGRESS,
libc::EALREADY => EALREADY,
libc::ENOTSOCK => ENOTSOCK,
libc::EDESTADDRREQ => EDESTADDRREQ,
libc::EMSGSIZE => EMSGSIZE,
libc::EPROTOTYPE => EPROTOTYPE,
libc::ENOPROTOOPT => ENOPROTOOPT,
libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
libc::ENOTSUP => ENOTSUP,
libc::EADDRINUSE => EADDRINUSE,
libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
libc::ENETDOWN => ENETDOWN,
libc::ENETUNREACH => ENETUNREACH,
libc::ENETRESET => ENETRESET,
libc::ECONNABORTED => ECONNABORTED,
libc::ECONNRESET => ECONNRESET,
libc::ENOBUFS => ENOBUFS,
libc::EISCONN => EISCONN,
libc::ENOTCONN => ENOTCONN,
libc::ESHUTDOWN => ESHUTDOWN,
libc::ETIMEDOUT => ETIMEDOUT,
libc::ECONNREFUSED => ECONNREFUSED,
libc::ELOOP => ELOOP,
libc::ENAMETOOLONG => ENAMETOOLONG,
libc::EHOSTDOWN => EHOSTDOWN,
libc::EHOSTUNREACH => EHOSTUNREACH,
libc::ENOTEMPTY => ENOTEMPTY,
libc::EDQUOT => EDQUOT,
libc::ESTALE => ESTALE,
libc::ENOLCK => ENOLCK,
libc::ENOSYS => ENOSYS,
libc::EIDRM => EIDRM,
libc::ENOMSG => ENOMSG,
libc::EOVERFLOW => EOVERFLOW,
libc::ECANCELED => ECANCELED,
libc::EILSEQ => EILSEQ,
libc::ENOATTR => ENOATTR,
libc::EBADMSG => EBADMSG,
libc::EMULTIHOP => EMULTIHOP,
libc::ENOLINK => ENOLINK,
libc::EPROTO => EPROTO,
_ => UnknownErrno,
}
}
}

4 changes: 2 additions & 2 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ libc_bitflags!(
/// Open the file in append-only mode.
O_APPEND;
/// Generate a signal when input or output becomes possible.
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
#[cfg(not(any(target_os = "illumos", target_os = "solaris", target_os = "haiku")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
O_ASYNC;
/// Closes the file descriptor once an `execve` call is made.
Expand Down Expand Up @@ -128,7 +128,7 @@ libc_bitflags!(
#[cfg_attr(docsrs, doc(cfg(all())))]
O_NOCTTY;
/// Same as `O_NONBLOCK`.
#[cfg(not(target_os = "redox"))]
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
O_NDELAY;
/// `open()` will fail if the given path is a symbolic link.
Expand Down
Loading

0 comments on commit 55333e4

Please sign in to comment.