Skip to content

Commit bd5427c

Browse files
authored
Fix build, sockopts and examples for cygwin (#1428)
1 parent 92cd57a commit bd5427c

File tree

10 files changed

+91
-24
lines changed

10 files changed

+91
-24
lines changed

examples/process.rs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,55 @@ fn main() -> rustix::io::Result<()> {
5050
println!("Stack Limit: {:?}", getrlimit(Resource::Stack));
5151
#[cfg(not(target_os = "haiku"))]
5252
println!("Core Limit: {:?}", getrlimit(Resource::Core));
53-
#[cfg(not(any(solarish, target_os = "haiku")))]
53+
#[cfg(not(any(solarish, target_os = "haiku", target_os = "cygwin")))]
5454
println!("Rss Limit: {:?}", getrlimit(Resource::Rss));
55-
#[cfg(not(any(solarish, target_os = "haiku")))]
55+
#[cfg(not(any(solarish, target_os = "haiku", target_os = "cygwin")))]
5656
println!("Nproc Limit: {:?}", getrlimit(Resource::Nproc));
5757
#[cfg(not(target_os = "solaris"))]
5858
println!("Nofile Limit: {:?}", getrlimit(Resource::Nofile));
59-
#[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
59+
#[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "cygwin")))]
6060
println!("Memlock Limit: {:?}", getrlimit(Resource::Memlock));
6161
#[cfg(not(target_os = "openbsd"))]
6262
println!("As Limit: {:?}", getrlimit(Resource::As));
63-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
63+
#[cfg(not(any(
64+
bsd,
65+
solarish,
66+
target_os = "aix",
67+
target_os = "haiku",
68+
target_os = "cygwin",
69+
)))]
6470
println!("Locks Limit: {:?}", getrlimit(Resource::Locks));
65-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
71+
#[cfg(not(any(
72+
bsd,
73+
solarish,
74+
target_os = "aix",
75+
target_os = "haiku",
76+
target_os = "cygwin",
77+
)))]
6678
println!("Sigpending Limit: {:?}", getrlimit(Resource::Sigpending));
67-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
79+
#[cfg(not(any(
80+
bsd,
81+
solarish,
82+
target_os = "aix",
83+
target_os = "haiku",
84+
target_os = "cygwin",
85+
)))]
6886
println!("Msgqueue Limit: {:?}", getrlimit(Resource::Msgqueue));
69-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
87+
#[cfg(not(any(
88+
bsd,
89+
solarish,
90+
target_os = "aix",
91+
target_os = "haiku",
92+
target_os = "cygwin",
93+
)))]
7094
println!("Nice Limit: {:?}", getrlimit(Resource::Nice));
71-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
95+
#[cfg(not(any(
96+
bsd,
97+
solarish,
98+
target_os = "aix",
99+
target_os = "haiku",
100+
target_os = "cygwin",
101+
)))]
72102
println!("Rtprio Limit: {:?}", getrlimit(Resource::Rtprio));
73103
#[cfg(not(any(
74104
bsd,
@@ -77,6 +107,7 @@ fn main() -> rustix::io::Result<()> {
77107
target_os = "android",
78108
target_os = "emscripten",
79109
target_os = "haiku",
110+
target_os = "cygwin",
80111
)))]
81112
println!("Rttime Limit: {:?}", getrlimit(Resource::Rttime));
82113
}

examples/stdio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
258258
if term.local_modes.contains(LocalModes::ECHOCTL) {
259259
print!(" ECHOCTL");
260260
}
261-
#[cfg(not(any(target_os = "redox")))]
261+
#[cfg(not(any(target_os = "redox", target_os = "cygwin")))]
262262
if term.local_modes.contains(LocalModes::ECHOPRT) {
263263
print!(" ECHOPRT");
264264
}
@@ -276,7 +276,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
276276
if term.local_modes.contains(LocalModes::TOSTOP) {
277277
print!(" TOSTOP");
278278
}
279-
#[cfg(not(any(target_os = "redox")))]
279+
#[cfg(not(any(target_os = "redox", target_os = "cygwin")))]
280280
if term.local_modes.contains(LocalModes::PENDIN) {
281281
print!(" PENDIN");
282282
}

src/backend/libc/net/sockopt.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,13 @@ pub(crate) fn ipv6_v6only(fd: BorrowedFd<'_>) -> io::Result<bool> {
490490
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_V6ONLY).map(to_bool)
491491
}
492492

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

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

770-
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
770+
#[cfg(any(
771+
apple,
772+
linux_like,
773+
target_os = "freebsd",
774+
target_os = "fuchsia",
775+
target_os = "cygwin",
776+
))]
771777
#[inline]
772778
pub(crate) fn set_ip_recvtos(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
773779
setsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS, from_bool(value))
774780
}
775781

776-
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
782+
#[cfg(any(
783+
apple,
784+
linux_like,
785+
target_os = "freebsd",
786+
target_os = "fuchsia",
787+
target_os = "cygwin",
788+
))]
777789
#[inline]
778790
pub(crate) fn ip_recvtos(fd: BorrowedFd<'_>) -> io::Result<bool> {
779791
getsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS).map(to_bool)

src/net/sockopt.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ pub fn ipv6_v6only<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
668668
///
669669
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
670670
#[inline]
671-
#[cfg(linux_kernel)]
671+
#[cfg(any(linux_kernel, target_os = "cygwin"))]
672672
#[doc(alias = "IP_MTU")]
673673
pub fn ip_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
674674
backend::net::sockopt::ip_mtu(fd.as_fd())
@@ -680,7 +680,7 @@ pub fn ip_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
680680
///
681681
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
682682
#[inline]
683-
#[cfg(linux_kernel)]
683+
#[cfg(any(linux_kernel, target_os = "cygwin"))]
684684
#[doc(alias = "IPV6_MTU")]
685685
pub fn ipv6_mtu<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
686686
backend::net::sockopt::ipv6_mtu(fd.as_fd())
@@ -1088,7 +1088,13 @@ pub fn ip_tos<Fd: AsFd>(fd: Fd) -> io::Result<u8> {
10881088
/// See the [module-level documentation] for more.
10891089
///
10901090
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
1091-
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
1091+
#[cfg(any(
1092+
apple,
1093+
linux_like,
1094+
target_os = "freebsd",
1095+
target_os = "fuchsia",
1096+
target_os = "cygwin",
1097+
))]
10921098
#[inline]
10931099
#[doc(alias = "IP_RECVTOS")]
10941100
pub fn set_ip_recvtos<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
@@ -1100,7 +1106,13 @@ pub fn set_ip_recvtos<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
11001106
/// See the [module-level documentation] for more.
11011107
///
11021108
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
1103-
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
1109+
#[cfg(any(
1110+
apple,
1111+
linux_like,
1112+
target_os = "freebsd",
1113+
target_os = "fuchsia",
1114+
target_os = "cygwin",
1115+
))]
11041116
#[inline]
11051117
#[doc(alias = "IP_RECVTOS")]
11061118
pub fn ip_recvtos<Fd: AsFd>(fd: Fd) -> io::Result<bool> {

src/signal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ impl Signal {
316316
target_os = "hurd",
317317
target_os = "nto",
318318
target_os = "vita",
319+
target_os = "cygwin",
319320
all(
320321
linux_kernel,
321322
any(

src/termios/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,8 @@ mod tests {
15671567
solarish,
15681568
target_os = "emscripten",
15691569
target_os = "haiku",
1570-
target_os = "redox"
1570+
target_os = "redox",
1571+
target_os = "cygwin",
15711572
)))]
15721573
fn termios_legacy() {
15731574
// Check that our doc aliases above are correct.

tests/io/ioctl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// `ioctl_fionread` on Windows doesn't work on files.
2-
#[cfg(not(windows))]
2+
#[cfg(not(any(windows, target_os = "cygwin")))]
33
#[test]
44
fn test_ioctls() {
55
let file = std::fs::File::open("Cargo.toml").unwrap();

tests/io/read_write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ fn test_preadv2_nowait() {
303303
#[cfg(not(target_os = "espidf"))] // no preadv/pwritev
304304
#[cfg(not(target_os = "solaris"))] // no preadv/pwritev
305305
#[cfg(not(target_os = "haiku"))] // no preadv/pwritev
306+
#[cfg(not(target_os = "cygwin"))] // no preadv/pwritev
306307
#[test]
307308
fn test_p_offsets() {
308309
use rustix::fs::{openat, Mode, OFlags, CWD};

tests/net/sockopt.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn test_sockopts_socket(s: &OwnedFd) {
148148
assert!(sockopt::socket_oobinline(s).unwrap());
149149

150150
// Check the initial value of `SO_REUSEPORT`, set it, and check it.
151-
#[cfg(not(any(solarish, windows)))]
151+
#[cfg(not(any(solarish, windows, target_os = "cygwin")))]
152152
{
153153
assert!(!sockopt::socket_reuseport(s).unwrap());
154154
sockopt::set_socket_reuseport(s, true).unwrap();
@@ -320,6 +320,7 @@ fn test_sockopts_ipv4() {
320320
target_os = "haiku",
321321
target_os = "netbsd",
322322
target_os = "nto",
323+
target_os = "cygwin",
323324
)))]
324325
assert_eq!(sockopt::socket_domain(&s).unwrap(), AddressFamily::INET);
325326
assert_ne!(sockopt::ip_ttl(&s).unwrap(), 0);
@@ -365,7 +366,13 @@ fn test_sockopts_ipv4() {
365366
}
366367

367368
// Check the initial value of `IP_RECVTOS`, set it, and check it.
368-
#[cfg(any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia"))]
369+
#[cfg(any(
370+
apple,
371+
linux_like,
372+
target_os = "freebsd",
373+
target_os = "fuchsia",
374+
target_os = "cygwin",
375+
))]
369376
{
370377
assert!(!sockopt::ip_recvtos(&s).unwrap());
371378
sockopt::set_ip_recvtos(&s, true).unwrap();
@@ -409,6 +416,7 @@ fn test_sockopts_ipv6() {
409416
target_os = "haiku",
410417
target_os = "netbsd",
411418
target_os = "nto",
419+
target_os = "cygwin",
412420
)))]
413421
assert_eq!(sockopt::socket_domain(&s).unwrap(), AddressFamily::INET6);
414422

@@ -514,7 +522,7 @@ fn test_sockopts_ipv6() {
514522
test_sockopts_tcp(&s);
515523
}
516524

517-
#[cfg(linux_kernel)]
525+
#[cfg(any(linux_kernel, target_os = "cygwin"))]
518526
#[test]
519527
fn test_socketopts_ip_mtu() {
520528
use std::net::SocketAddrV4;

tests/process/wait.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ fn test_waitpgid() {
9595
target_os = "emscripten",
9696
target_os = "openbsd",
9797
target_os = "redox",
98-
target_os = "wasi"
98+
target_os = "wasi",
99+
target_os = "cygwin",
99100
)))]
100101
#[test]
101102
#[serial]

0 commit comments

Comments
 (0)