Skip to content

Commit f1d166d

Browse files
committed
feat: full cygwin support
1 parent 8785010 commit f1d166d

File tree

12 files changed

+62
-34
lines changed

12 files changed

+62
-34
lines changed

src/dir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ impl Entry {
287287
target_os = "fuchsia",
288288
target_os = "haiku",
289289
target_os = "hurd",
290+
target_os = "cygwin",
290291
solarish,
291292
linux_android,
292293
apple_targets))] {

src/features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ mod os {
103103
target_os = "hurd", // Since glibc 2.28
104104
target_os = "illumos", // Since ???
105105
target_os = "redox", // Since 1-july-2020
106+
target_os = "cygwin",
106107
))]
107108
mod os {
108109
/// Check if the OS supports atomic close-on-exec for sockets

src/net/if_.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ libc_bitflags!(
5151
IFF_BROADCAST as IflagsType;
5252
/// Internal debugging flag. (see
5353
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
54-
#[cfg(not(target_os = "haiku"))]
54+
#[cfg(not(any(target_os = "haiku", target_os = "cygwin")))]
5555
IFF_DEBUG as IflagsType;
5656
/// Interface is a loopback interface. (see
5757
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
@@ -66,7 +66,8 @@ libc_bitflags!(
6666
solarish,
6767
apple_targets,
6868
target_os = "fuchsia",
69-
target_os = "netbsd"))]
69+
target_os = "netbsd",
70+
target_os = "cygwin"))]
7071
IFF_NOTRAILERS as IflagsType;
7172
/// Interface manages own routes.
7273
#[cfg(any(target_os = "dragonfly"))]
@@ -77,7 +78,8 @@ libc_bitflags!(
7778
linux_android,
7879
bsd,
7980
solarish,
80-
target_os = "fuchsia"))]
81+
target_os = "fuchsia",
82+
target_os = "cygwin"))]
8183
IFF_RUNNING as IflagsType;
8284
/// No arp protocol, L2 destination address not set. (see
8385
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
@@ -87,6 +89,7 @@ libc_bitflags!(
8789
IFF_PROMISC as IflagsType;
8890
/// Receive all multicast packets. (see
8991
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
92+
#[cfg(not(target_os = "cygwin"))]
9093
IFF_ALLMULTI as IflagsType;
9194
/// Master of a load balancing bundle. (see
9295
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
@@ -145,7 +148,7 @@ libc_bitflags!(
145148
#[cfg(solarish)]
146149
IFF_PRIVATE as IflagsType;
147150
/// Driver signals L1 up. Volatile.
148-
#[cfg(any(target_os = "fuchsia", target_os = "linux"))]
151+
#[cfg(any(target_os = "fuchsia", target_os = "linux", target_os = "cygwin"))]
149152
IFF_LOWER_UP;
150153
/// Interface is in polling mode.
151154
#[cfg(any(target_os = "dragonfly"))]
@@ -157,7 +160,7 @@ libc_bitflags!(
157160
#[cfg(solarish)]
158161
IFF_NOXMIT as IflagsType;
159162
/// Driver signals dormant. Volatile.
160-
#[cfg(any(target_os = "fuchsia", target_os = "linux"))]
163+
#[cfg(any(target_os = "fuchsia", target_os = "linux", target_os = "cygwin"))]
161164
IFF_DORMANT;
162165
/// User-requested promisc mode.
163166
#[cfg(freebsdlike)]

src/sys/mman.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ libc_enum! {
281281
#[cfg(linux_android)]
282282
MADV_DODUMP,
283283
/// Specify that the application no longer needs the pages in the given range.
284-
#[cfg(not(any(target_os = "aix", target_os = "hurd")))]
284+
#[cfg(not(any(target_os = "aix", target_os = "hurd", target_os = "cygwin")))]
285285
MADV_FREE,
286286
/// Request that the system not flush the current range to disk unless it needs to.
287287
#[cfg(freebsdlike)]
@@ -357,7 +357,7 @@ libc_bitflags! {
357357
}
358358
}
359359

360-
#[cfg(not(target_os = "haiku"))]
360+
#[cfg(not(any(target_os = "haiku", target_os = "cygwin")))]
361361
libc_bitflags! {
362362
/// Flags for [`mlockall`].
363363
pub struct MlockAllFlags: c_int {
@@ -400,7 +400,7 @@ pub unsafe fn munlock(addr: NonNull<c_void>, length: size_t) -> Result<()> {
400400
/// Locked pages never move to the swap area. For more information, see [`mlockall(2)`].
401401
///
402402
/// [`mlockall(2)`]: https://man7.org/linux/man-pages/man2/mlockall.2.html
403-
#[cfg(not(target_os = "haiku"))]
403+
#[cfg(not(any(target_os = "haiku", target_os = "cygwin")))]
404404
pub fn mlockall(flags: MlockAllFlags) -> Result<()> {
405405
unsafe { Errno::result(libc::mlockall(flags.bits())) }.map(drop)
406406
}
@@ -410,7 +410,7 @@ pub fn mlockall(flags: MlockAllFlags) -> Result<()> {
410410
/// For more information, see [`munlockall(2)`].
411411
///
412412
/// [`munlockall(2)`]: https://man7.org/linux/man-pages/man2/munlockall.2.html
413-
#[cfg(not(target_os = "haiku"))]
413+
#[cfg(not(any(target_os = "haiku", target_os = "cygwin")))]
414414
pub fn munlockall() -> Result<()> {
415415
unsafe { Errno::result(libc::munlockall()) }.map(drop)
416416
}

src/sys/signal.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ libc_enum! {
111111
#[cfg(not(any(linux_android, target_os = "emscripten",
112112
target_os = "fuchsia", target_os = "redox",
113113
target_os = "haiku", target_os = "aix",
114-
target_os = "solaris")))]
114+
target_os = "solaris", target_os = "cygwin")))]
115115
/// Information request
116116
SIGINFO,
117117
}
@@ -190,7 +190,8 @@ impl FromStr for Signal {
190190
target_os = "redox",
191191
target_os = "aix",
192192
target_os = "haiku",
193-
target_os = "solaris"
193+
target_os = "solaris",
194+
target_os = "cygwin"
194195
)))]
195196
"SIGINFO" => Signal::SIGINFO,
196197
_ => return Err(Errno::EINVAL),
@@ -275,7 +276,8 @@ impl Signal {
275276
target_os = "redox",
276277
target_os = "aix",
277278
target_os = "haiku",
278-
target_os = "solaris"
279+
target_os = "solaris",
280+
target_os = "cygwin"
279281
)))]
280282
Signal::SIGINFO => "SIGINFO",
281283
}
@@ -359,7 +361,7 @@ const SIGNALS: [Signal; 30] = [
359361
SIGURG, SIGPOLL, SIGIO, SIGSTOP, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU,
360362
SIGVTALRM, SIGPROF, SIGXCPU, SIGXFSZ, SIGTRAP,
361363
];
362-
#[cfg(target_os = "solaris")]
364+
#[cfg(any(target_os = "solaris", target_os = "cygwin"))]
363365
#[cfg(feature = "signal")]
364366
const SIGNALS: [Signal; 30] = [
365367
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
@@ -374,7 +376,8 @@ const SIGNALS: [Signal; 30] = [
374376
target_os = "aix",
375377
target_os = "redox",
376378
target_os = "haiku",
377-
target_os = "solaris"
379+
target_os = "solaris",
380+
target_os = "cygwin"
378381
)))]
379382
#[cfg(feature = "signal")]
380383
const SIGNALS: [Signal; 31] = [

src/sys/socket/addr.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub enum AddressFamily {
6666
#[cfg(linux_android)]
6767
Netlink = libc::AF_NETLINK,
6868
/// Kernel interface for interacting with the routing table
69-
#[cfg(not(any(linux_android, target_os = "redox")))]
69+
#[cfg(not(any(linux_android, target_os = "redox", target_os = "cygwin")))]
7070
Route = libc::PF_ROUTE,
7171
/// Low level packet interface (see [`packet(7)`](https://man7.org/linux/man-pages/man7/packet.7.html))
7272
#[cfg(any(linux_android, solarish, target_os = "fuchsia"))]
@@ -78,7 +78,7 @@ pub enum AddressFamily {
7878
#[cfg(linux_android)]
7979
Ax25 = libc::AF_AX25,
8080
/// IPX - Novell protocols
81-
#[cfg(not(any(target_os = "aix", target_os = "redox")))]
81+
#[cfg(not(any(target_os = "aix", target_os = "redox", target_os = "cygwin")))]
8282
Ipx = libc::AF_IPX,
8383
/// AppleTalk
8484
#[cfg(not(target_os = "redox"))]
@@ -164,6 +164,7 @@ pub enum AddressFamily {
164164
apple_targets,
165165
target_os = "hurd",
166166
target_os = "redox",
167+
target_os = "cygwin",
167168
)))]
168169
Bluetooth = libc::AF_BLUETOOTH,
169170
/// IUCV (inter-user communication vehicle) z/VM protocol for
@@ -180,6 +181,7 @@ pub enum AddressFamily {
180181
target_os = "haiku",
181182
target_os = "hurd",
182183
target_os = "redox",
184+
target_os = "cygwin",
183185
)))]
184186
Isdn = libc::AF_ISDN,
185187
/// Nokia cellular modem IPC/RPC interface
@@ -263,7 +265,7 @@ impl AddressFamily {
263265
libc::AF_NETLINK => Some(AddressFamily::Netlink),
264266
#[cfg(apple_targets)]
265267
libc::AF_SYSTEM => Some(AddressFamily::System),
266-
#[cfg(not(any(linux_android, target_os = "redox")))]
268+
#[cfg(not(any(linux_android, target_os = "redox", target_os = "cygwin")))]
267269
libc::PF_ROUTE => Some(AddressFamily::Route),
268270
#[cfg(linux_android)]
269271
libc::AF_PACKET => Some(AddressFamily::Packet),
@@ -446,6 +448,7 @@ impl UnixAddr {
446448
target_os = "fuchsia",
447449
solarish,
448450
target_os = "redox",
451+
target_os = "cygwin",
449452
))]
450453
{
451454
UnixAddr { sun, sun_len }
@@ -510,6 +513,7 @@ impl UnixAddr {
510513
target_os = "fuchsia",
511514
solarish,
512515
target_os = "redox",
516+
target_os = "cygwin",
513517
))]
514518
{
515519
self.sun_len
@@ -556,6 +560,7 @@ impl SockaddrLike for UnixAddr {
556560
target_os = "fuchsia",
557561
solarish,
558562
target_os = "redox",
563+
target_os = "cygwin",
559564
))] {
560565
let su_len = len.unwrap_or(
561566
mem::size_of::<libc::sockaddr_un>() as libc::socklen_t
@@ -1122,7 +1127,7 @@ pub union SockaddrStorage {
11221127
alg: AlgAddr,
11231128
#[cfg(all(
11241129
feature = "net",
1125-
not(any(target_os = "hurd", target_os = "redox"))
1130+
not(any(target_os = "hurd", target_os = "redox", target_os = "cygwin"))
11261131
))]
11271132
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
11281133
dl: LinkAddr,

src/sys/socket/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ pub use self::addr::{AddressFamily, UnixAddr};
4343
solarish,
4444
target_os = "haiku",
4545
target_os = "hurd",
46-
target_os = "redox"
46+
target_os = "redox",
47+
target_os = "cygwin",
4748
)))]
4849
#[cfg(feature = "net")]
4950
pub use self::addr::{LinkAddr, SockaddrIn, SockaddrIn6};
5051
#[cfg(any(
5152
solarish,
5253
target_os = "haiku",
5354
target_os = "hurd",
54-
target_os = "redox"
55+
target_os = "redox",
56+
target_os = "cygwin",
5557
))]
5658
#[cfg(feature = "net")]
5759
pub use self::addr::{SockaddrIn, SockaddrIn6};
@@ -1023,7 +1025,7 @@ impl ControlMessageOwned {
10231025
let cred: libc::cmsgcred = unsafe { ptr::read_unaligned(p as *const _) };
10241026
ControlMessageOwned::ScmCreds(cred.into())
10251027
}
1026-
#[cfg(not(any(target_os = "aix", target_os = "haiku")))]
1028+
#[cfg(not(any(target_os = "aix", target_os = "haiku", target_os = "cygwin")))]
10271029
(libc::SOL_SOCKET, libc::SCM_TIMESTAMP) => {
10281030
let tv: libc::timeval = unsafe { ptr::read_unaligned(p as *const _) };
10291031
ControlMessageOwned::ScmTimestamp(TimeVal::from(tv))
@@ -1372,13 +1374,15 @@ impl ControlMessage<'_> {
13721374
/// The value of CMSG_LEN on this message.
13731375
/// Safe because CMSG_LEN is always safe
13741376
#[cfg(any(target_os = "android",
1375-
all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos")))))]
1377+
all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos"))),
1378+
target_os = "cygwin"))]
13761379
fn cmsg_len(&self) -> usize {
13771380
unsafe{CMSG_LEN(self.len() as libc::c_uint) as usize}
13781381
}
13791382

13801383
#[cfg(not(any(target_os = "android",
1381-
all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos"))))))]
1384+
all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos"))),
1385+
target_os = "cygwin")))]
13821386
fn cmsg_len(&self) -> libc::c_uint {
13831387
unsafe{CMSG_LEN(self.len() as libc::c_uint)}
13841388
}

src/sys/socket/sockopt.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ sockopt_impl!(
298298
libc::SO_REUSEADDR,
299299
bool
300300
);
301-
#[cfg(not(solarish))]
301+
#[cfg(not(any(solarish, target_os = "cygwin")))]
302302
sockopt_impl!(
303303
/// Permits multiple AF_INET or AF_INET6 sockets to be bound to an
304304
/// identical socket address.
@@ -883,7 +883,8 @@ sockopt_impl!(
883883
target_os = "aix",
884884
target_os = "haiku",
885885
target_os = "hurd",
886-
target_os = "redox"
886+
target_os = "redox",
887+
target_os = "cygwin"
887888
)))]
888889
sockopt_impl!(
889890
/// Enable or disable the receiving of the `SO_TIMESTAMP` control message.

src/sys/termios.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ libc_bitflags! {
667667
ECHOK;
668668
ECHO;
669669
ECHONL;
670-
#[cfg(not(target_os = "redox"))]
670+
#[cfg(not(any(target_os = "redox", target_os = "cygwin")))]
671671
ECHOPRT;
672672
#[cfg(not(target_os = "redox"))]
673673
ECHOCTL;
@@ -676,14 +676,14 @@ libc_bitflags! {
676676
#[cfg(bsd)]
677677
ALTWERASE;
678678
IEXTEN;
679-
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "aix")))]
679+
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "aix", target_os = "cygwin")))]
680680
EXTPROC;
681681
TOSTOP;
682682
#[cfg(not(target_os = "redox"))]
683683
FLUSHO;
684684
#[cfg(bsd)]
685685
NOKERNINFO;
686-
#[cfg(not(target_os = "redox"))]
686+
#[cfg(not(any(target_os = "redox", target_os = "cygwin")))]
687687
PENDIN;
688688
NOFLSH;
689689
}

src/sys/uio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn readv<Fd: AsFd>(fd: Fd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
5353
/// or an error occurs. The file offset is not changed.
5454
///
5555
/// See also: [`writev`](fn.writev.html) and [`pwrite`](fn.pwrite.html)
56-
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris")))]
56+
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris", target_os = "cygwin")))]
5757
pub fn pwritev<Fd: AsFd>(
5858
fd: Fd,
5959
iov: &[IoSlice<'_>],
@@ -82,7 +82,7 @@ pub fn pwritev<Fd: AsFd>(
8282
/// changed.
8383
///
8484
/// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html)
85-
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris")))]
85+
#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris", target_os = "cygwin")))]
8686
// Clippy doesn't know that we need to pass iov mutably only because the
8787
// mutation happens after converting iov to a pointer
8888
#[allow(clippy::needless_pass_by_ref_mut)]

src/syslog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ libc_bitflags! {
215215
/// which file descriptors are allocated.
216216
LOG_NDELAY;
217217
/// Write the message to standard error output as well to the system log.
218-
#[cfg(not(any(solarish, target_os = "redox")))]
218+
#[cfg(not(any(solarish, target_os = "redox", target_os = "cygwin")))]
219219
LOG_PERROR;
220220
}
221221
}

0 commit comments

Comments
 (0)