From c27a42ee690e6ad2dabf3094bf92f70baa00ada0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Tue, 31 Dec 2024 00:23:06 +0900 Subject: [PATCH 01/14] feat: add cygwin support --- src/errno.rs | 346 +++++++++++++++++++++++++++++++++++++++++++- src/fcntl.rs | 5 +- src/sys/resource.rs | 6 +- src/unistd.rs | 2 + 4 files changed, 348 insertions(+), 11 deletions(-) diff --git a/src/errno.rs b/src/errno.rs index 2dae6154b7..0d9d2d0fa0 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -24,7 +24,8 @@ cfg_if! { unsafe fn errno_location() -> *mut c_int { unsafe { libc::__error() } } - } else if #[cfg(any(target_os = "android", netbsdlike))] { + } else if #[cfg(any(target_os = "android", netbsdlike, target_os = "cygwin"))] { + #[cfg_attr(target_os = "cygwin", no_mangle)] unsafe fn errno_location() -> *mut c_int { unsafe { libc::__errno() } } @@ -280,6 +281,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ECHRNG => "Channel number out of range", @@ -289,6 +291,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EL2NSYNC => "Level 2 not synchronized", @@ -298,6 +301,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EL3HLT => "Level 3 halted", @@ -307,6 +311,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EL3RST => "Level 3 reset", @@ -316,6 +321,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ELNRNG => "Link number out of range", @@ -325,6 +331,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EUNATCH => "Protocol driver not attached", @@ -334,6 +341,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ENOCSI => "No CSI structure available", @@ -343,6 +351,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EL2HLT => "Level 2 halted", @@ -351,6 +360,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EBADE => "Invalid exchange", @@ -359,6 +369,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EBADR => "Invalid request descriptor", @@ -367,6 +378,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EXFULL => "Exchange full", @@ -375,6 +387,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ENOANO => "No anode", @@ -383,6 +396,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EBADRQC => "Invalid request code", @@ -391,6 +405,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EBADSLT => "Invalid slot", @@ -399,6 +414,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EBFONT => "Bad font file format", @@ -408,6 +424,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] ENOSTR => "Device not a stream", @@ -417,6 +434,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] ENODATA => "No data available", @@ -426,6 +444,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] ETIME => "Timer expired", @@ -435,6 +454,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] ENOSR => "Out of streams resources", @@ -443,6 +463,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ENONET => "Machine is not on the network", @@ -451,6 +472,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ENOPKG => "Package not installed", @@ -460,6 +482,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] EREMOTE => "Object is remote", @@ -477,6 +500,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EADV => "Advertise error", @@ -485,6 +509,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ESRMNT => "Srmount error", @@ -493,6 +518,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ECOMM => "Communication error on send", @@ -502,6 +528,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EPROTO => "Protocol error", @@ -518,6 +545,7 @@ fn desc(errno: Errno) -> &'static str { linux_android, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EDOTDOT => "RFS specific error", @@ -526,6 +554,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EBADMSG => "Not a data message", @@ -539,6 +568,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] EOVERFLOW => "Value too large for defined data type", @@ -547,6 +577,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ENOTUNIQ => "Name not unique on network", @@ -555,6 +586,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EBADFD => "File descriptor in bad state", @@ -563,6 +595,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EREMCHG => "Remote address changed", @@ -571,6 +604,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ELIBACC => "Can not access a needed shared library", @@ -579,6 +613,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ELIBBAD => "Accessing a corrupted shared library", @@ -587,6 +622,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ELIBSCN => ".lib section in a.out corrupted", @@ -595,6 +631,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ELIBMAX => "Attempting to link in too many shared libraries", @@ -604,6 +641,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] ELIBEXEC => "Cannot exec a shared library directly", @@ -614,6 +652,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "openbsd", target_os = "emscripten", + target_os = "cygwin", ))] EILSEQ => "Illegal byte sequence", @@ -631,6 +670,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ESTRPIPE => "Streams pipe error", @@ -639,6 +679,7 @@ fn desc(errno: Errno) -> &'static str { solarish, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EUSERS => "Too many users", @@ -648,6 +689,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "netbsd", target_os = "redox", target_os = "emscripten", + target_os = "cygwin", ))] EOPNOTSUPP => "Operation not supported on transport endpoint", @@ -656,6 +698,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] ESTALE => "Stale file handle", @@ -698,6 +741,7 @@ fn desc(errno: Errno) -> &'static str { linux_android, target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] EDQUOT => "Quota exceeded", @@ -707,6 +751,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "openbsd", target_os = "dragonfly", target_os = "emscripten", + target_os = "cygwin", ))] ENOMEDIUM => "No medium found", @@ -724,6 +769,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "haiku", target_os = "emscripten", + target_os = "cygwin", ))] ECANCELED => "Operation canceled", @@ -761,6 +807,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "fuchsia", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", ))] EOWNERDEAD => "Owner died", @@ -772,6 +819,7 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", target_os = "fuchsia", target_os = "emscripten", + target_os = "cygwin", ))] ENOTRECOVERABLE => "State not recoverable", @@ -795,10 +843,20 @@ fn desc(errno: Errno) -> &'static str { #[cfg(freebsdlike)] EDOOFUS => "Programming error", - #[cfg(any(freebsdlike, target_os = "hurd", target_os = "redox"))] + #[cfg(any( + freebsdlike, + target_os = "hurd", + target_os = "redox", + target_os = "cygwin" + ))] EMULTIHOP => "Multihop attempted", - #[cfg(any(freebsdlike, target_os = "hurd", target_os = "redox"))] + #[cfg(any( + freebsdlike, + target_os = "hurd", + target_os = "redox", + target_os = "cygwin" + ))] ENOLINK => "Link has been severed", #[cfg(target_os = "freebsd")] @@ -858,11 +916,17 @@ fn desc(errno: Errno) -> &'static str { target_os = "aix", solarish, target_os = "haiku", - target_os = "hurd" + target_os = "hurd", + target_os = "cygwin" ))] ENOTSUP => "Operation not supported", - #[cfg(any(bsd, target_os = "aix", target_os = "hurd"))] + #[cfg(any( + bsd, + target_os = "aix", + target_os = "hurd", + target_os = "cygwin" + ))] EPROCLIM => "Too many processes", #[cfg(any( @@ -910,7 +974,7 @@ fn desc(errno: Errno) -> &'static str { #[cfg(any(bsd, target_os = "hurd"))] EPROCUNAVAIL => "Bad procedure for program", - #[cfg(any(bsd, target_os = "hurd"))] + #[cfg(any(bsd, target_os = "hurd", target_os = "cygwin"))] EFTYPE => "Inappropriate file type or format", #[cfg(any(bsd, target_os = "hurd"))] @@ -998,7 +1062,7 @@ fn desc(errno: Errno) -> &'static str { #[cfg(target_os = "dragonfly")] EASYNC => "Async", - #[cfg(solarish)] + #[cfg(any(solarish, target_os = "cygwin"))] EDEADLOCK => "Resource deadlock would occur", #[cfg(solarish)] @@ -3526,3 +3590,271 @@ mod consts { } } } + +#[cfg(target_os = "cygwin")] +mod consts { + #[derive(Clone, Copy, Debug, Eq, PartialEq)] + #[repr(i32)] + #[non_exhaustive] + pub enum Errno { + UnknownErrno = 0, + EPERM = libc::EPERM, + ENOENT = libc::ENOENT, + ESRCH = libc::ESRCH, + EINTR = libc::EINTR, + EIO = libc::EIO, + ENXIO = libc::ENXIO, + E2BIG = libc::E2BIG, + ENOEXEC = libc::ENOEXEC, + EBADF = libc::EBADF, + ECHILD = libc::ECHILD, + EAGAIN = libc::EAGAIN, + ENOMEM = libc::ENOMEM, + EACCES = libc::EACCES, + EFAULT = libc::EFAULT, + ENOTBLK = libc::ENOTBLK, + EBUSY = libc::EBUSY, + EEXIST = libc::EEXIST, + EXDEV = libc::EXDEV, + ENODEV = libc::ENODEV, + ENOTDIR = libc::ENOTDIR, + EISDIR = libc::EISDIR, + EINVAL = libc::EINVAL, + ENFILE = libc::ENFILE, + EMFILE = libc::EMFILE, + ENOTTY = libc::ENOTTY, + ETXTBSY = libc::ETXTBSY, + EFBIG = libc::EFBIG, + ENOSPC = libc::ENOSPC, + ESPIPE = libc::ESPIPE, + EROFS = libc::EROFS, + EMLINK = libc::EMLINK, + EPIPE = libc::EPIPE, + EDOM = libc::EDOM, + ERANGE = libc::ERANGE, + ENOMSG = libc::ENOMSG, + EIDRM = libc::EIDRM, + ECHRNG = libc::ECHRNG, + EL2NSYNC = libc::EL2NSYNC, + EL3HLT = libc::EL3HLT, + EL3RST = libc::EL3RST, + ELNRNG = libc::ELNRNG, + EUNATCH = libc::EUNATCH, + ENOCSI = libc::ENOCSI, + EL2HLT = libc::EL2HLT, + EDEADLK = libc::EDEADLK, + ENOLCK = libc::ENOLCK, + EBADE = libc::EBADE, + EBADR = libc::EBADR, + EXFULL = libc::EXFULL, + ENOANO = libc::ENOANO, + EBADRQC = libc::EBADRQC, + EBADSLT = libc::EBADSLT, + EDEADLOCK = libc::EDEADLOCK, + EBFONT = libc::EBFONT, + ENOSTR = libc::ENOSTR, + ENODATA = libc::ENODATA, + ETIME = libc::ETIME, + ENOSR = libc::ENOSR, + ENONET = libc::ENONET, + ENOPKG = libc::ENOPKG, + EREMOTE = libc::EREMOTE, + ENOLINK = libc::ENOLINK, + EADV = libc::EADV, + ESRMNT = libc::ESRMNT, + ECOMM = libc::ECOMM, + EPROTO = libc::EPROTO, + EMULTIHOP = libc::EMULTIHOP, + EDOTDOT = libc::EDOTDOT, + EBADMSG = libc::EBADMSG, + EFTYPE = libc::EFTYPE, + ENOTUNIQ = libc::ENOTUNIQ, + EBADFD = libc::EBADFD, + EREMCHG = libc::EREMCHG, + ELIBACC = libc::ELIBACC, + ELIBBAD = libc::ELIBBAD, + ELIBSCN = libc::ELIBSCN, + ELIBMAX = libc::ELIBMAX, + ELIBEXEC = libc::ELIBEXEC, + ENOSYS = libc::ENOSYS, + ENOTEMPTY = libc::ENOTEMPTY, + ENAMETOOLONG = libc::ENAMETOOLONG, + ELOOP = libc::ELOOP, + EOPNOTSUPP = libc::EOPNOTSUPP, + EPFNOSUPPORT = libc::EPFNOSUPPORT, + ECONNRESET = libc::ECONNRESET, + ENOBUFS = libc::ENOBUFS, + EAFNOSUPPORT = libc::EAFNOSUPPORT, + EPROTOTYPE = libc::EPROTOTYPE, + ENOTSOCK = libc::ENOTSOCK, + ENOPROTOOPT = libc::ENOPROTOOPT, + ESHUTDOWN = libc::ESHUTDOWN, + ECONNREFUSED = libc::ECONNREFUSED, + EADDRINUSE = libc::EADDRINUSE, + ECONNABORTED = libc::ECONNABORTED, + ENETUNREACH = libc::ENETUNREACH, + ENETDOWN = libc::ENETDOWN, + ETIMEDOUT = libc::ETIMEDOUT, + EHOSTDOWN = libc::EHOSTDOWN, + EHOSTUNREACH = libc::EHOSTUNREACH, + EINPROGRESS = libc::EINPROGRESS, + EALREADY = libc::EALREADY, + EDESTADDRREQ = libc::EDESTADDRREQ, + EMSGSIZE = libc::EMSGSIZE, + EPROTONOSUPPORT = libc::EPROTONOSUPPORT, + ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT, + EADDRNOTAVAIL = libc::EADDRNOTAVAIL, + ENETRESET = libc::ENETRESET, + EISCONN = libc::EISCONN, + ENOTCONN = libc::ENOTCONN, + ETOOMANYREFS = libc::ETOOMANYREFS, + EPROCLIM = libc::EPROCLIM, + EUSERS = libc::EUSERS, + EDQUOT = libc::EDQUOT, + ESTALE = libc::ESTALE, + ENOTSUP = libc::ENOTSUP, + ENOMEDIUM = libc::ENOMEDIUM, + EILSEQ = libc::EILSEQ, + EOVERFLOW = libc::EOVERFLOW, + ECANCELED = libc::ECANCELED, + ENOTRECOVERABLE = libc::ENOTRECOVERABLE, + EOWNERDEAD = libc::EOWNERDEAD, + ESTRPIPE = libc::ESTRPIPE, + } + + impl Errno { + pub const EWOULDBLOCK: Errno = Errno::EAGAIN; + pub const EDEADLOCK: Errno = Errno::EDEADLK; + pub const EOPNOTSUPP: Errno = Errno::ENOTSUP; + } + + pub const fn from_i32(e: i32) -> Errno { + use self::Errno::*; + + match e { + libc::EPERM => EPERM, + libc::ENOENT => ENOENT, + libc::ESRCH => ESRCH, + libc::EINTR => EINTR, + libc::EIO => EIO, + libc::ENXIO => ENXIO, + libc::E2BIG => E2BIG, + libc::ENOEXEC => ENOEXEC, + libc::EBADF => EBADF, + libc::ECHILD => ECHILD, + libc::EAGAIN => EAGAIN, + libc::ENOMEM => ENOMEM, + libc::EACCES => EACCES, + libc::EFAULT => EFAULT, + libc::ENOTBLK => ENOTBLK, + libc::EBUSY => EBUSY, + libc::EEXIST => EEXIST, + libc::EXDEV => EXDEV, + libc::ENODEV => ENODEV, + libc::ENOTDIR => ENOTDIR, + libc::EISDIR => EISDIR, + libc::EINVAL => EINVAL, + libc::ENFILE => ENFILE, + libc::EMFILE => EMFILE, + libc::ENOTTY => ENOTTY, + libc::ETXTBSY => ETXTBSY, + libc::EFBIG => EFBIG, + libc::ENOSPC => ENOSPC, + libc::ESPIPE => ESPIPE, + libc::EROFS => EROFS, + libc::EMLINK => EMLINK, + libc::EPIPE => EPIPE, + libc::EDOM => EDOM, + libc::ERANGE => ERANGE, + libc::ENOMSG => ENOMSG, + libc::EIDRM => EIDRM, + libc::ECHRNG => ECHRNG, + libc::EL2NSYNC => EL2NSYNC, + libc::EL3HLT => EL3HLT, + libc::EL3RST => EL3RST, + libc::ELNRNG => ELNRNG, + libc::EUNATCH => EUNATCH, + libc::ENOCSI => ENOCSI, + libc::EL2HLT => EL2HLT, + libc::EDEADLK => EDEADLK, + libc::ENOLCK => ENOLCK, + libc::EBADE => EBADE, + libc::EBADR => EBADR, + libc::EXFULL => EXFULL, + libc::ENOANO => ENOANO, + libc::EBADRQC => EBADRQC, + libc::EBADSLT => EBADSLT, + libc::EDEADLOCK => EDEADLOCK, + libc::EBFONT => EBFONT, + libc::ENOSTR => ENOSTR, + libc::ENODATA => ENODATA, + libc::ETIME => ETIME, + libc::ENOSR => ENOSR, + libc::ENONET => ENONET, + libc::ENOPKG => ENOPKG, + libc::EREMOTE => EREMOTE, + libc::ENOLINK => ENOLINK, + libc::EADV => EADV, + libc::ESRMNT => ESRMNT, + libc::ECOMM => ECOMM, + libc::EPROTO => EPROTO, + libc::EMULTIHOP => EMULTIHOP, + libc::EDOTDOT => EDOTDOT, + libc::EBADMSG => EBADMSG, + libc::EFTYPE => EFTYPE, + libc::ENOTUNIQ => ENOTUNIQ, + libc::EBADFD => EBADFD, + libc::EREMCHG => EREMCHG, + libc::ELIBACC => ELIBACC, + libc::ELIBBAD => ELIBBAD, + libc::ELIBSCN => ELIBSCN, + libc::ELIBMAX => ELIBMAX, + libc::ELIBEXEC => ELIBEXEC, + libc::ENOSYS => ENOSYS, + libc::ENOTEMPTY => ENOTEMPTY, + libc::ENAMETOOLONG => ENAMETOOLONG, + libc::ELOOP => ELOOP, + libc::EOPNOTSUPP => EOPNOTSUPP, + libc::EPFNOSUPPORT => EPFNOSUPPORT, + libc::ECONNRESET => ECONNRESET, + libc::ENOBUFS => ENOBUFS, + libc::EAFNOSUPPORT => EAFNOSUPPORT, + libc::EPROTOTYPE => EPROTOTYPE, + libc::ENOTSOCK => ENOTSOCK, + libc::ENOPROTOOPT => ENOPROTOOPT, + libc::ESHUTDOWN => ESHUTDOWN, + libc::ECONNREFUSED => ECONNREFUSED, + libc::EADDRINUSE => EADDRINUSE, + libc::ECONNABORTED => ECONNABORTED, + libc::ENETUNREACH => ENETUNREACH, + libc::ENETDOWN => ENETDOWN, + libc::ETIMEDOUT => ETIMEDOUT, + libc::EHOSTDOWN => EHOSTDOWN, + libc::EHOSTUNREACH => EHOSTUNREACH, + libc::EINPROGRESS => EINPROGRESS, + libc::EALREADY => EALREADY, + libc::EDESTADDRREQ => EDESTADDRREQ, + libc::EMSGSIZE => EMSGSIZE, + libc::EPROTONOSUPPORT => EPROTONOSUPPORT, + libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT, + libc::EADDRNOTAVAIL => EADDRNOTAVAIL, + libc::ENETRESET => ENETRESET, + libc::EISCONN => EISCONN, + libc::ENOTCONN => ENOTCONN, + libc::ETOOMANYREFS => ETOOMANYREFS, + libc::EPROCLIM => EPROCLIM, + libc::EUSERS => EUSERS, + libc::EDQUOT => EDQUOT, + libc::ESTALE => ESTALE, + libc::ENOTSUP => ENOTSUP, + libc::ENOMEDIUM => ENOMEDIUM, + libc::EILSEQ => EILSEQ, + libc::EOVERFLOW => EOVERFLOW, + libc::ECANCELED => ECANCELED, + libc::ENOTRECOVERABLE => ENOTRECOVERABLE, + libc::EOWNERDEAD => EOWNERDEAD, + libc::ESTRPIPE => ESTRPIPE, + _ => UnknownErrno, + } + } +} diff --git a/src/fcntl.rs b/src/fcntl.rs index 68140966a3..13ee1919ca 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -128,7 +128,8 @@ libc_bitflags!( #[cfg(not(any( solarish, target_os = "aix", - target_os = "haiku" + target_os = "haiku", + target_os = "cygwin" )))] O_ASYNC; /// Closes the file descriptor once an `execve` call is made. @@ -173,7 +174,7 @@ libc_bitflags!( #[cfg(not(target_os = "redox"))] O_NOCTTY; /// Same as `O_NONBLOCK`. - #[cfg(not(any(target_os = "redox", target_os = "haiku")))] + #[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "cygwin")))] O_NDELAY; /// `open()` will fail if the given path is a symbolic link. O_NOFOLLOW; diff --git a/src/sys/resource.rs b/src/sys/resource.rs index 73d8a05e0f..449698dbe2 100644 --- a/src/sys/resource.rs +++ b/src/sys/resource.rs @@ -19,7 +19,8 @@ cfg_if! { bsd, target_os = "android", target_os = "aix", - all(target_os = "linux", not(target_env = "gnu")) + all(target_os = "linux", not(target_env = "gnu")), + target_os = "cygwin" ))]{ use libc::rlimit; } @@ -49,7 +50,8 @@ libc_enum! { bsd, target_os = "android", target_os = "aix", - all(target_os = "linux", not(any(target_env = "gnu", target_env = "uclibc"))) + all(target_os = "linux", not(any(target_env = "gnu", target_env = "uclibc"))), + target_os = "cygwin" ), repr(i32))] #[non_exhaustive] pub enum Resource { diff --git a/src/unistd.rs b/src/unistd.rs index 4bb715b707..172cb4a6b0 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -16,6 +16,7 @@ use crate::fcntl::AtFlags; target_os = "fuchsia", target_os = "hurd", target_os = "redox", + target_os = "cygwin", ))] use crate::fcntl::OFlag; #[cfg(all(feature = "fs", bsd))] @@ -1494,6 +1495,7 @@ feature! { target_os = "hurd", target_os = "redox", netbsdlike, + target_os = "cygwin", ))] pub fn pipe2(flags: OFlag) -> Result<(std::os::fd::OwnedFd, std::os::fd::OwnedFd)> { let mut fds = mem::MaybeUninit::<[std::os::fd::OwnedFd; 2]>::uninit(); From 1cb3fab2ea481259d7aeb2e486e67ae5bccb7835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Fri, 7 Mar 2025 23:42:56 +0800 Subject: [PATCH 02/14] Remove no_mangle --- src/errno.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/errno.rs b/src/errno.rs index 0d9d2d0fa0..d7d3926d30 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -25,7 +25,6 @@ cfg_if! { unsafe { libc::__error() } } } else if #[cfg(any(target_os = "android", netbsdlike, target_os = "cygwin"))] { - #[cfg_attr(target_os = "cygwin", no_mangle)] unsafe fn errno_location() -> *mut c_int { unsafe { libc::__errno() } } From 174890720bf640ccb8dcdd8556f697d30363f764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Fri, 7 Mar 2025 23:52:09 +0800 Subject: [PATCH 03/14] Add check-cfg for cygwin target --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index 6586cee48e..eb279438f5 100644 --- a/build.rs +++ b/build.rs @@ -30,4 +30,6 @@ fn main() { // Below are custom cfg values set during some CI steps. println!("cargo:rustc-check-cfg=cfg(fbsd14)"); println!("cargo:rustc-check-cfg=cfg(qemu)"); + // Cygwin target, added in 1.86 + println!("cargo:rustc-check-cfg=cfg(target_os, values(\"cygwin\"))"); } From f0e9e406bd04f19fa77034245ae4462c390205ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sat, 8 Mar 2025 23:34:39 +0800 Subject: [PATCH 04/14] feat: full cygwin support --- src/dir.rs | 1 + src/features.rs | 1 + src/net/if_.rs | 13 ++++++++----- src/sys/mman.rs | 8 ++++---- src/sys/signal.rs | 13 ++++++++----- src/sys/socket/addr.rs | 13 +++++++++---- src/sys/socket/mod.rs | 14 +++++++++----- src/sys/socket/sockopt.rs | 5 +++-- src/sys/termios.rs | 6 +++--- src/sys/uio.rs | 4 ++-- src/syslog.rs | 2 +- src/unistd.rs | 16 +++++++++++++--- 12 files changed, 62 insertions(+), 34 deletions(-) diff --git a/src/dir.rs b/src/dir.rs index d146b4f126..b514212e60 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -287,6 +287,7 @@ impl Entry { target_os = "fuchsia", target_os = "haiku", target_os = "hurd", + target_os = "cygwin", solarish, linux_android, apple_targets))] { diff --git a/src/features.rs b/src/features.rs index b71d42e83c..b472f803a7 100644 --- a/src/features.rs +++ b/src/features.rs @@ -103,6 +103,7 @@ mod os { target_os = "hurd", // Since glibc 2.28 target_os = "illumos", // Since ??? target_os = "redox", // Since 1-july-2020 + target_os = "cygwin", ))] mod os { /// Check if the OS supports atomic close-on-exec for sockets diff --git a/src/net/if_.rs b/src/net/if_.rs index 5b6c2e77a5..cae6e3f826 100644 --- a/src/net/if_.rs +++ b/src/net/if_.rs @@ -51,7 +51,7 @@ libc_bitflags!( IFF_BROADCAST as IflagsType; /// Internal debugging flag. (see /// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html)) - #[cfg(not(target_os = "haiku"))] + #[cfg(not(any(target_os = "haiku", target_os = "cygwin")))] IFF_DEBUG as IflagsType; /// Interface is a loopback interface. (see /// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html)) @@ -66,7 +66,8 @@ libc_bitflags!( solarish, apple_targets, target_os = "fuchsia", - target_os = "netbsd"))] + target_os = "netbsd", + target_os = "cygwin"))] IFF_NOTRAILERS as IflagsType; /// Interface manages own routes. #[cfg(any(target_os = "dragonfly"))] @@ -77,7 +78,8 @@ libc_bitflags!( linux_android, bsd, solarish, - target_os = "fuchsia"))] + target_os = "fuchsia", + target_os = "cygwin"))] IFF_RUNNING as IflagsType; /// No arp protocol, L2 destination address not set. (see /// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html)) @@ -87,6 +89,7 @@ libc_bitflags!( IFF_PROMISC as IflagsType; /// Receive all multicast packets. (see /// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html)) + #[cfg(not(target_os = "cygwin"))] IFF_ALLMULTI as IflagsType; /// Master of a load balancing bundle. (see /// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html)) @@ -145,7 +148,7 @@ libc_bitflags!( #[cfg(solarish)] IFF_PRIVATE as IflagsType; /// Driver signals L1 up. Volatile. - #[cfg(any(target_os = "fuchsia", target_os = "linux"))] + #[cfg(any(target_os = "fuchsia", target_os = "linux", target_os = "cygwin"))] IFF_LOWER_UP; /// Interface is in polling mode. #[cfg(any(target_os = "dragonfly"))] @@ -157,7 +160,7 @@ libc_bitflags!( #[cfg(solarish)] IFF_NOXMIT as IflagsType; /// Driver signals dormant. Volatile. - #[cfg(any(target_os = "fuchsia", target_os = "linux"))] + #[cfg(any(target_os = "fuchsia", target_os = "linux", target_os = "cygwin"))] IFF_DORMANT; /// User-requested promisc mode. #[cfg(freebsdlike)] diff --git a/src/sys/mman.rs b/src/sys/mman.rs index ac142316b1..06507ef65b 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -281,7 +281,7 @@ libc_enum! { #[cfg(linux_android)] MADV_DODUMP, /// Specify that the application no longer needs the pages in the given range. - #[cfg(not(any(target_os = "aix", target_os = "hurd")))] + #[cfg(not(any(target_os = "aix", target_os = "hurd", target_os = "cygwin")))] MADV_FREE, /// Request that the system not flush the current range to disk unless it needs to. #[cfg(freebsdlike)] @@ -357,7 +357,7 @@ libc_bitflags! { } } -#[cfg(not(target_os = "haiku"))] +#[cfg(not(any(target_os = "haiku", target_os = "cygwin")))] libc_bitflags! { /// Flags for [`mlockall`]. pub struct MlockAllFlags: c_int { @@ -400,7 +400,7 @@ pub unsafe fn munlock(addr: NonNull, length: size_t) -> Result<()> { /// Locked pages never move to the swap area. For more information, see [`mlockall(2)`]. /// /// [`mlockall(2)`]: https://man7.org/linux/man-pages/man2/mlockall.2.html -#[cfg(not(target_os = "haiku"))] +#[cfg(not(any(target_os = "haiku", target_os = "cygwin")))] pub fn mlockall(flags: MlockAllFlags) -> Result<()> { unsafe { Errno::result(libc::mlockall(flags.bits())) }.map(drop) } @@ -410,7 +410,7 @@ pub fn mlockall(flags: MlockAllFlags) -> Result<()> { /// For more information, see [`munlockall(2)`]. /// /// [`munlockall(2)`]: https://man7.org/linux/man-pages/man2/munlockall.2.html -#[cfg(not(target_os = "haiku"))] +#[cfg(not(any(target_os = "haiku", target_os = "cygwin")))] pub fn munlockall() -> Result<()> { unsafe { Errno::result(libc::munlockall()) }.map(drop) } diff --git a/src/sys/signal.rs b/src/sys/signal.rs index c1a2ac6deb..bc920dbf17 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -111,7 +111,7 @@ libc_enum! { #[cfg(not(any(linux_android, target_os = "emscripten", target_os = "fuchsia", target_os = "redox", target_os = "haiku", target_os = "aix", - target_os = "solaris")))] + target_os = "solaris", target_os = "cygwin")))] /// Information request SIGINFO, } @@ -190,7 +190,8 @@ impl FromStr for Signal { target_os = "redox", target_os = "aix", target_os = "haiku", - target_os = "solaris" + target_os = "solaris", + target_os = "cygwin" )))] "SIGINFO" => Signal::SIGINFO, _ => return Err(Errno::EINVAL), @@ -275,7 +276,8 @@ impl Signal { target_os = "redox", target_os = "aix", target_os = "haiku", - target_os = "solaris" + target_os = "solaris", + target_os = "cygwin" )))] Signal::SIGINFO => "SIGINFO", } @@ -359,7 +361,7 @@ const SIGNALS: [Signal; 30] = [ SIGURG, SIGPOLL, SIGIO, SIGSTOP, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU, SIGVTALRM, SIGPROF, SIGXCPU, SIGXFSZ, SIGTRAP, ]; -#[cfg(target_os = "solaris")] +#[cfg(any(target_os = "solaris", target_os = "cygwin"))] #[cfg(feature = "signal")] const SIGNALS: [Signal; 30] = [ SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL, @@ -374,7 +376,8 @@ const SIGNALS: [Signal; 30] = [ target_os = "aix", target_os = "redox", target_os = "haiku", - target_os = "solaris" + target_os = "solaris", + target_os = "cygwin" )))] #[cfg(feature = "signal")] const SIGNALS: [Signal; 31] = [ diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index ac3a234704..fdaff3660b 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -66,7 +66,7 @@ pub enum AddressFamily { #[cfg(linux_android)] Netlink = libc::AF_NETLINK, /// Kernel interface for interacting with the routing table - #[cfg(not(any(linux_android, target_os = "redox")))] + #[cfg(not(any(linux_android, target_os = "redox", target_os = "cygwin")))] Route = libc::PF_ROUTE, /// Low level packet interface (see [`packet(7)`](https://man7.org/linux/man-pages/man7/packet.7.html)) #[cfg(any(linux_android, solarish, target_os = "fuchsia"))] @@ -78,7 +78,7 @@ pub enum AddressFamily { #[cfg(linux_android)] Ax25 = libc::AF_AX25, /// IPX - Novell protocols - #[cfg(not(any(target_os = "aix", target_os = "redox")))] + #[cfg(not(any(target_os = "aix", target_os = "redox", target_os = "cygwin")))] Ipx = libc::AF_IPX, /// AppleTalk #[cfg(not(target_os = "redox"))] @@ -164,6 +164,7 @@ pub enum AddressFamily { apple_targets, target_os = "hurd", target_os = "redox", + target_os = "cygwin", )))] Bluetooth = libc::AF_BLUETOOTH, /// IUCV (inter-user communication vehicle) z/VM protocol for @@ -180,6 +181,7 @@ pub enum AddressFamily { target_os = "haiku", target_os = "hurd", target_os = "redox", + target_os = "cygwin", )))] Isdn = libc::AF_ISDN, /// Nokia cellular modem IPC/RPC interface @@ -263,7 +265,7 @@ impl AddressFamily { libc::AF_NETLINK => Some(AddressFamily::Netlink), #[cfg(apple_targets)] libc::AF_SYSTEM => Some(AddressFamily::System), - #[cfg(not(any(linux_android, target_os = "redox")))] + #[cfg(not(any(linux_android, target_os = "redox", target_os = "cygwin")))] libc::PF_ROUTE => Some(AddressFamily::Route), #[cfg(linux_android)] libc::AF_PACKET => Some(AddressFamily::Packet), @@ -446,6 +448,7 @@ impl UnixAddr { target_os = "fuchsia", solarish, target_os = "redox", + target_os = "cygwin", ))] { UnixAddr { sun, sun_len } @@ -510,6 +513,7 @@ impl UnixAddr { target_os = "fuchsia", solarish, target_os = "redox", + target_os = "cygwin", ))] { self.sun_len @@ -556,6 +560,7 @@ impl SockaddrLike for UnixAddr { target_os = "fuchsia", solarish, target_os = "redox", + target_os = "cygwin", ))] { let su_len = len.unwrap_or( mem::size_of::() as libc::socklen_t @@ -1122,7 +1127,7 @@ pub union SockaddrStorage { alg: AlgAddr, #[cfg(all( feature = "net", - not(any(target_os = "hurd", target_os = "redox")) + not(any(target_os = "hurd", target_os = "redox", target_os = "cygwin")) ))] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] dl: LinkAddr, diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index e26e327d78..ffea1144b0 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -43,7 +43,8 @@ pub use self::addr::{AddressFamily, UnixAddr}; solarish, target_os = "haiku", target_os = "hurd", - target_os = "redox" + target_os = "redox", + target_os = "cygwin", )))] #[cfg(feature = "net")] pub use self::addr::{LinkAddr, SockaddrIn, SockaddrIn6}; @@ -51,7 +52,8 @@ pub use self::addr::{LinkAddr, SockaddrIn, SockaddrIn6}; solarish, target_os = "haiku", target_os = "hurd", - target_os = "redox" + target_os = "redox", + target_os = "cygwin", ))] #[cfg(feature = "net")] pub use self::addr::{SockaddrIn, SockaddrIn6}; @@ -1023,7 +1025,7 @@ impl ControlMessageOwned { let cred: libc::cmsgcred = unsafe { ptr::read_unaligned(p as *const _) }; ControlMessageOwned::ScmCreds(cred.into()) } - #[cfg(not(any(target_os = "aix", target_os = "haiku")))] + #[cfg(not(any(target_os = "aix", target_os = "haiku", target_os = "cygwin")))] (libc::SOL_SOCKET, libc::SCM_TIMESTAMP) => { let tv: libc::timeval = unsafe { ptr::read_unaligned(p as *const _) }; ControlMessageOwned::ScmTimestamp(TimeVal::from(tv)) @@ -1372,13 +1374,15 @@ impl ControlMessage<'_> { /// The value of CMSG_LEN on this message. /// Safe because CMSG_LEN is always safe #[cfg(any(target_os = "android", - all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos")))))] + all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos"))), + target_os = "cygwin"))] fn cmsg_len(&self) -> usize { unsafe{CMSG_LEN(self.len() as libc::c_uint) as usize} } #[cfg(not(any(target_os = "android", - all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos"))))))] + all(target_os = "linux", not(any(target_env = "musl", target_env = "ohos"))), + target_os = "cygwin")))] fn cmsg_len(&self) -> libc::c_uint { unsafe{CMSG_LEN(self.len() as libc::c_uint)} } diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 11c3be9e13..f1bebddfaf 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -298,7 +298,7 @@ sockopt_impl!( libc::SO_REUSEADDR, bool ); -#[cfg(not(solarish))] +#[cfg(not(any(solarish, target_os = "cygwin")))] sockopt_impl!( /// Permits multiple AF_INET or AF_INET6 sockets to be bound to an /// identical socket address. @@ -883,7 +883,8 @@ sockopt_impl!( target_os = "aix", target_os = "haiku", target_os = "hurd", - target_os = "redox" + target_os = "redox", + target_os = "cygwin" )))] sockopt_impl!( /// Enable or disable the receiving of the `SO_TIMESTAMP` control message. diff --git a/src/sys/termios.rs b/src/sys/termios.rs index b69bc178d8..b2415c0aff 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -667,7 +667,7 @@ libc_bitflags! { ECHOK; ECHO; ECHONL; - #[cfg(not(target_os = "redox"))] + #[cfg(not(any(target_os = "redox", target_os = "cygwin")))] ECHOPRT; #[cfg(not(target_os = "redox"))] ECHOCTL; @@ -676,14 +676,14 @@ libc_bitflags! { #[cfg(bsd)] ALTWERASE; IEXTEN; - #[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "aix")))] + #[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "aix", target_os = "cygwin")))] EXTPROC; TOSTOP; #[cfg(not(target_os = "redox"))] FLUSHO; #[cfg(bsd)] NOKERNINFO; - #[cfg(not(target_os = "redox"))] + #[cfg(not(any(target_os = "redox", target_os = "cygwin")))] PENDIN; NOFLSH; } diff --git a/src/sys/uio.rs b/src/sys/uio.rs index cdf380dd11..f47083cba4 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -53,7 +53,7 @@ pub fn readv(fd: Fd, iov: &mut [IoSliceMut<'_>]) -> Result { /// or an error occurs. The file offset is not changed. /// /// See also: [`writev`](fn.writev.html) and [`pwrite`](fn.pwrite.html) -#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris")))] +#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris", target_os = "cygwin")))] pub fn pwritev( fd: Fd, iov: &[IoSlice<'_>], @@ -82,7 +82,7 @@ pub fn pwritev( /// changed. /// /// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html) -#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris")))] +#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "solaris", target_os = "cygwin")))] // Clippy doesn't know that we need to pass iov mutably only because the // mutation happens after converting iov to a pointer #[allow(clippy::needless_pass_by_ref_mut)] diff --git a/src/syslog.rs b/src/syslog.rs index 05143252d4..7894978029 100644 --- a/src/syslog.rs +++ b/src/syslog.rs @@ -215,7 +215,7 @@ libc_bitflags! { /// which file descriptors are allocated. LOG_NDELAY; /// Write the message to standard error output as well to the system log. - #[cfg(not(any(solarish, target_os = "redox")))] + #[cfg(not(any(solarish, target_os = "redox", target_os = "cygwin")))] LOG_PERROR; } } diff --git a/src/unistd.rs b/src/unistd.rs index 172cb4a6b0..8995fbe02e 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1945,7 +1945,8 @@ pub fn setgroups(groups: &[Gid]) -> Result<()> { cfg_if! { if #[cfg(any(bsd, solarish, - target_os = "aix"))] { + target_os = "aix", + target_os = "cygwin"))] { type setgroups_ngroups_t = c_int; } else { type setgroups_ngroups_t = size_t; @@ -2208,7 +2209,7 @@ feature! { #![feature = "acct"] /// Process accounting -#[cfg(not(any(target_os = "redox", target_os = "haiku")))] +#[cfg(not(any(target_os = "redox", target_os = "haiku", target_os = "cygwin")))] pub mod acct { use crate::errno::Errno; use crate::{NixPath, Result}; @@ -3499,6 +3500,7 @@ pub struct User { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] pub class: CString, /// Last password change @@ -3510,6 +3512,7 @@ pub struct User { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] pub change: libc::time_t, /// Expiration time of account @@ -3521,6 +3524,7 @@ pub struct User { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] pub expire: libc::time_t, } @@ -3575,6 +3579,7 @@ impl From<&libc::passwd> for User { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] class: CString::new(CStr::from_ptr(pw.pw_class).to_bytes()) .unwrap(), @@ -3586,6 +3591,7 @@ impl From<&libc::passwd> for User { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] change: pw.pw_change, #[cfg(not(any( @@ -3596,6 +3602,7 @@ impl From<&libc::passwd> for User { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] expire: pw.pw_expire, } @@ -3638,6 +3645,7 @@ impl From for libc::passwd { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] pw_class: u.class.into_raw(), #[cfg(not(any( @@ -3648,6 +3656,7 @@ impl From for libc::passwd { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] pw_change: u.change, #[cfg(not(any( @@ -3658,11 +3667,12 @@ impl From for libc::passwd { target_os = "haiku", target_os = "hurd", target_os = "emscripten", + target_os = "cygwin", )))] pw_expire: u.expire, #[cfg(solarish)] pw_age: CString::new("").unwrap().into_raw(), - #[cfg(solarish)] + #[cfg(any(solarish, target_os = "cygwin"))] pw_comment: CString::new("").unwrap().into_raw(), #[cfg(freebsdlike)] pw_fields: 0, From 2cc5c7674ead64611e9d24b55ca0b97fa1d52657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Tue, 11 Mar 2025 22:52:15 +0800 Subject: [PATCH 05/14] feat: update libc to add cygwin support --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c6690d46ef..559f0b6a45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ targets = [ ] [dependencies] -libc = { version = "0.2.166", features = ["extra_traits"] } +libc = { version = "0.2.171", features = ["extra_traits"] } bitflags = "2.3.3" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } From e0f3f24be6ba0799a3db2f953c98d19abe4d2d58 Mon Sep 17 00:00:00 2001 From: Berrysoft Date: Wed, 12 Mar 2025 13:09:53 +0800 Subject: [PATCH 06/14] feat: add statfs support for cygwin --- src/sys/mod.rs | 2 +- src/sys/statfs.rs | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/sys/mod.rs b/src/sys/mod.rs index d4ad851f35..95ad68b4ad 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -137,7 +137,7 @@ feature! { pub mod stat; } -#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "openbsd"))] +#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "openbsd", target_os = "cygwin"))] feature! { #![feature = "fs"] pub mod statfs; diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs index 3b019dbd05..c0a9f6c993 100644 --- a/src/sys/statfs.rs +++ b/src/sys/statfs.rs @@ -1,7 +1,7 @@ //! Get filesystem statistics, non-portably //! //! See [`statvfs`](crate::sys::statvfs) for a portable alternative. -#[cfg(not(linux_android))] +#[cfg(not(any(linux_android, target_os = "cygwin")))] use std::ffi::CStr; use std::fmt::{self, Debug}; use std::mem; @@ -19,8 +19,11 @@ use crate::{errno::Errno, NixPath, Result}; #[cfg(target_os = "android")] pub type fsid_t = libc::__fsid_t; /// Identifies a mounted file system -#[cfg(not(target_os = "android"))] +#[cfg(not(any(target_os = "android", target_os = "cygwin")))] pub type fsid_t = libc::fsid_t; +/// Identifies a mounted file system +#[cfg(target_os = "cygwin")] +pub type fsid_t = libc::c_long; cfg_if! { if #[cfg(any(linux_android, target_os = "fuchsia"))] { @@ -71,6 +74,8 @@ type fs_type_t = libc::c_int; )) ))] type fs_type_t = libc::__fsword_t; +#[cfg(target_os = "cygwin")] +type fs_type_t = libc::c_long; /// Describes the file system type as known by the operating system. #[cfg(any( @@ -83,6 +88,7 @@ type fs_type_t = libc::__fsword_t; target_os = "linux", not(any(target_arch = "s390x", target_env = "musl")) ), + target_os = "cygwin", ))] #[derive(Eq, Copy, Clone, PartialEq, Debug)] pub struct FsType(pub fs_type_t); @@ -301,7 +307,7 @@ impl Statfs { } /// Magic code defining system type - #[cfg(not(linux_android))] + #[cfg(not(any(linux_android, target_os = "cygwin")))] pub fn filesystem_type_name(&self) -> &str { let c_str = unsafe { CStr::from_ptr(self.0.f_fstypename.as_ptr()) }; c_str.to_str().unwrap() @@ -437,7 +443,7 @@ impl Statfs { } /// Size of a block - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "cygwin"))] pub fn block_size(&self) -> libc::c_long { self.0.f_bsize } @@ -518,7 +524,7 @@ impl Statfs { } /// Total data blocks in filesystem - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "cygwin"))] pub fn blocks(&self) -> libc::c_long { self.0.f_blocks } @@ -542,7 +548,7 @@ impl Statfs { } /// Free blocks in filesystem - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "cygwin"))] pub fn blocks_free(&self) -> libc::c_long { self.0.f_bfree } @@ -560,7 +566,7 @@ impl Statfs { } /// Free blocks available to unprivileged user - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "cygwin"))] pub fn blocks_available(&self) -> libc::c_long { self.0.f_bavail } @@ -590,7 +596,7 @@ impl Statfs { } /// Total file nodes in filesystem - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "cygwin"))] pub fn files(&self) -> libc::c_long { self.0.f_files } @@ -613,7 +619,7 @@ impl Statfs { } /// Free file nodes in filesystem - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "cygwin"))] pub fn files_free(&self) -> libc::c_long { self.0.f_ffree } @@ -639,6 +645,7 @@ impl Statfs { impl Debug for Statfs { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut ds = f.debug_struct("Statfs"); + #[cfg(not(target_os = "cygwin"))] ds.field("optimal_transfer_size", &self.optimal_transfer_size()); ds.field("block_size", &self.block_size()); ds.field("blocks", &self.blocks()); From 821d7c9771c5835f45f70fee6fdcf2f7b3a3b5e4 Mon Sep 17 00:00:00 2001 From: Berrysoft Date: Wed, 12 Mar 2025 14:34:50 +0800 Subject: [PATCH 07/14] fix: some tests for cygwin --- src/sys/socket/addr.rs | 10 +++++++--- test/sys/mod.rs | 3 ++- test/sys/test_pthread.rs | 10 ++++++++-- test/sys/test_resource.rs | 1 + test/sys/test_socket.rs | 3 ++- test/sys/test_uio.rs | 6 ++++-- test/test_unistd.rs | 3 ++- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index fdaff3660b..bb6c54fd21 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -530,7 +530,8 @@ impl SockaddrLike for UnixAddr { linux_android, target_os = "fuchsia", solarish, - target_os = "redox" + target_os = "redox", + target_os = "cygwin", ))] fn len(&self) -> libc::socklen_t { self.sun_len.into() @@ -1171,6 +1172,7 @@ impl SockaddrLike for SockaddrStorage { linux_android, target_os = "fuchsia", solarish, + target_os = "cygwin", ))] if i32::from(ss.ss_family) == libc::AF_UNIX { // Safe because we UnixAddr is strictly smaller than @@ -1227,7 +1229,7 @@ impl SockaddrLike for SockaddrStorage { } } - #[cfg(any(linux_android, target_os = "fuchsia", solarish))] + #[cfg(any(linux_android, target_os = "fuchsia", solarish, target_os = "cygwin"))] fn len(&self) -> libc::socklen_t { match self.as_unix_addr() { // The UnixAddr type knows its own length @@ -1289,6 +1291,7 @@ impl SockaddrStorage { if #[cfg(any(linux_android, target_os = "fuchsia", solarish, + target_os = "cygwin", ))] { let p = unsafe{ &self.ss as *const libc::sockaddr_storage }; @@ -1318,6 +1321,7 @@ impl SockaddrStorage { if #[cfg(any(linux_android, target_os = "fuchsia", solarish, + target_os = "cygwin", ))] { let p = unsafe{ &self.ss as *const libc::sockaddr_storage }; @@ -2193,7 +2197,7 @@ mod tests { } } - #[cfg(not(any(target_os = "hurd", target_os = "redox")))] + #[cfg(not(any(target_os = "hurd", target_os = "redox", target_os = "cygwin")))] #[allow(clippy::cast_ptr_alignment)] mod link { #[cfg(any(apple_targets, solarish))] diff --git a/test/sys/mod.rs b/test/sys/mod.rs index 63b256298e..ab7c5167ce 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -19,7 +19,8 @@ mod test_aio; target_os = "redox", target_os = "fuchsia", target_os = "haiku", - target_os = "hurd" + target_os = "hurd", + target_os = "cygwin" )))] mod test_ioctl; #[cfg(not(target_os = "redox"))] diff --git a/test/sys/test_pthread.rs b/test/sys/test_pthread.rs index 5af128ce63..0403ffad31 100644 --- a/test/sys/test_pthread.rs +++ b/test/sys/test_pthread.rs @@ -1,6 +1,11 @@ use nix::sys::pthread::*; -#[cfg(any(target_env = "musl", target_os = "redox", target_env = "ohos"))] +#[cfg(any( + target_env = "musl", + target_os = "redox", + target_env = "ohos", + target_os = "cygwin" +))] #[test] fn test_pthread_self() { let tid = pthread_self(); @@ -10,7 +15,8 @@ fn test_pthread_self() { #[cfg(not(any( target_env = "musl", target_os = "redox", - target_env = "ohos" + target_env = "ohos", + target_os = "cygwin" )))] #[test] fn test_pthread_self() { diff --git a/test/sys/test_resource.rs b/test/sys/test_resource.rs index 8b12a9495b..102b1b57d8 100644 --- a/test/sys/test_resource.rs +++ b/test/sys/test_resource.rs @@ -10,6 +10,7 @@ use nix::sys::resource::{getrusage, UsageWho}; /// to put the new soft limit in effect, and then getrlimit() once more to ensure the limits have /// been updated. #[test] +#[cfg_attr(target_os = "cygwin", ignore)] pub fn test_resource_limits_nofile() { let (mut soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_NOFILE).unwrap(); diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 5a43aab437..5f1a8cdff3 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1707,6 +1707,7 @@ pub fn test_listen_maxbacklog() { pub fn test_listen_wrongbacklog() { use nix::sys::socket::Backlog; + #[cfg(not(target_os = "cygwin"))] assert!(Backlog::new(libc::SOMAXCONN + 1).is_err()); assert!(Backlog::new(-2).is_err()); } @@ -3152,7 +3153,7 @@ fn can_use_cmsg_space() { let _ = cmsg_space!(u8); } -#[cfg(not(any(linux_android, target_os = "redox", target_os = "haiku")))] +#[cfg(not(any(linux_android, target_os = "redox", target_os = "haiku", target_os = "cygwin")))] #[test] fn can_open_routing_socket() { use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType}; diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index 22248db141..43f2f7a01e 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -144,7 +144,8 @@ fn test_pread() { #[cfg(not(any( target_os = "redox", target_os = "haiku", - target_os = "solaris" + target_os = "solaris", + target_os = "cygwin" )))] fn test_pwritev() { use std::io::Read; @@ -183,7 +184,8 @@ fn test_pwritev() { #[cfg(not(any( target_os = "redox", target_os = "haiku", - target_os = "solaris" + target_os = "solaris", + target_os = "cygwin" )))] fn test_preadv() { use std::io::Write; diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 19b9f94284..2c54c4757c 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -631,7 +631,8 @@ cfg_if! { #[cfg(not(any( target_os = "redox", target_os = "fuchsia", - target_os = "haiku" + target_os = "haiku", + target_os = "cygwin" )))] fn test_acct() { use std::process::Command; From 70781c63465adfe4f4b9dfaaa65ecf21fb94e51a Mon Sep 17 00:00:00 2001 From: Berrysoft Date: Thu, 13 Mar 2025 16:22:44 +0800 Subject: [PATCH 08/14] fix: ignore failed tests on cygwin --- test/sys/test_socket.rs | 3 +++ test/sys/test_sockopt.rs | 1 + test/sys/test_stat.rs | 5 +++++ test/test_fcntl.rs | 1 + test/test_net.rs | 2 ++ test/test_unistd.rs | 4 ++++ 6 files changed, 16 insertions(+) diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 5f1a8cdff3..a8b966fd64 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -327,6 +327,7 @@ pub fn test_socketpair() { } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] pub fn test_recvmsg_sockaddr_un() { use nix::sys::socket::{ self, bind, socket, AddressFamily, MsgFlags, SockFlag, SockType, @@ -841,6 +842,7 @@ pub fn test_recvmsg_ebadf() { // 2.12.0. https://bugs.launchpad.net/qemu/+bug/1701808 #[cfg_attr(qemu, ignore)] #[test] +#[cfg_attr(target_os = "cygwin", ignore)] pub fn test_scm_rights() { use nix::sys::socket::{ recvmsg, sendmsg, socketpair, AddressFamily, ControlMessage, @@ -1327,6 +1329,7 @@ pub fn test_sendmsg_ipv4sendsrcaddr() { // 2.12.0. https://bugs.launchpad.net/qemu/+bug/1701808 #[cfg_attr(qemu, ignore)] #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_scm_rights_single_cmsg_multiple_fds() { use nix::sys::socket::{ recvmsg, sendmsg, ControlMessage, ControlMessageOwned, MsgFlags, diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs index 42697ffa24..1a5e1cdac6 100644 --- a/test/sys/test_sockopt.rs +++ b/test/sys/test_sockopt.rs @@ -159,6 +159,7 @@ fn test_so_listen_q_limit() { } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_so_tcp_maxseg() { use nix::sys::socket::{ accept, bind, connect, getsockname, listen, Backlog, SockaddrIn, diff --git a/test/sys/test_stat.rs b/test/sys/test_stat.rs index fed517cf76..8d3adf7928 100644 --- a/test/sys/test_stat.rs +++ b/test/sys/test_stat.rs @@ -145,6 +145,7 @@ fn test_stat_fstat_lstat() { } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_fchmod() { let tempdir = tempfile::tempdir().unwrap(); let filename = tempdir.path().join("foo.txt"); @@ -168,6 +169,7 @@ fn test_fchmod() { #[test] #[cfg(not(target_os = "redox"))] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_fchmodat() { let _dr = crate::DirRestore::new(); let tempdir = tempfile::tempdir().unwrap(); @@ -331,6 +333,7 @@ fn test_mkdirat_success_path() { #[test] #[cfg(not(any(target_os = "redox", target_os = "haiku")))] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_mkdirat_success_mode() { let expected_bits = stat::SFlag::S_IFDIR.bits() | stat::Mode::S_IRWXU.bits(); @@ -371,6 +374,7 @@ fn test_mkdirat_fail() { target_os = "redox", target_os = "solaris" )))] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_mknod() { use stat::{lstat, mknod, SFlag}; @@ -391,6 +395,7 @@ fn test_mknod() { target_os = "haiku", target_os = "redox" )))] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_mknodat() { use fcntl::{AtFlags, OFlag}; use nix::dir::Dir; diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 76c3b9f2dc..bbbcb604e5 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -243,6 +243,7 @@ fn test_renameat2_noreplace() { #[test] #[cfg(not(target_os = "redox"))] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_readlink() { let tempdir = tempfile::tempdir().unwrap(); let src = tempdir.path().join("a"); diff --git a/test/test_net.rs b/test/test_net.rs index 46a3efd501..be86b65d30 100644 --- a/test/test_net.rs +++ b/test/test_net.rs @@ -10,11 +10,13 @@ const LOOPBACK: &[u8] = b"lo0"; const LOOPBACK: &[u8] = b"loop"; #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_if_nametoindex() { if_nametoindex(LOOPBACK).expect("assertion failed"); } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_if_indextoname() { let loopback_index = if_nametoindex(LOOPBACK).expect("assertion failed"); assert_eq!( diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 2c54c4757c..681368e113 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -516,6 +516,7 @@ fn test_getcwd() { } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_chown() { // Testing for anything other than our own UID/GID is hard. let uid = Some(getuid()); @@ -550,6 +551,7 @@ fn test_fchown() { #[test] #[cfg(not(target_os = "redox"))] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_fchownat() { use nix::fcntl::AtFlags; use nix::fcntl::AT_FDCWD; @@ -868,6 +870,7 @@ fn test_canceling_alarm() { #[test] #[cfg(not(any(target_os = "redox", target_os = "haiku")))] +#[cfg_attr(target_os = "cygwin", ignore)] fn test_symlinkat() { use nix::fcntl::AT_FDCWD; @@ -1221,6 +1224,7 @@ fn test_access_file_exists() { } #[cfg(not(target_os = "redox"))] +#[cfg_attr(target_os = "cygwin", ignore)] #[test] fn test_user_into_passwd() { // get the UID of the "nobody" user From 83f0e89b1e75a782bc204da4a9c5ac8022b79e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Tue, 18 Mar 2025 15:05:41 +0800 Subject: [PATCH 09/14] Fix deprecated warnings --- test/sys/test_sockopt.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs index 1a5e1cdac6..a367aa0aba 100644 --- a/test/sys/test_sockopt.rs +++ b/test/sys/test_sockopt.rs @@ -242,6 +242,7 @@ fn test_so_type_unknown() { use nix::errno::Errno; require_capability!("test_so_type", CAP_NET_RAW); + #[allow(deprecated)] let raw_fd = unsafe { libc::socket(libc::AF_PACKET, libc::SOCK_PACKET, 0) }; assert!(raw_fd >= 0, "Error opening socket: {}", nix::Error::last()); let sockfd = unsafe { OwnedFd::from_raw_fd(raw_fd) }; From 99b87bd7075c37218430f2786d901a6bfdc925b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Tue, 18 Mar 2025 15:06:46 +0800 Subject: [PATCH 10/14] Format code --- src/sys/mod.rs | 8 +++++++- test/sys/test_socket.rs | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 95ad68b4ad..17b033170d 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -137,7 +137,13 @@ feature! { pub mod stat; } -#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "openbsd", target_os = "cygwin"))] +#[cfg(any( + linux_android, + freebsdlike, + apple_targets, + target_os = "openbsd", + target_os = "cygwin" +))] feature! { #![feature = "fs"] pub mod statfs; diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index a8b966fd64..95598f470c 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -3156,7 +3156,12 @@ fn can_use_cmsg_space() { let _ = cmsg_space!(u8); } -#[cfg(not(any(linux_android, target_os = "redox", target_os = "haiku", target_os = "cygwin")))] +#[cfg(not(any( + linux_android, + target_os = "redox", + target_os = "haiku", + target_os = "cygwin" +)))] #[test] fn can_open_routing_socket() { use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType}; From c6fe2f28f58e9908dbbc40895a830ac9b4276815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Fri, 21 Mar 2025 12:11:28 +0800 Subject: [PATCH 11/14] fix: mark from_i32 pub(crate) --- src/errno.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errno.rs b/src/errno.rs index d7d3926d30..497e33dbbf 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -3727,7 +3727,7 @@ mod consts { pub const EOPNOTSUPP: Errno = Errno::ENOTSUP; } - pub const fn from_i32(e: i32) -> Errno { + pub(crate) const fn from_i32(e: i32) -> Errno { use self::Errno::*; match e { From 609242e876f2ccd1882395076b6a881de1d83c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Fri, 21 Mar 2025 18:50:26 +0800 Subject: [PATCH 12/14] test: restore symlink tests on cygwin --- test/test_fcntl.rs | 1 - test/test_unistd.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index bbbcb604e5..76c3b9f2dc 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -243,7 +243,6 @@ fn test_renameat2_noreplace() { #[test] #[cfg(not(target_os = "redox"))] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_readlink() { let tempdir = tempfile::tempdir().unwrap(); let src = tempdir.path().join("a"); diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 681368e113..12e7f3bfda 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -870,7 +870,6 @@ fn test_canceling_alarm() { #[test] #[cfg(not(any(target_os = "redox", target_os = "haiku")))] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_symlinkat() { use nix::fcntl::AT_FDCWD; From 895e2c285edf7c048b5db290fa01b9b927681295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Fri, 21 Mar 2025 19:23:46 +0800 Subject: [PATCH 13/14] test: test user passwd on cygwin --- test/test_unistd.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 12e7f3bfda..a6aa761dc9 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -1223,15 +1223,18 @@ fn test_access_file_exists() { } #[cfg(not(target_os = "redox"))] -#[cfg_attr(target_os = "cygwin", ignore)] #[test] fn test_user_into_passwd() { - // get the UID of the "nobody" user - #[cfg(not(target_os = "haiku"))] - let test_username = "nobody"; - // "nobody" unavailable on haiku - #[cfg(target_os = "haiku")] - let test_username = "user"; + let test_username = if cfg!(target_os = "haiku") { + // "nobody" unavailable on haiku + "user" + } else if cfg!(target_os = "cygwin") { + // the Windows admin user + "Administrator" + } else { + // get the UID of the "nobody" user + "nobody" + }; let nobody = User::from_name(test_username).unwrap().unwrap(); let pwd: libc::passwd = nobody.into(); From 8baede52779112733c48d09067172b237683fb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sat, 22 Mar 2025 16:51:51 +0800 Subject: [PATCH 14/14] test: restore more tests on cygwin They pass on Cygwin, but not on MSYS2 as intended. --- test/sys/test_stat.rs | 5 ----- test/test_unistd.rs | 2 -- 2 files changed, 7 deletions(-) diff --git a/test/sys/test_stat.rs b/test/sys/test_stat.rs index 8d3adf7928..fed517cf76 100644 --- a/test/sys/test_stat.rs +++ b/test/sys/test_stat.rs @@ -145,7 +145,6 @@ fn test_stat_fstat_lstat() { } #[test] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_fchmod() { let tempdir = tempfile::tempdir().unwrap(); let filename = tempdir.path().join("foo.txt"); @@ -169,7 +168,6 @@ fn test_fchmod() { #[test] #[cfg(not(target_os = "redox"))] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_fchmodat() { let _dr = crate::DirRestore::new(); let tempdir = tempfile::tempdir().unwrap(); @@ -333,7 +331,6 @@ fn test_mkdirat_success_path() { #[test] #[cfg(not(any(target_os = "redox", target_os = "haiku")))] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_mkdirat_success_mode() { let expected_bits = stat::SFlag::S_IFDIR.bits() | stat::Mode::S_IRWXU.bits(); @@ -374,7 +371,6 @@ fn test_mkdirat_fail() { target_os = "redox", target_os = "solaris" )))] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_mknod() { use stat::{lstat, mknod, SFlag}; @@ -395,7 +391,6 @@ fn test_mknod() { target_os = "haiku", target_os = "redox" )))] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_mknodat() { use fcntl::{AtFlags, OFlag}; use nix::dir::Dir; diff --git a/test/test_unistd.rs b/test/test_unistd.rs index a6aa761dc9..6037bb7a02 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -516,7 +516,6 @@ fn test_getcwd() { } #[test] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_chown() { // Testing for anything other than our own UID/GID is hard. let uid = Some(getuid()); @@ -551,7 +550,6 @@ fn test_fchown() { #[test] #[cfg(not(target_os = "redox"))] -#[cfg_attr(target_os = "cygwin", ignore)] fn test_fchownat() { use nix::fcntl::AtFlags; use nix::fcntl::AT_FDCWD;