Skip to content

Commit 0f45593

Browse files
authored
Solaris: fixes build and tests, adds CI (#2544)
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.
1 parent 7153ba1 commit 0f45593

File tree

14 files changed

+65
-17
lines changed

14 files changed

+65
-17
lines changed

.github/workflows/ci.yml

+21
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,27 @@ jobs:
328328
- name: before_cache_script
329329
run: rm -rf $CARGO_HOME/registry/index
330330

331+
solaris:
332+
name: solaris (x86_64-pc-solaris)
333+
runs-on: ubuntu-latest
334+
steps:
335+
- uses: actions/checkout@v4
336+
- name: build and test
337+
uses: vmactions/solaris-vm@v1
338+
with:
339+
release: "11.4-gcc"
340+
usesh: true
341+
mem: 4096
342+
copyback: false
343+
prepare: |
344+
source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install)
345+
echo "~~~~ rustc --version ~~~~"
346+
rustc --version
347+
echo "~~~~ Solaris-version ~~~~"
348+
uname -a
349+
run: |
350+
export PATH=$HOME/.rust_solaris/bin:$PATH
351+
cargo build --target x86_64-pc-solaris --all-targets --all-features && sudo cargo test
331352
332353
# Test that we can build with the lowest version of all dependencies.
333354
# "cargo test" doesn't work because some of our dev-dependencies, like

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ targets = [
2828
]
2929

3030
[dependencies]
31-
libc = { version = "0.2.164", features = ["extra_traits"] }
31+
libc = { version = "0.2.166", features = ["extra_traits"] }
3232
bitflags = "2.3.3"
3333
cfg-if = "1.0"
3434
pin-utils = { version = "0.1.0", optional = true }

src/dir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use libc::{dirent, readdir_r};
4646
/// let mut cwd = Dir::open(".", OFlag::O_RDONLY | OFlag::O_CLOEXEC, Mode::empty()).unwrap();
4747
/// for res_entry in cwd.iter() {
4848
/// let entry = res_entry.unwrap();
49-
/// println!("File name: {}", entry.file_name().to_str().unwrap());
49+
/// println!("File name: {}", entry.file_name().to_string_lossy());
5050
/// }
5151
/// ```
5252
#[derive(Debug, Eq, Hash, PartialEq)]

src/fcntl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::ffi::OsString;
1414
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
1515
use std::ops::{Deref, DerefMut};
1616
use std::os::unix::ffi::OsStringExt;
17-
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
17+
#[cfg(not(target_os = "redox"))]
1818
use std::os::unix::io::OwnedFd;
1919
use std::os::unix::io::RawFd;
2020
#[cfg(any(
@@ -141,7 +141,7 @@ libc_bitflags!(
141141
#[cfg(any(
142142
freebsdlike,
143143
linux_android,
144-
solarish,
144+
target_os = "illumos",
145145
target_os = "netbsd"
146146
))]
147147
O_DIRECT;

src/sys/mman.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ libc_bitflags! {
3838
/// Additional parameters for [`mmap`].
3939
pub struct MapFlags: c_int {
4040
/// Compatibility flag. Ignored.
41+
#[cfg(not(target_os = "solaris"))]
4142
MAP_FILE;
4243
/// Share this mapping. Mutually exclusive with `MAP_PRIVATE`.
4344
MAP_SHARED;

src/sys/signal.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ libc_enum! {
110110
SIGEMT,
111111
#[cfg(not(any(linux_android, target_os = "emscripten",
112112
target_os = "fuchsia", target_os = "redox",
113-
target_os = "haiku", target_os = "aix")))]
113+
target_os = "haiku", target_os = "aix",
114+
target_os = "solaris")))]
114115
/// Information request
115116
SIGINFO,
116117
}
@@ -188,7 +189,8 @@ impl FromStr for Signal {
188189
target_os = "fuchsia",
189190
target_os = "redox",
190191
target_os = "aix",
191-
target_os = "haiku"
192+
target_os = "haiku",
193+
target_os = "solaris"
192194
)))]
193195
"SIGINFO" => Signal::SIGINFO,
194196
_ => return Err(Errno::EINVAL),
@@ -272,7 +274,8 @@ impl Signal {
272274
target_os = "fuchsia",
273275
target_os = "redox",
274276
target_os = "aix",
275-
target_os = "haiku"
277+
target_os = "haiku",
278+
target_os = "solaris"
276279
)))]
277280
Signal::SIGINFO => "SIGINFO",
278281
}
@@ -356,13 +359,22 @@ const SIGNALS: [Signal; 30] = [
356359
SIGURG, SIGPOLL, SIGIO, SIGSTOP, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU,
357360
SIGVTALRM, SIGPROF, SIGXCPU, SIGXFSZ, SIGTRAP,
358361
];
362+
#[cfg(target_os = "solaris")]
363+
#[cfg(feature = "signal")]
364+
const SIGNALS: [Signal; 30] = [
365+
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
366+
SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT,
367+
SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM,
368+
SIGPROF, SIGWINCH, SIGIO, SIGSYS, SIGEMT,
369+
];
359370
#[cfg(not(any(
360371
linux_android,
361372
target_os = "fuchsia",
362373
target_os = "emscripten",
363374
target_os = "aix",
364375
target_os = "redox",
365-
target_os = "haiku"
376+
target_os = "haiku",
377+
target_os = "solaris"
366378
)))]
367379
#[cfg(feature = "signal")]
368380
const SIGNALS: [Signal; 31] = [

src/sys/socket/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,7 @@ impl ControlMessage<'_> {
16701670
/// sendmsg::<()>(fd1.as_raw_fd(), &iov, &[cmsg], MsgFlags::empty(), None).unwrap();
16711671
/// ```
16721672
/// When directing to a specific address, the generic type will be inferred.
1673+
/// Note that SCM_RIGHTS ancillary data are valid only for AF_UNIX sockets on Solaris.
16731674
/// ```
16741675
/// # use nix::sys::socket::*;
16751676
/// # use nix::unistd::pipe;
@@ -1684,6 +1685,7 @@ impl ControlMessage<'_> {
16841685
/// let iov = [IoSlice::new(b"hello")];
16851686
/// let fds = [r.as_raw_fd()];
16861687
/// let cmsg = ControlMessage::ScmRights(&fds);
1688+
/// #[cfg(not(target_os = "solaris"))]
16871689
/// sendmsg(fd.as_raw_fd(), &iov, &[cmsg], MsgFlags::empty(), Some(&localhost)).unwrap();
16881690
/// ```
16891691
pub fn sendmsg<S>(fd: RawFd, iov: &[IoSlice<'_>], cmsgs: &[ControlMessage],

src/sys/termios.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ libc_enum! {
418418
VEOL,
419419
VEOL2,
420420
VERASE,
421-
#[cfg(any(freebsdlike, solarish))]
421+
#[cfg(any(freebsdlike, target_os = "illumos"))]
422422
VERASE2,
423423
VINTR,
424424
VKILL,
@@ -431,7 +431,7 @@ libc_enum! {
431431
#[cfg(not(target_os = "haiku"))]
432432
VREPRINT,
433433
VSTART,
434-
#[cfg(any(bsd, solarish))]
434+
#[cfg(any(bsd, target_os = "illumos"))]
435435
VSTATUS,
436436
VSTOP,
437437
VSUSP,
@@ -461,7 +461,7 @@ impl SpecialCharacterIndices {
461461
}
462462

463463
pub use libc::NCCS;
464-
#[cfg(any(linux_android, target_os = "aix", bsd))]
464+
#[cfg(any(bsd, linux_android, target_os = "aix", target_os = "solaris"))]
465465
pub use libc::_POSIX_VDISABLE;
466466

467467
libc_bitflags! {

src/syslog.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ libc_bitflags! {
138138
/// which file descriptors are allocated.
139139
LOG_NDELAY;
140140
/// Write the message to standard error output as well to the system log.
141-
#[cfg(not(any(target_os = "redox", target_os = "illumos")))]
141+
#[cfg(not(any(solarish, target_os = "redox")))]
142142
LOG_PERROR;
143143
}
144144
}

src/unistd.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,9 @@ pub mod alarm {
21572157
//! sigset.add(Signal::SIGALRM);
21582158
//! sigset.wait();
21592159
//!
2160-
//! assert!(start.elapsed() >= Duration::from_secs(1));
2160+
//! // On Solaris, the signal can arrive before the full second.
2161+
//! const TOLERANCE: Duration = Duration::from_millis(10);
2162+
//! assert!(start.elapsed() + TOLERANCE >= Duration::from_secs(1));
21612163
//! ```
21622164
//!
21632165
//! # References

test/sys/test_stat.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ fn test_mkdirat_fail() {
368368
freebsdlike,
369369
apple_targets,
370370
target_os = "haiku",
371-
target_os = "redox"
371+
target_os = "redox",
372+
target_os = "solaris"
372373
)))]
373374
fn test_mknod() {
374375
use stat::{lstat, mknod, SFlag};

test/sys/test_termios.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ fn test_output_flags() {
8080

8181
// Test modifying local flags
8282
#[test]
83+
#[cfg(not(target_os = "solaris"))]
8384
fn test_local_flags() {
8485
// openpty uses ptname(3) internally
8586
let _m = crate::PTSNAME_MTX.lock();

test/test_pty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ fn make_raw<Fd: AsFd>(fd: Fd) {
148148

149149
/// Test `io::Read` on the PTTY master
150150
#[test]
151+
#[cfg(not(target_os = "solaris"))]
151152
fn test_read_ptty_pair() {
152153
let (mut master, mut slave) = open_ptty_pair();
153154
make_raw(&slave);

test/test_sendfile.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ use tempfile::tempfile;
77
cfg_if! {
88
if #[cfg(linux_android)] {
99
use nix::unistd::{pipe, read};
10-
} else if #[cfg(any(freebsdlike, apple_targets, solarish))] {
10+
} else if #[cfg(any(freebsdlike, apple_targets))] {
1111
use std::net::Shutdown;
1212
use std::os::unix::net::UnixStream;
13+
} else if #[cfg(solarish)] {
14+
use std::net::Shutdown;
15+
use std::net::{TcpListener, TcpStream};
1316
}
1417
}
1518

@@ -222,7 +225,11 @@ fn test_sendfilev() {
222225
trailer_data
223226
.write_all(trailer_strings.concat().as_bytes())
224227
.unwrap();
225-
let (mut rd, wr) = UnixStream::pair().unwrap();
228+
// Create a TCP socket pair (listener and client)
229+
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
230+
let addr = listener.local_addr().unwrap();
231+
let mut rd = TcpStream::connect(addr).unwrap();
232+
let (wr, _) = listener.accept().unwrap();
226233
let vec: &[SendfileVec] = &[
227234
SendfileVec::new(
228235
header_data.as_fd(),
@@ -243,7 +250,7 @@ fn test_sendfilev() {
243250

244251
let (res, bytes_written) = sendfilev(&wr, vec);
245252
assert!(res.is_ok());
246-
wr.shutdown(Shutdown::Both).unwrap();
253+
wr.shutdown(Shutdown::Write).unwrap();
247254

248255
// Prepare the expected result
249256
let expected_string = header_strings.concat()

0 commit comments

Comments
 (0)