Skip to content

Commit 810b8c6

Browse files
committed
Auto merge of #1251 - jasonbking:solarish-sq, r=gnzlbg
Add support for illumos target This change adds support for an illumos os target to libc. Similar to the BSDs, there is a large deal of overlap (given the common history), so the 'solaris' directory was renamed to 'solarish' (it's the closest thing to an official term to refer to things descending from Solaris as well as Solaris). There were also a number of missing definitions (as well as a couple missing functions) that have proved necessary for building a number of rust programs on illumos or Solaris. Portions contributed by @papertigers .
2 parents d6977c8 + 821fd8a commit 810b8c6

File tree

4 files changed

+371
-26
lines changed

4 files changed

+371
-26
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ matrix:
2626
install: rustup component add rustfmt-preview
2727
script:
2828
- rustc ci/style.rs && ./style src
29-
- cargo fmt --all -- --check
29+
# Disabled due to rust-lang/rustfmt#3341
30+
# - cargo fmt --all -- --check
3031
stage: tools-and-build-and-tier1
3132

3233
# BUILD stable, beta, nightly

src/unix/mod.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ cfg_if! {
349349
// to "pthread" needs to be added.
350350
#[link(name = "pthread")]
351351
extern {}
352+
} else if #[cfg(target_env = "illumos")] {
353+
#[link(name = "c")]
354+
#[link(name = "m")]
355+
extern {}
352356
} else {
353357
#[link(name = "c")]
354358
#[link(name = "m")]
@@ -519,13 +523,16 @@ extern {
519523
pub fn putchar_unlocked(c: ::c_int) -> ::c_int;
520524

521525
#[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
526+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")]
522527
pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int;
523528
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
524529
link_name = "connect$UNIX2003")]
530+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_connect")]
525531
pub fn connect(socket: ::c_int, address: *const sockaddr,
526532
len: socklen_t) -> ::c_int;
527533
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
528534
link_name = "listen$UNIX2003")]
535+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")]
529536
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
530537
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
531538
link_name = "accept$UNIX2003")]
@@ -544,10 +551,12 @@ extern {
544551
option_len: socklen_t) -> ::c_int;
545552
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
546553
link_name = "socketpair$UNIX2003")]
554+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")]
547555
pub fn socketpair(domain: ::c_int, type_: ::c_int, protocol: ::c_int,
548556
socket_vector: *mut ::c_int) -> ::c_int;
549557
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
550558
link_name = "sendto$UNIX2003")]
559+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_sendto")]
551560
pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
552561
flags: ::c_int, addr: *const sockaddr,
553562
addrlen: socklen_t) -> ::ssize_t;
@@ -607,7 +616,8 @@ extern {
607616
pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent;
608617
#[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
609618
#[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
610-
#[cfg_attr(target_os = "solaris", link_name = "__posix_readdir_r")]
619+
#[cfg_attr(any(target_os = "solaris", target_os = "illumos"),
620+
link_name = "__posix_readdir_r")]
611621
#[cfg_attr(target_os = "freebsd", link_name = "readdir_r@FBSD_1.0")]
612622
pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
613623
result: *mut *mut ::dirent) -> ::c_int;
@@ -916,6 +926,7 @@ extern {
916926
pub fn strerror_r(errnum: ::c_int, buf: *mut c_char,
917927
buflen: ::size_t) -> ::c_int;
918928

929+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_getsockopt")]
919930
pub fn getsockopt(sockfd: ::c_int,
920931
level: ::c_int,
921932
optname: ::c_int,
@@ -1080,10 +1091,8 @@ extern {
10801091
pub fn tcdrain(fd: ::c_int) -> ::c_int;
10811092
pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t;
10821093
pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t;
1083-
pub fn cfmakeraw(termios: *mut ::termios);
10841094
pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
10851095
pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
1086-
pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
10871096
pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
10881097
pub fn tcsetattr(fd: ::c_int,
10891098
optional_actions: ::c_int,
@@ -1116,6 +1125,16 @@ extern {
11161125
stream: *mut FILE) -> ssize_t;
11171126
}
11181127

1128+
cfg_if! {
1129+
if #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] {
1130+
extern {
1131+
pub fn cfmakeraw(termios: *mut ::termios);
1132+
pub fn cfsetspeed(termios: *mut ::termios,
1133+
speed: ::speed_t) -> ::c_int;
1134+
}
1135+
}
1136+
}
1137+
11191138
cfg_if! {
11201139
if #[cfg(target_env = "uclibc")] {
11211140
mod uclibc;
@@ -1137,9 +1156,10 @@ cfg_if! {
11371156
target_os = "bitrig"))] {
11381157
mod bsd;
11391158
pub use self::bsd::*;
1140-
} else if #[cfg(target_os = "solaris")] {
1141-
mod solaris;
1142-
pub use self::solaris::*;
1159+
} else if #[cfg(any(target_os = "solaris",
1160+
target_os = "illumos"))] {
1161+
mod solarish;
1162+
pub use self::solarish::*;
11431163
} else if #[cfg(target_os = "haiku")] {
11441164
mod haiku;
11451165
pub use self::haiku::*;

src/unix/solarish/compat.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Common functions that are unfortunately missing on illumos and
2+
// Solaris, but often needed by other crates.
3+
4+
use unix::solarish::*;
5+
6+
pub unsafe fn cfmakeraw(termios: *mut ::termios) {
7+
let mut t = *termios as ::termios;
8+
t.c_iflag &= !(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
9+
t.c_oflag &= !OPOST;
10+
t.c_lflag &= !(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
11+
t.c_cflag &= !(CSIZE|PARENB);
12+
t.c_cflag |= CS8;
13+
}
14+
15+
pub unsafe fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int {
16+
// Neither of these functions on illumos or Solaris actually ever
17+
// return an error
18+
::cfsetispeed(termios, speed);
19+
::cfsetospeed(termios, speed);
20+
0
21+
}

0 commit comments

Comments
 (0)