Skip to content

Fix build, sockopts and examples for cygwin #1428

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 1 commit into from
Apr 1, 2025
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
47 changes: 39 additions & 8 deletions examples/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,55 @@ fn main() -> rustix::io::Result<()> {
println!("Stack Limit: {:?}", getrlimit(Resource::Stack));
#[cfg(not(target_os = "haiku"))]
println!("Core Limit: {:?}", getrlimit(Resource::Core));
#[cfg(not(any(solarish, target_os = "haiku")))]
#[cfg(not(any(solarish, target_os = "haiku", target_os = "cygwin")))]
println!("Rss Limit: {:?}", getrlimit(Resource::Rss));
#[cfg(not(any(solarish, target_os = "haiku")))]
#[cfg(not(any(solarish, target_os = "haiku", target_os = "cygwin")))]
println!("Nproc Limit: {:?}", getrlimit(Resource::Nproc));
#[cfg(not(target_os = "solaris"))]
println!("Nofile Limit: {:?}", getrlimit(Resource::Nofile));
#[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
#[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "cygwin")))]
println!("Memlock Limit: {:?}", getrlimit(Resource::Memlock));
#[cfg(not(target_os = "openbsd"))]
println!("As Limit: {:?}", getrlimit(Resource::As));
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
#[cfg(not(any(
bsd,
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "cygwin",
)))]
println!("Locks Limit: {:?}", getrlimit(Resource::Locks));
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
#[cfg(not(any(
bsd,
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "cygwin",
)))]
println!("Sigpending Limit: {:?}", getrlimit(Resource::Sigpending));
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
#[cfg(not(any(
bsd,
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "cygwin",
)))]
println!("Msgqueue Limit: {:?}", getrlimit(Resource::Msgqueue));
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
#[cfg(not(any(
bsd,
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "cygwin",
)))]
println!("Nice Limit: {:?}", getrlimit(Resource::Nice));
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
#[cfg(not(any(
bsd,
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "cygwin",
)))]
println!("Rtprio Limit: {:?}", getrlimit(Resource::Rtprio));
#[cfg(not(any(
bsd,
Expand All @@ -77,6 +107,7 @@ fn main() -> rustix::io::Result<()> {
target_os = "android",
target_os = "emscripten",
target_os = "haiku",
target_os = "cygwin",
)))]
println!("Rttime Limit: {:?}", getrlimit(Resource::Rttime));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
if term.local_modes.contains(LocalModes::ECHOCTL) {
print!(" ECHOCTL");
}
#[cfg(not(any(target_os = "redox")))]
#[cfg(not(any(target_os = "redox", target_os = "cygwin")))]
if term.local_modes.contains(LocalModes::ECHOPRT) {
print!(" ECHOPRT");
}
Expand All @@ -276,7 +276,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
if term.local_modes.contains(LocalModes::TOSTOP) {
print!(" TOSTOP");
}
#[cfg(not(any(target_os = "redox")))]
#[cfg(not(any(target_os = "redox", target_os = "cygwin")))]
if term.local_modes.contains(LocalModes::PENDIN) {
print!(" PENDIN");
}
Expand Down
20 changes: 16 additions & 4 deletions src/backend/libc/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,13 @@ pub(crate) fn ipv6_v6only(fd: BorrowedFd<'_>) -> io::Result<bool> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_V6ONLY).map(to_bool)
}

#[cfg(linux_kernel)]
#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[inline]
pub(crate) fn ip_mtu(fd: BorrowedFd<'_>) -> io::Result<u32> {
getsockopt(fd, c::IPPROTO_IP, c::IP_MTU)
}

#[cfg(linux_kernel)]
#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[inline]
pub(crate) fn ipv6_mtu(fd: BorrowedFd<'_>) -> io::Result<u32> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_MTU)
Expand Down Expand Up @@ -767,13 +767,25 @@ pub(crate) fn ip_tos(fd: BorrowedFd<'_>) -> io::Result<u8> {
Ok(value as u8)
}

#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
#[cfg(any(
apple,
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "cygwin",
))]
#[inline]
pub(crate) fn set_ip_recvtos(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS, from_bool(value))
}

#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
#[cfg(any(
apple,
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "cygwin",
))]
#[inline]
pub(crate) fn ip_recvtos(fd: BorrowedFd<'_>) -> io::Result<bool> {
getsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS).map(to_bool)
Expand Down
20 changes: 16 additions & 4 deletions src/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ pub fn ipv6_v6only<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
///
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[inline]
#[cfg(linux_kernel)]
#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[doc(alias = "IP_MTU")]
pub fn ip_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ip_mtu(fd.as_fd())
Expand All @@ -680,7 +680,7 @@ pub fn ip_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
///
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[inline]
#[cfg(linux_kernel)]
#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[doc(alias = "IPV6_MTU")]
pub fn ipv6_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ipv6_mtu(fd.as_fd())
Expand Down Expand Up @@ -1088,7 +1088,13 @@ pub fn ip_tos<Fd: AsFd>(fd: Fd) -> io::Result<u8> {
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
#[cfg(any(
apple,
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "cygwin",
))]
#[inline]
#[doc(alias = "IP_RECVTOS")]
pub fn set_ip_recvtos<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
Expand All @@ -1100,7 +1106,13 @@ pub fn set_ip_recvtos<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
#[cfg(any(
apple,
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "cygwin",
))]
#[inline]
#[doc(alias = "IP_RECVTOS")]
pub fn ip_recvtos<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
Expand Down
1 change: 1 addition & 0 deletions src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ impl Signal {
target_os = "hurd",
target_os = "nto",
target_os = "vita",
target_os = "cygwin",
all(
linux_kernel,
any(
Expand Down
3 changes: 2 additions & 1 deletion src/termios/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,8 @@ mod tests {
solarish,
target_os = "emscripten",
target_os = "haiku",
target_os = "redox"
target_os = "redox",
target_os = "cygwin",
)))]
fn termios_legacy() {
// Check that our doc aliases above are correct.
Expand Down
2 changes: 1 addition & 1 deletion tests/io/ioctl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// `ioctl_fionread` on Windows doesn't work on files.
#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "cygwin")))]
#[test]
fn test_ioctls() {
let file = std::fs::File::open("Cargo.toml").unwrap();
Expand Down
1 change: 1 addition & 0 deletions tests/io/read_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ fn test_preadv2_nowait() {
#[cfg(not(target_os = "espidf"))] // no preadv/pwritev
#[cfg(not(target_os = "solaris"))] // no preadv/pwritev
#[cfg(not(target_os = "haiku"))] // no preadv/pwritev
#[cfg(not(target_os = "cygwin"))] // no preadv/pwritev
#[test]
fn test_p_offsets() {
use rustix::fs::{openat, Mode, OFlags, CWD};
Expand Down
14 changes: 11 additions & 3 deletions tests/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn test_sockopts_socket(s: &OwnedFd) {
assert!(sockopt::socket_oobinline(s).unwrap());

// Check the initial value of `SO_REUSEPORT`, set it, and check it.
#[cfg(not(any(solarish, windows)))]
#[cfg(not(any(solarish, windows, target_os = "cygwin")))]
{
assert!(!sockopt::socket_reuseport(s).unwrap());
sockopt::set_socket_reuseport(s, true).unwrap();
Expand Down Expand Up @@ -320,6 +320,7 @@ fn test_sockopts_ipv4() {
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
target_os = "cygwin",
)))]
assert_eq!(sockopt::socket_domain(&s).unwrap(), AddressFamily::INET);
assert_ne!(sockopt::ip_ttl(&s).unwrap(), 0);
Expand Down Expand Up @@ -365,7 +366,13 @@ fn test_sockopts_ipv4() {
}

// Check the initial value of `IP_RECVTOS`, set it, and check it.
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
#[cfg(any(
apple,
linux_like,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "cygwin",
))]
{
assert!(!sockopt::ip_recvtos(&s).unwrap());
sockopt::set_ip_recvtos(&s, true).unwrap();
Expand Down Expand Up @@ -409,6 +416,7 @@ fn test_sockopts_ipv6() {
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
target_os = "cygwin",
)))]
assert_eq!(sockopt::socket_domain(&s).unwrap(), AddressFamily::INET6);

Expand Down Expand Up @@ -514,7 +522,7 @@ fn test_sockopts_ipv6() {
test_sockopts_tcp(&s);
}

#[cfg(linux_kernel)]
#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[test]
fn test_socketopts_ip_mtu() {
use std::net::SocketAddrV4;
Expand Down
3 changes: 2 additions & 1 deletion tests/process/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ fn test_waitpgid() {
target_os = "emscripten",
target_os = "openbsd",
target_os = "redox",
target_os = "wasi"
target_os = "wasi",
target_os = "cygwin",
)))]
#[test]
#[serial]
Expand Down
Loading