From 91b9b5cd9fdb87e0de78ec9eeafec03faa995222 Mon Sep 17 00:00:00 2001 From: Berrysoft Date: Tue, 1 Apr 2025 17:57:39 +0800 Subject: [PATCH] Fix build, sockopts and examples for cygwin --- examples/process.rs | 47 +++++++++++++++++++++++++++------ examples/stdio.rs | 4 +-- src/backend/libc/net/sockopt.rs | 20 +++++++++++--- src/net/sockopt.rs | 20 +++++++++++--- src/signal.rs | 1 + src/termios/types.rs | 3 ++- tests/io/ioctl.rs | 2 +- tests/io/read_write.rs | 1 + tests/net/sockopt.rs | 14 +++++++--- tests/process/wait.rs | 3 ++- 10 files changed, 91 insertions(+), 24 deletions(-) diff --git a/examples/process.rs b/examples/process.rs index 1792514df..2f384805e 100644 --- a/examples/process.rs +++ b/examples/process.rs @@ -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, @@ -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)); } diff --git a/examples/stdio.rs b/examples/stdio.rs index 40170e30d..d6fb132ae 100644 --- a/examples/stdio.rs +++ b/examples/stdio.rs @@ -258,7 +258,7 @@ fn show(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"); } @@ -276,7 +276,7 @@ fn show(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"); } diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs index 29ceaa84c..2c1c392e9 100644 --- a/src/backend/libc/net/sockopt.rs +++ b/src/backend/libc/net/sockopt.rs @@ -490,13 +490,13 @@ pub(crate) fn ipv6_v6only(fd: BorrowedFd<'_>) -> io::Result { 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 { 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 { getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_MTU) @@ -767,13 +767,25 @@ pub(crate) fn ip_tos(fd: BorrowedFd<'_>) -> io::Result { 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 { getsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS).map(to_bool) diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index 3379fb028..5af5db1e9 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -668,7 +668,7 @@ pub fn ipv6_v6only(fd: Fd) -> io::Result { /// /// [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: Fd) -> io::Result { backend::net::sockopt::ip_mtu(fd.as_fd()) @@ -680,7 +680,7 @@ pub fn ip_mtu(fd: Fd) -> io::Result { /// /// [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: Fd) -> io::Result { backend::net::sockopt::ipv6_mtu(fd.as_fd()) @@ -1088,7 +1088,13 @@ pub fn ip_tos(fd: Fd) -> 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 set_ip_recvtos(fd: Fd, value: bool) -> io::Result<()> { @@ -1100,7 +1106,13 @@ pub fn set_ip_recvtos(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: Fd) -> io::Result { diff --git a/src/signal.rs b/src/signal.rs index 264f227e9..d150b5219 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -316,6 +316,7 @@ impl Signal { target_os = "hurd", target_os = "nto", target_os = "vita", + target_os = "cygwin", all( linux_kernel, any( diff --git a/src/termios/types.rs b/src/termios/types.rs index 16adc7fe4..dbe82560b 100644 --- a/src/termios/types.rs +++ b/src/termios/types.rs @@ -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. diff --git a/tests/io/ioctl.rs b/tests/io/ioctl.rs index 40573ffef..721d5e09b 100644 --- a/tests/io/ioctl.rs +++ b/tests/io/ioctl.rs @@ -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(); diff --git a/tests/io/read_write.rs b/tests/io/read_write.rs index 6d6daa93a..e264c997a 100644 --- a/tests/io/read_write.rs +++ b/tests/io/read_write.rs @@ -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}; diff --git a/tests/net/sockopt.rs b/tests/net/sockopt.rs index a668afad9..67d11a84a 100644 --- a/tests/net/sockopt.rs +++ b/tests/net/sockopt.rs @@ -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(); @@ -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); @@ -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(); @@ -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); @@ -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; diff --git a/tests/process/wait.rs b/tests/process/wait.rs index cd2dc27e0..5a455129a 100644 --- a/tests/process/wait.rs +++ b/tests/process/wait.rs @@ -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]