Skip to content

Commit 8d52064

Browse files
authored
Rollup merge of rust-lang#137621 - Berrysoft:cygwin-std, r=joboet
Add std support to cygwin target
2 parents 33ddf0c + 9cab8c2 commit 8d52064

File tree

26 files changed

+187
-15
lines changed

26 files changed

+187
-15
lines changed

compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) fn target() -> Target {
1818
description: Some("64-bit x86 Cygwin".into()),
1919
tier: Some(3),
2020
host_tools: Some(false),
21-
std: None,
21+
std: Some(true),
2222
},
2323
}
2424
}

library/std/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fn main() {
6262
|| target_os == "zkvm"
6363
|| target_os == "rtems"
6464
|| target_os == "nuttx"
65+
|| target_os == "cygwin"
6566

6667
// See src/bootstrap/src/core/build_steps/synthetic_targets.rs
6768
|| env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok()

library/std/src/os/cygwin/fs.rs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
use crate::fs::Metadata;
3+
use crate::sys_common::AsInner;
4+
/// OS-specific extensions to [`fs::Metadata`].
5+
///
6+
/// [`fs::Metadata`]: crate::fs::Metadata
7+
#[stable(feature = "metadata_ext", since = "1.1.0")]
8+
pub trait MetadataExt {
9+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
10+
fn st_dev(&self) -> u64;
11+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
12+
fn st_ino(&self) -> u64;
13+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
14+
fn st_mode(&self) -> u32;
15+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
16+
fn st_nlink(&self) -> u64;
17+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
18+
fn st_uid(&self) -> u32;
19+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
20+
fn st_gid(&self) -> u32;
21+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
22+
fn st_rdev(&self) -> u64;
23+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
24+
fn st_size(&self) -> u64;
25+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
26+
fn st_atime(&self) -> i64;
27+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
28+
fn st_atime_nsec(&self) -> i64;
29+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
30+
fn st_mtime(&self) -> i64;
31+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
32+
fn st_mtime_nsec(&self) -> i64;
33+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
34+
fn st_ctime(&self) -> i64;
35+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
36+
fn st_ctime_nsec(&self) -> i64;
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_blksize(&self) -> u64;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_blocks(&self) -> u64;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_birthtime(&self) -> i64;
43+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
44+
fn st_birthtime_nsec(&self) -> i64;
45+
}
46+
#[stable(feature = "metadata_ext", since = "1.1.0")]
47+
impl MetadataExt for Metadata {
48+
fn st_dev(&self) -> u64 {
49+
self.as_inner().as_inner().st_dev as u64
50+
}
51+
fn st_ino(&self) -> u64 {
52+
self.as_inner().as_inner().st_ino as u64
53+
}
54+
fn st_mode(&self) -> u32 {
55+
self.as_inner().as_inner().st_mode as u32
56+
}
57+
fn st_nlink(&self) -> u64 {
58+
self.as_inner().as_inner().st_nlink as u64
59+
}
60+
fn st_uid(&self) -> u32 {
61+
self.as_inner().as_inner().st_uid as u32
62+
}
63+
fn st_gid(&self) -> u32 {
64+
self.as_inner().as_inner().st_gid as u32
65+
}
66+
fn st_rdev(&self) -> u64 {
67+
self.as_inner().as_inner().st_rdev as u64
68+
}
69+
fn st_size(&self) -> u64 {
70+
self.as_inner().as_inner().st_size as u64
71+
}
72+
fn st_atime(&self) -> i64 {
73+
self.as_inner().as_inner().st_atime as i64
74+
}
75+
fn st_atime_nsec(&self) -> i64 {
76+
self.as_inner().as_inner().st_atime_nsec as i64
77+
}
78+
fn st_mtime(&self) -> i64 {
79+
self.as_inner().as_inner().st_mtime as i64
80+
}
81+
fn st_mtime_nsec(&self) -> i64 {
82+
self.as_inner().as_inner().st_mtime_nsec as i64
83+
}
84+
fn st_ctime(&self) -> i64 {
85+
self.as_inner().as_inner().st_ctime as i64
86+
}
87+
fn st_ctime_nsec(&self) -> i64 {
88+
self.as_inner().as_inner().st_ctime_nsec as i64
89+
}
90+
fn st_blksize(&self) -> u64 {
91+
self.as_inner().as_inner().st_blksize as u64
92+
}
93+
fn st_blocks(&self) -> u64 {
94+
self.as_inner().as_inner().st_blocks as u64
95+
}
96+
fn st_birthtime(&self) -> i64 {
97+
self.as_inner().as_inner().st_birthtime as i64
98+
}
99+
fn st_birthtime_nsec(&self) -> i64 {
100+
self.as_inner().as_inner().st_birthtime_nsec as i64
101+
}
102+
}

library/std/src/os/cygwin/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Cygwin-specific definitions
2+
#![stable(feature = "raw_ext", since = "1.1.0")]
3+
pub mod fs;
4+
pub(crate) mod raw;

library/std/src/os/cygwin/raw.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Cygwin-specific raw type definitions.
2+
3+
#[stable(feature = "raw_ext", since = "1.1.0")]
4+
pub use libc::{blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, off_t, pthread_t, time_t};

library/std/src/os/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub mod windows;
125125
pub mod aix;
126126
#[cfg(target_os = "android")]
127127
pub mod android;
128+
#[cfg(target_os = "cygwin")]
129+
pub mod cygwin;
128130
#[cfg(target_os = "dragonfly")]
129131
pub mod dragonfly;
130132
#[cfg(target_os = "emscripten")]

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

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ mod platform {
4141
pub use crate::os::aix::*;
4242
#[cfg(target_os = "android")]
4343
pub use crate::os::android::*;
44+
#[cfg(target_os = "cygwin")]
45+
pub use crate::os::cygwin::*;
4446
#[cfg(target_vendor = "apple")]
4547
pub use crate::os::darwin::*;
4648
#[cfg(target_os = "dragonfly")]

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

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
target_os = "illumos",
1010
target_os = "haiku",
1111
target_os = "nto",
12+
target_os = "cygwin"
1213
))]
1314
use libc::MSG_NOSIGNAL;
1415

@@ -37,6 +38,7 @@ use crate::{fmt, io};
3738
target_os = "illumos",
3839
target_os = "haiku",
3940
target_os = "nto",
41+
target_os = "cygwin"
4042
)))]
4143
const MSG_NOSIGNAL: core::ffi::c_int = 0x0;
4244

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

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod tests;
2121
target_os = "openbsd",
2222
target_os = "nto",
2323
target_vendor = "apple",
24+
target_os = "cygwin"
2425
))]
2526
mod ucred;
2627

@@ -44,6 +45,7 @@ pub use self::stream::*;
4445
target_os = "openbsd",
4546
target_os = "nto",
4647
target_vendor = "apple",
48+
target_os = "cygwin",
4749
))]
4850
#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
4951
pub use self::ucred::*;

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

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_wi
1010
target_os = "openbsd",
1111
target_os = "nto",
1212
target_vendor = "apple",
13+
target_os = "cygwin"
1314
))]
1415
use super::{UCred, peer_cred};
1516
use crate::fmt;
@@ -231,6 +232,7 @@ impl UnixStream {
231232
target_os = "openbsd",
232233
target_os = "nto",
233234
target_vendor = "apple",
235+
target_os = "cygwin"
234236
))]
235237
pub fn peer_cred(&self) -> io::Result<UCred> {
236238
peer_cred(self)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ pub(super) use self::impl_apple::peer_cred;
3333
target_os = "nto"
3434
))]
3535
pub(super) use self::impl_bsd::peer_cred;
36-
#[cfg(any(target_os = "android", target_os = "linux"))]
36+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
3737
pub(super) use self::impl_linux::peer_cred;
3838

39-
#[cfg(any(target_os = "linux", target_os = "android"))]
39+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
4040
mod impl_linux {
4141
use libc::{SO_PEERCRED, SOL_SOCKET, c_void, getsockopt, socklen_t, ucred};
4242

library/std/src/random.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::sys::random as sys;
3737
/// Solaris | [`arc4random_buf`](https://docs.oracle.com/cd/E88353_01/html/E37843/arc4random-3c.html)
3838
/// Vita | `arc4random_buf`
3939
/// Hermit | `read_entropy`
40-
/// Horizon | `getrandom` shim
40+
/// Horizon, Cygwin | `getrandom`
4141
/// AIX, Hurd, L4Re, QNX | `/dev/urandom`
4242
/// Redox | `/scheme/rand`
4343
/// RTEMS | [`arc4random_buf`](https://docs.rtems.org/branches/master/bsp-howto/getentropy.html)

library/std/src/sys/fs/unix.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,12 @@ impl FileAttr {
543543
SystemTime::new(self.stat.st_atim.tv_sec as i64, self.stat.st_atim.tv_nsec as i64)
544544
}
545545

546-
#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_vendor = "apple"))]
546+
#[cfg(any(
547+
target_os = "freebsd",
548+
target_os = "openbsd",
549+
target_vendor = "apple",
550+
target_os = "cygwin",
551+
))]
547552
pub fn created(&self) -> io::Result<SystemTime> {
548553
SystemTime::new(self.stat.st_birthtime as i64, self.stat.st_birthtime_nsec as i64)
549554
}
@@ -553,6 +558,7 @@ impl FileAttr {
553558
target_os = "openbsd",
554559
target_os = "vita",
555560
target_vendor = "apple",
561+
target_os = "cygwin",
556562
)))]
557563
pub fn created(&self) -> io::Result<SystemTime> {
558564
cfg_has_statx! {
@@ -960,6 +966,7 @@ impl DirEntry {
960966

961967
#[cfg(any(
962968
target_os = "linux",
969+
target_os = "cygwin",
963970
target_os = "emscripten",
964971
target_os = "android",
965972
target_os = "solaris",
@@ -1220,6 +1227,7 @@ impl File {
12201227
target_os = "freebsd",
12211228
target_os = "fuchsia",
12221229
target_os = "linux",
1230+
target_os = "cygwin",
12231231
target_os = "android",
12241232
target_os = "netbsd",
12251233
target_os = "openbsd",
@@ -1234,6 +1242,7 @@ impl File {
12341242
target_os = "fuchsia",
12351243
target_os = "freebsd",
12361244
target_os = "linux",
1245+
target_os = "cygwin",
12371246
target_os = "netbsd",
12381247
target_os = "openbsd",
12391248
target_os = "nto",

library/std/src/sys/net/connection/socket.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ cfg_if::cfg_if! {
5959
target_os = "dragonfly", target_os = "freebsd",
6060
target_os = "openbsd", target_os = "netbsd",
6161
target_os = "solaris", target_os = "illumos",
62-
target_os = "haiku", target_os = "nto"))] {
62+
target_os = "haiku", target_os = "nto",
63+
target_os = "cygwin"))] {
6364
use libc::MSG_NOSIGNAL;
6465
} else {
6566
const MSG_NOSIGNAL: c_int = 0x0;

library/std/src/sys/net/connection/socket/unix.rs

+14
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl Socket {
8181
target_os = "linux",
8282
target_os = "netbsd",
8383
target_os = "openbsd",
84+
target_os = "cygwin",
8485
target_os = "nto",
8586
target_os = "solaris",
8687
))] {
@@ -128,6 +129,7 @@ impl Socket {
128129
target_os = "hurd",
129130
target_os = "netbsd",
130131
target_os = "openbsd",
132+
target_os = "cygwin",
131133
target_os = "nto",
132134
))] {
133135
// Like above, set cloexec atomically
@@ -257,6 +259,7 @@ impl Socket {
257259
target_os = "hurd",
258260
target_os = "netbsd",
259261
target_os = "openbsd",
262+
target_os = "cygwin",
260263
))] {
261264
unsafe {
262265
let fd = cvt_r(|| libc::accept4(self.as_raw_fd(), storage, len, libc::SOCK_CLOEXEC))?;
@@ -421,6 +424,7 @@ impl Socket {
421424
Ok(())
422425
}
423426

427+
#[cfg(not(target_os = "cygwin"))]
424428
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
425429
let linger = libc::linger {
426430
l_onoff: linger.is_some() as libc::c_int,
@@ -430,6 +434,16 @@ impl Socket {
430434
setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger)
431435
}
432436

437+
#[cfg(target_os = "cygwin")]
438+
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
439+
let linger = libc::linger {
440+
l_onoff: linger.is_some() as libc::c_ushort,
441+
l_linger: linger.unwrap_or_default().as_secs() as libc::c_ushort,
442+
};
443+
444+
setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger)
445+
}
446+
433447
pub fn linger(&self) -> io::Result<Option<Duration>> {
434448
let val: libc::linger = getsockopt(self, libc::SOL_SOCKET, SO_LINGER)?;
435449

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

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl DoubleEndedIterator for Args {
100100
target_os = "dragonfly",
101101
target_os = "netbsd",
102102
target_os = "openbsd",
103+
target_os = "cygwin",
103104
target_os = "solaris",
104105
target_os = "illumos",
105106
target_os = "emscripten",

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

+11
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ pub mod os {
108108
pub const EXE_EXTENSION: &str = "";
109109
}
110110

111+
#[cfg(target_os = "cygwin")]
112+
pub mod os {
113+
pub const FAMILY: &str = "unix";
114+
pub const OS: &str = "cygwin";
115+
pub const DLL_PREFIX: &str = "";
116+
pub const DLL_SUFFIX: &str = ".dll";
117+
pub const DLL_EXTENSION: &str = "dll";
118+
pub const EXE_SUFFIX: &str = ".exe";
119+
pub const EXE_EXTENSION: &str = "exe";
120+
}
121+
111122
#[cfg(target_os = "android")]
112123
pub mod os {
113124
pub const FAMILY: &str = "unix";

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

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
4747
target_os = "netbsd",
4848
target_os = "openbsd",
4949
target_vendor = "apple",
50+
target_os = "cygwin",
5051
))]
5152
const fn max_iov() -> usize {
5253
libc::IOV_MAX as usize
@@ -74,6 +75,7 @@ const fn max_iov() -> usize {
7475
target_os = "horizon",
7576
target_os = "vita",
7677
target_vendor = "apple",
78+
target_os = "cygwin",
7779
)))]
7880
const fn max_iov() -> usize {
7981
16 // The minimum value required by POSIX.
@@ -503,6 +505,7 @@ impl FileDesc {
503505
target_os = "fuchsia",
504506
target_os = "l4re",
505507
target_os = "linux",
508+
target_os = "cygwin",
506509
target_os = "haiku",
507510
target_os = "redox",
508511
target_os = "vxworks",
@@ -525,6 +528,7 @@ impl FileDesc {
525528
target_os = "fuchsia",
526529
target_os = "l4re",
527530
target_os = "linux",
531+
target_os = "cygwin",
528532
target_os = "haiku",
529533
target_os = "redox",
530534
target_os = "vxworks",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ cfg_if::cfg_if! {
380380
#[link(name = "pthread")]
381381
#[link(name = "rt")]
382382
unsafe extern "C" {}
383-
} else if #[cfg(any(target_os = "dragonfly", target_os = "openbsd"))] {
383+
} else if #[cfg(any(target_os = "dragonfly", target_os = "openbsd", target_os = "cygwin"))] {
384384
#[link(name = "pthread")]
385385
unsafe extern "C" {}
386386
} else if #[cfg(target_os = "solaris")] {

0 commit comments

Comments
 (0)