Skip to content

Add support for illumos target #1251

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 4 commits into from
Feb 12, 2019
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ matrix:
install: rustup component add rustfmt-preview
script:
- rustc ci/style.rs && ./style src
- cargo fmt --all -- --check
# Disabled due to rust-lang/rustfmt#3341
# - cargo fmt --all -- --check
stage: tools-and-build-and-tier1

# BUILD stable, beta, nightly
Expand Down
32 changes: 26 additions & 6 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ cfg_if! {
// to "pthread" needs to be added.
#[link(name = "pthread")]
extern {}
} else if #[cfg(target_env = "illumos")] {
#[link(name = "c")]
#[link(name = "m")]
extern {}
} else {
#[link(name = "c")]
#[link(name = "m")]
Expand Down Expand Up @@ -519,13 +523,16 @@ extern {
pub fn putchar_unlocked(c: ::c_int) -> ::c_int;

#[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_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "connect$UNIX2003")]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_connect")]
pub fn connect(socket: ::c_int, address: *const sockaddr,
len: socklen_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "listen$UNIX2003")]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")]
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "accept$UNIX2003")]
Expand All @@ -544,10 +551,12 @@ extern {
option_len: socklen_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "socketpair$UNIX2003")]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")]
pub fn socketpair(domain: ::c_int, type_: ::c_int, protocol: ::c_int,
socket_vector: *mut ::c_int) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "sendto$UNIX2003")]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_sendto")]
pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
flags: ::c_int, addr: *const sockaddr,
addrlen: socklen_t) -> ::ssize_t;
Expand Down Expand Up @@ -607,7 +616,8 @@ extern {
pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent;
#[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
#[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
#[cfg_attr(target_os = "solaris", link_name = "__posix_readdir_r")]
#[cfg_attr(any(target_os = "solaris", target_os = "illumos"),
link_name = "__posix_readdir_r")]
#[cfg_attr(target_os = "freebsd", link_name = "readdir_r@FBSD_1.0")]
pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
result: *mut *mut ::dirent) -> ::c_int;
Expand Down Expand Up @@ -916,6 +926,7 @@ extern {
pub fn strerror_r(errnum: ::c_int, buf: *mut c_char,
buflen: ::size_t) -> ::c_int;

#[cfg_attr(target_os = "illumos", link_name = "__xnet_getsockopt")]
pub fn getsockopt(sockfd: ::c_int,
level: ::c_int,
optname: ::c_int,
Expand Down Expand Up @@ -1080,10 +1091,8 @@ extern {
pub fn tcdrain(fd: ::c_int) -> ::c_int;
pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t;
pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t;
pub fn cfmakeraw(termios: *mut ::termios);
pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
pub fn tcsetattr(fd: ::c_int,
optional_actions: ::c_int,
Expand Down Expand Up @@ -1116,6 +1125,16 @@ extern {
stream: *mut FILE) -> ssize_t;
}

cfg_if! {
if #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] {
extern {
pub fn cfmakeraw(termios: *mut ::termios);
pub fn cfsetspeed(termios: *mut ::termios,
speed: ::speed_t) -> ::c_int;
}
}
}

cfg_if! {
if #[cfg(target_env = "uclibc")] {
mod uclibc;
Expand All @@ -1137,9 +1156,10 @@ cfg_if! {
target_os = "bitrig"))] {
mod bsd;
pub use self::bsd::*;
} else if #[cfg(target_os = "solaris")] {
mod solaris;
pub use self::solaris::*;
} else if #[cfg(any(target_os = "solaris",
target_os = "illumos"))] {
mod solarish;
pub use self::solarish::*;
} else if #[cfg(target_os = "haiku")] {
mod haiku;
pub use self::haiku::*;
Expand Down
21 changes: 21 additions & 0 deletions src/unix/solarish/compat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Common functions that are unfortunately missing on illumos and
// Solaris, but often needed by other crates.

use unix::solarish::*;

pub unsafe fn cfmakeraw(termios: *mut ::termios) {
let mut t = *termios as ::termios;
t.c_iflag &= !(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
t.c_oflag &= !OPOST;
t.c_lflag &= !(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
t.c_cflag &= !(CSIZE|PARENB);
t.c_cflag |= CS8;
}

pub unsafe fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int {
// Neither of these functions on illumos or Solaris actually ever
// return an error
::cfsetispeed(termios, speed);
::cfsetospeed(termios, speed);
0
}
Loading