about summary refs log tree commit diff
diff options
context:
space:
mode:
author王宇逸 <Strawberry_Str@hotmail.com>2024-12-30 05:00:20 +0900
committer王宇逸 <Strawberry_Str@hotmail.com>2025-03-10 21:23:31 +0800
commit1aad114afda473ccda8b0eb5e0d5a3dcfc35c40e (patch)
tree0b31ebf742c243e503d9deb0add824c3b8474463
parente3e98c84d3eb64181c25ff88f31aee432363ca12 (diff)
downloadrust-1aad114afda473ccda8b0eb5e0d5a3dcfc35c40e.tar.gz
rust-1aad114afda473ccda8b0eb5e0d5a3dcfc35c40e.zip
Fix building for cygwin
-rw-r--r--library/std/src/os/unix/net/mod.rs1
-rw-r--r--library/std/src/sys/pal/unix/fd.rs1
-rw-r--r--library/std/src/sys/pal/unix/stack_overflow.rs8
-rw-r--r--library/std/src/sys/random/linux.rs6
-rw-r--r--library/std/src/sys/random/mod.rs3
5 files changed, 14 insertions, 5 deletions
diff --git a/library/std/src/os/unix/net/mod.rs b/library/std/src/os/unix/net/mod.rs
index b07ba110c41..6cd62303a53 100644
--- a/library/std/src/os/unix/net/mod.rs
+++ b/library/std/src/os/unix/net/mod.rs
@@ -45,6 +45,7 @@ pub use self::stream::*;
     target_os = "openbsd",
     target_os = "nto",
     target_vendor = "apple",
+    target_os = "cygwin",
 ))]
 #[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
 pub use self::ucred::*;
diff --git a/library/std/src/sys/pal/unix/fd.rs b/library/std/src/sys/pal/unix/fd.rs
index 8ec2a08966e..eb873759ecb 100644
--- a/library/std/src/sys/pal/unix/fd.rs
+++ b/library/std/src/sys/pal/unix/fd.rs
@@ -75,6 +75,7 @@ const fn max_iov() -> usize {
     target_os = "horizon",
     target_os = "vita",
     target_vendor = "apple",
+    target_os = "cygwin",
 )))]
 const fn max_iov() -> usize {
     16 // The minimum value required by POSIX.
diff --git a/library/std/src/sys/pal/unix/stack_overflow.rs b/library/std/src/sys/pal/unix/stack_overflow.rs
index 5a639d0545b..463f18800a6 100644
--- a/library/std/src/sys/pal/unix/stack_overflow.rs
+++ b/library/std/src/sys/pal/unix/stack_overflow.rs
@@ -316,7 +316,8 @@ mod imp {
         target_os = "netbsd",
         target_os = "hurd",
         target_os = "linux",
-        target_os = "l4re"
+        target_os = "l4re",
+        target_os = "cygwin"
     ))]
     unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
         let mut ret = None;
@@ -371,7 +372,7 @@ mod imp {
             // this way someone on any unix-y OS can check that all these compile
             if cfg!(all(target_os = "linux", not(target_env = "musl"))) {
                 install_main_guard_linux(page_size)
-            } else if cfg!(all(target_os = "linux", target_env = "musl")) {
+            } else if cfg!(any(all(target_os = "linux", target_env = "musl"), target_os = "cygwin")) {
                 install_main_guard_linux_musl(page_size)
             } else if cfg!(target_os = "freebsd") {
                 install_main_guard_freebsd(page_size)
@@ -511,7 +512,8 @@ mod imp {
         target_os = "hurd",
         target_os = "linux",
         target_os = "netbsd",
-        target_os = "l4re"
+        target_os = "l4re",
+        target_os = "cygwin"
     ))]
     // FIXME: I am probably not unsafe.
     unsafe fn current_guard() -> Option<Range<usize>> {
diff --git a/library/std/src/sys/random/linux.rs b/library/std/src/sys/random/linux.rs
index e3cb79285cd..266c71abf3d 100644
--- a/library/std/src/sys/random/linux.rs
+++ b/library/std/src/sys/random/linux.rs
@@ -94,7 +94,10 @@ fn getrandom(mut bytes: &mut [u8], insecure: bool) {
 
             let flags = if insecure {
                 if GRND_INSECURE_AVAILABLE.load(Relaxed) {
-                    libc::GRND_INSECURE
+                    #[cfg(target_os = "cygwin")]
+                    { libc::GRND_NONBLOCK }
+                    #[cfg(not(target_os = "cygwin"))]
+                    { libc::GRND_INSECURE }
                 } else {
                     libc::GRND_NONBLOCK
                 }
@@ -110,6 +113,7 @@ fn getrandom(mut bytes: &mut [u8], insecure: bool) {
                     libc::EINTR => continue,
                     // `GRND_INSECURE` is not available, try
                     // `GRND_NONBLOCK`.
+                    #[cfg(not(target_os = "cygwin"))]
                     libc::EINVAL if flags == libc::GRND_INSECURE => {
                         GRND_INSECURE_AVAILABLE.store(false, Relaxed);
                         continue;
diff --git a/library/std/src/sys/random/mod.rs b/library/std/src/sys/random/mod.rs
index f42351deb92..b6a357e5b07 100644
--- a/library/std/src/sys/random/mod.rs
+++ b/library/std/src/sys/random/mod.rs
@@ -1,6 +1,6 @@
 cfg_if::cfg_if! {
     // Tier 1
-    if #[cfg(any(target_os = "linux", target_os = "android"))] {
+    if #[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))] {
         mod linux;
         pub use linux::{fill_bytes, hashmap_random_keys};
     } else if #[cfg(target_os = "windows")] {
@@ -88,6 +88,7 @@ cfg_if::cfg_if! {
     target_os = "android",
     all(target_family = "wasm", target_os = "unknown"),
     target_os = "xous",
+    target_os = "cygwin",
 )))]
 pub fn hashmap_random_keys() -> (u64, u64) {
     let mut buf = [0; 16];