Skip to content

Commit c3c6ff1

Browse files
committed
Fix building for cygwin
1 parent 8576c29 commit c3c6ff1

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

library/std/src/os/unix/net/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub use self::stream::*;
4545
target_os = "openbsd",
4646
target_os = "nto",
4747
target_vendor = "apple",
48+
target_os = "cygwin",
4849
))]
4950
#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
5051
pub use self::ucred::*;

library/std/src/sys/pal/unix/fd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const fn max_iov() -> usize {
7575
target_os = "horizon",
7676
target_os = "vita",
7777
target_vendor = "apple",
78+
target_os = "cygwin",
7879
)))]
7980
const fn max_iov() -> usize {
8081
16 // The minimum value required by POSIX.

library/std/src/sys/pal/unix/stack_overflow.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ mod imp {
316316
target_os = "netbsd",
317317
target_os = "hurd",
318318
target_os = "linux",
319-
target_os = "l4re"
319+
target_os = "l4re",
320+
target_os = "cygwin"
320321
))]
321322
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
322323
let mut ret = None;
@@ -371,7 +372,7 @@ mod imp {
371372
// this way someone on any unix-y OS can check that all these compile
372373
if cfg!(all(target_os = "linux", not(target_env = "musl"))) {
373374
install_main_guard_linux(page_size)
374-
} else if cfg!(all(target_os = "linux", target_env = "musl")) {
375+
} else if cfg!(any(all(target_os = "linux", target_env = "musl"), target_os = "cygwin")) {
375376
install_main_guard_linux_musl(page_size)
376377
} else if cfg!(target_os = "freebsd") {
377378
install_main_guard_freebsd(page_size)
@@ -511,7 +512,8 @@ mod imp {
511512
target_os = "hurd",
512513
target_os = "linux",
513514
target_os = "netbsd",
514-
target_os = "l4re"
515+
target_os = "l4re",
516+
target_os = "cygwin"
515517
))]
516518
// FIXME: I am probably not unsafe.
517519
unsafe fn current_guard() -> Option<Range<usize>> {

library/std/src/sys/random/linux.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ fn getrandom(mut bytes: &mut [u8], insecure: bool) {
9494

9595
let flags = if insecure {
9696
if GRND_INSECURE_AVAILABLE.load(Relaxed) {
97-
libc::GRND_INSECURE
97+
#[cfg(target_os = "cygwin")]
98+
{ libc::GRND_NONBLOCK }
99+
#[cfg(not(target_os = "cygwin"))]
100+
{ libc::GRND_INSECURE }
98101
} else {
99102
libc::GRND_NONBLOCK
100103
}
@@ -110,6 +113,7 @@ fn getrandom(mut bytes: &mut [u8], insecure: bool) {
110113
libc::EINTR => continue,
111114
// `GRND_INSECURE` is not available, try
112115
// `GRND_NONBLOCK`.
116+
#[cfg(not(target_os = "cygwin"))]
113117
libc::EINVAL if flags == libc::GRND_INSECURE => {
114118
GRND_INSECURE_AVAILABLE.store(false, Relaxed);
115119
continue;

library/std/src/sys/random/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cfg_if::cfg_if! {
22
// Tier 1
3-
if #[cfg(any(target_os = "linux", target_os = "android"))] {
3+
if #[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))] {
44
mod linux;
55
pub use linux::{fill_bytes, hashmap_random_keys};
66
} else if #[cfg(target_os = "windows")] {
@@ -88,6 +88,7 @@ cfg_if::cfg_if! {
8888
target_os = "android",
8989
all(target_family = "wasm", target_os = "unknown"),
9090
target_os = "xous",
91+
target_os = "cygwin",
9192
)))]
9293
pub fn hashmap_random_keys() -> (u64, u64) {
9394
let mut buf = [0; 16];

0 commit comments

Comments
 (0)