Skip to content

Commit

Permalink
Solaris: fixes build and tests, adds CI (#2544)
Browse files Browse the repository at this point in the history
Disables some tests for Solaris.

test/test_sendfile.rs:

Solaris, sendfilev() doesn't support AF_UNIX sockets.
Instead, it expects an AF_INET or AF_INET6 sockets.

test/sys/test_timer.rs:

Note that sys::test_timer::alarm_fires can fail as timer_create(3C) function
requires the PRIV_PROC_CLOCK_HIGHRES. But since tests are supposed to run
with sudo it should be ok.
  • Loading branch information
psumbera authored Nov 30, 2024
1 parent 7153ba1 commit 0f45593
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 17 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,27 @@ jobs:
- name: before_cache_script
run: rm -rf $CARGO_HOME/registry/index

solaris:
name: solaris (x86_64-pc-solaris)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: build and test
uses: vmactions/solaris-vm@v1
with:
release: "11.4-gcc"
usesh: true
mem: 4096
copyback: false
prepare: |
source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install)
echo "~~~~ rustc --version ~~~~"
rustc --version
echo "~~~~ Solaris-version ~~~~"
uname -a
run: |
export PATH=$HOME/.rust_solaris/bin:$PATH
cargo build --target x86_64-pc-solaris --all-targets --all-features && sudo cargo test
# Test that we can build with the lowest version of all dependencies.
# "cargo test" doesn't work because some of our dev-dependencies, like
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ targets = [
]

[dependencies]
libc = { version = "0.2.164", features = ["extra_traits"] }
libc = { version = "0.2.166", features = ["extra_traits"] }
bitflags = "2.3.3"
cfg-if = "1.0"
pin-utils = { version = "0.1.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use libc::{dirent, readdir_r};
/// let mut cwd = Dir::open(".", OFlag::O_RDONLY | OFlag::O_CLOEXEC, Mode::empty()).unwrap();
/// for res_entry in cwd.iter() {
/// let entry = res_entry.unwrap();
/// println!("File name: {}", entry.file_name().to_str().unwrap());
/// println!("File name: {}", entry.file_name().to_string_lossy());
/// }
/// ```
#[derive(Debug, Eq, Hash, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::ffi::OsString;
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
use std::ops::{Deref, DerefMut};
use std::os::unix::ffi::OsStringExt;
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
#[cfg(not(target_os = "redox"))]
use std::os::unix::io::OwnedFd;
use std::os::unix::io::RawFd;
#[cfg(any(
Expand Down Expand Up @@ -141,7 +141,7 @@ libc_bitflags!(
#[cfg(any(
freebsdlike,
linux_android,
solarish,
target_os = "illumos",
target_os = "netbsd"
))]
O_DIRECT;
Expand Down
1 change: 1 addition & 0 deletions src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ libc_bitflags! {
/// Additional parameters for [`mmap`].
pub struct MapFlags: c_int {
/// Compatibility flag. Ignored.
#[cfg(not(target_os = "solaris"))]
MAP_FILE;
/// Share this mapping. Mutually exclusive with `MAP_PRIVATE`.
MAP_SHARED;
Expand Down
20 changes: 16 additions & 4 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ libc_enum! {
SIGEMT,
#[cfg(not(any(linux_android, target_os = "emscripten",
target_os = "fuchsia", target_os = "redox",
target_os = "haiku", target_os = "aix")))]
target_os = "haiku", target_os = "aix",
target_os = "solaris")))]
/// Information request
SIGINFO,
}
Expand Down Expand Up @@ -188,7 +189,8 @@ impl FromStr for Signal {
target_os = "fuchsia",
target_os = "redox",
target_os = "aix",
target_os = "haiku"
target_os = "haiku",
target_os = "solaris"
)))]
"SIGINFO" => Signal::SIGINFO,
_ => return Err(Errno::EINVAL),
Expand Down Expand Up @@ -272,7 +274,8 @@ impl Signal {
target_os = "fuchsia",
target_os = "redox",
target_os = "aix",
target_os = "haiku"
target_os = "haiku",
target_os = "solaris"
)))]
Signal::SIGINFO => "SIGINFO",
}
Expand Down Expand Up @@ -356,13 +359,22 @@ const SIGNALS: [Signal; 30] = [
SIGURG, SIGPOLL, SIGIO, SIGSTOP, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU,
SIGVTALRM, SIGPROF, SIGXCPU, SIGXFSZ, SIGTRAP,
];
#[cfg(target_os = "solaris")]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 30] = [
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT,
SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM,
SIGPROF, SIGWINCH, SIGIO, SIGSYS, SIGEMT,
];
#[cfg(not(any(
linux_android,
target_os = "fuchsia",
target_os = "emscripten",
target_os = "aix",
target_os = "redox",
target_os = "haiku"
target_os = "haiku",
target_os = "solaris"
)))]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
Expand Down
2 changes: 2 additions & 0 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,7 @@ impl ControlMessage<'_> {
/// sendmsg::<()>(fd1.as_raw_fd(), &iov, &[cmsg], MsgFlags::empty(), None).unwrap();
/// ```
/// When directing to a specific address, the generic type will be inferred.
/// Note that SCM_RIGHTS ancillary data are valid only for AF_UNIX sockets on Solaris.
/// ```
/// # use nix::sys::socket::*;
/// # use nix::unistd::pipe;
Expand All @@ -1684,6 +1685,7 @@ impl ControlMessage<'_> {
/// let iov = [IoSlice::new(b"hello")];
/// let fds = [r.as_raw_fd()];
/// let cmsg = ControlMessage::ScmRights(&fds);
/// #[cfg(not(target_os = "solaris"))]
/// sendmsg(fd.as_raw_fd(), &iov, &[cmsg], MsgFlags::empty(), Some(&localhost)).unwrap();
/// ```
pub fn sendmsg<S>(fd: RawFd, iov: &[IoSlice<'_>], cmsgs: &[ControlMessage],
Expand Down
6 changes: 3 additions & 3 deletions src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ libc_enum! {
VEOL,
VEOL2,
VERASE,
#[cfg(any(freebsdlike, solarish))]
#[cfg(any(freebsdlike, target_os = "illumos"))]
VERASE2,
VINTR,
VKILL,
Expand All @@ -431,7 +431,7 @@ libc_enum! {
#[cfg(not(target_os = "haiku"))]
VREPRINT,
VSTART,
#[cfg(any(bsd, solarish))]
#[cfg(any(bsd, target_os = "illumos"))]
VSTATUS,
VSTOP,
VSUSP,
Expand Down Expand Up @@ -461,7 +461,7 @@ impl SpecialCharacterIndices {
}

pub use libc::NCCS;
#[cfg(any(linux_android, target_os = "aix", bsd))]
#[cfg(any(bsd, linux_android, target_os = "aix", target_os = "solaris"))]
pub use libc::_POSIX_VDISABLE;

libc_bitflags! {
Expand Down
2 changes: 1 addition & 1 deletion src/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ libc_bitflags! {
/// which file descriptors are allocated.
LOG_NDELAY;
/// Write the message to standard error output as well to the system log.
#[cfg(not(any(target_os = "redox", target_os = "illumos")))]
#[cfg(not(any(solarish, target_os = "redox")))]
LOG_PERROR;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,9 @@ pub mod alarm {
//! sigset.add(Signal::SIGALRM);
//! sigset.wait();
//!
//! assert!(start.elapsed() >= Duration::from_secs(1));
//! // On Solaris, the signal can arrive before the full second.
//! const TOLERANCE: Duration = Duration::from_millis(10);
//! assert!(start.elapsed() + TOLERANCE >= Duration::from_secs(1));
//! ```
//!
//! # References
Expand Down
3 changes: 2 additions & 1 deletion test/sys/test_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ fn test_mkdirat_fail() {
freebsdlike,
apple_targets,
target_os = "haiku",
target_os = "redox"
target_os = "redox",
target_os = "solaris"
)))]
fn test_mknod() {
use stat::{lstat, mknod, SFlag};
Expand Down
1 change: 1 addition & 0 deletions test/sys/test_termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn test_output_flags() {

// Test modifying local flags
#[test]
#[cfg(not(target_os = "solaris"))]
fn test_local_flags() {
// openpty uses ptname(3) internally
let _m = crate::PTSNAME_MTX.lock();
Expand Down
1 change: 1 addition & 0 deletions test/test_pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ fn make_raw<Fd: AsFd>(fd: Fd) {

/// Test `io::Read` on the PTTY master
#[test]
#[cfg(not(target_os = "solaris"))]
fn test_read_ptty_pair() {
let (mut master, mut slave) = open_ptty_pair();
make_raw(&slave);
Expand Down
13 changes: 10 additions & 3 deletions test/test_sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use tempfile::tempfile;
cfg_if! {
if #[cfg(linux_android)] {
use nix::unistd::{pipe, read};
} else if #[cfg(any(freebsdlike, apple_targets, solarish))] {
} else if #[cfg(any(freebsdlike, apple_targets))] {
use std::net::Shutdown;
use std::os::unix::net::UnixStream;
} else if #[cfg(solarish)] {
use std::net::Shutdown;
use std::net::{TcpListener, TcpStream};
}
}

Expand Down Expand Up @@ -222,7 +225,11 @@ fn test_sendfilev() {
trailer_data
.write_all(trailer_strings.concat().as_bytes())
.unwrap();
let (mut rd, wr) = UnixStream::pair().unwrap();
// Create a TCP socket pair (listener and client)
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();
let mut rd = TcpStream::connect(addr).unwrap();
let (wr, _) = listener.accept().unwrap();
let vec: &[SendfileVec] = &[
SendfileVec::new(
header_data.as_fd(),
Expand All @@ -243,7 +250,7 @@ fn test_sendfilev() {

let (res, bytes_written) = sendfilev(&wr, vec);
assert!(res.is_ok());
wr.shutdown(Shutdown::Both).unwrap();
wr.shutdown(Shutdown::Write).unwrap();

// Prepare the expected result
let expected_string = header_strings.concat()
Expand Down

0 comments on commit 0f45593

Please sign in to comment.