Skip to content

Commit 84b2d03

Browse files
committed
Initial STD support for Cygwin
Signed-off-by: Ookiineko <[email protected]>
1 parent ad27045 commit 84b2d03

File tree

24 files changed

+247
-9
lines changed

24 files changed

+247
-9
lines changed

library/rtstartup/rsbegin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
4949
// enumerating currently loaded modules via the dl_iterate_phdr() API and
5050
// finding their ".eh_frame" sections); Others, like Windows, require modules
5151
// to actively register their unwind info sections via unwinder API.
52-
#[cfg(all(target_os = "windows", target_arch = "x86", target_env = "gnu"))]
52+
#[cfg(all(any(target_os = "cygwin", all(target_os = "windows", target_env = "gnu")), target_arch = "x86"))]
5353
pub mod eh_frames {
5454
#[no_mangle]
5555
#[unsafe(link_section = ".eh_frame")]

library/rtstartup/rsend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
2727
drop_in_place(to_drop);
2828
}
2929

30-
#[cfg(all(target_os = "windows", target_arch = "x86", target_env = "gnu"))]
30+
#[cfg(all(any(target_os = "cygwin", all(target_os = "windows", target_env = "gnu")), target_arch = "x86"))]
3131
pub mod eh_frames {
3232
// Terminate the frame unwind info section with a 0 as a sentinel;
3333
// this would be the 'length' field in a real FDE.

library/std/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fn main() {
5656
|| target_os == "zkvm"
5757
|| target_os == "rtems"
5858
|| target_os == "nuttx"
59+
|| target_os == "cygwin"
5960

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

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

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
use crate::fs::Metadata;
3+
#[allow(deprecated)]
4+
use crate::os::cygwin::raw;
5+
use crate::sys_common::AsInner;
6+
/// OS-specific extensions to [`fs::Metadata`].
7+
///
8+
/// [`fs::Metadata`]: crate::fs::Metadata
9+
#[stable(feature = "metadata_ext", since = "1.1.0")]
10+
pub trait MetadataExt {
11+
/// Gain a reference to the underlying `stat` structure which contains
12+
/// the raw information returned by the OS.
13+
///
14+
/// The contents of the returned `stat` are **not** consistent across
15+
/// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
16+
/// cross-Unix abstractions contained within the raw stat.
17+
#[stable(feature = "metadata_ext", since = "1.1.0")]
18+
#[deprecated(
19+
since = "1.8.0",
20+
note = "deprecated in favor of the accessor \
21+
methods of this trait"
22+
)]
23+
#[allow(deprecated)]
24+
fn as_raw_stat(&self) -> &raw::stat;
25+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
26+
fn st_dev(&self) -> u64;
27+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
28+
fn st_ino(&self) -> u64;
29+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
30+
fn st_mode(&self) -> u32;
31+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
32+
fn st_nlink(&self) -> u64;
33+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
34+
fn st_uid(&self) -> u32;
35+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
36+
fn st_gid(&self) -> u32;
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_rdev(&self) -> u64;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_size(&self) -> u64;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_atime(&self) -> i64;
43+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
44+
fn st_atime_nsec(&self) -> i64;
45+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
46+
fn st_mtime(&self) -> i64;
47+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
48+
fn st_mtime_nsec(&self) -> i64;
49+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
50+
fn st_ctime(&self) -> i64;
51+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
52+
fn st_ctime_nsec(&self) -> i64;
53+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
54+
fn st_blksize(&self) -> u64;
55+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
56+
fn st_blocks(&self) -> u64;
57+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
58+
fn st_birthtime(&self) -> i64;
59+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
60+
fn st_birthtime_nsec(&self) -> i64;
61+
}
62+
#[stable(feature = "metadata_ext", since = "1.1.0")]
63+
impl MetadataExt for Metadata {
64+
#[allow(deprecated)]
65+
fn as_raw_stat(&self) -> &raw::stat {
66+
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
67+
}
68+
fn st_dev(&self) -> u64 {
69+
self.as_inner().as_inner().st_dev as u64
70+
}
71+
fn st_ino(&self) -> u64 {
72+
self.as_inner().as_inner().st_ino as u64
73+
}
74+
fn st_mode(&self) -> u32 {
75+
self.as_inner().as_inner().st_mode as u32
76+
}
77+
fn st_nlink(&self) -> u64 {
78+
self.as_inner().as_inner().st_nlink as u64
79+
}
80+
fn st_uid(&self) -> u32 {
81+
self.as_inner().as_inner().st_uid as u32
82+
}
83+
fn st_gid(&self) -> u32 {
84+
self.as_inner().as_inner().st_gid as u32
85+
}
86+
fn st_rdev(&self) -> u64 {
87+
self.as_inner().as_inner().st_rdev as u64
88+
}
89+
fn st_size(&self) -> u64 {
90+
self.as_inner().as_inner().st_size as u64
91+
}
92+
fn st_atime(&self) -> i64 {
93+
self.as_inner().as_inner().st_atime as i64
94+
}
95+
fn st_atime_nsec(&self) -> i64 {
96+
self.as_inner().as_inner().st_atime_nsec as i64
97+
}
98+
fn st_mtime(&self) -> i64 {
99+
self.as_inner().as_inner().st_mtime as i64
100+
}
101+
fn st_mtime_nsec(&self) -> i64 {
102+
self.as_inner().as_inner().st_mtime_nsec as i64
103+
}
104+
fn st_ctime(&self) -> i64 {
105+
self.as_inner().as_inner().st_ctime as i64
106+
}
107+
fn st_ctime_nsec(&self) -> i64 {
108+
self.as_inner().as_inner().st_ctime_nsec as i64
109+
}
110+
fn st_blksize(&self) -> u64 {
111+
self.as_inner().as_inner().st_blksize as u64
112+
}
113+
fn st_blocks(&self) -> u64 {
114+
self.as_inner().as_inner().st_blocks as u64
115+
}
116+
fn st_birthtime(&self) -> i64 {
117+
self.as_inner().as_inner().st_birthtime as i64
118+
}
119+
fn st_birthtime_nsec(&self) -> i64 {
120+
self.as_inner().as_inner().st_birthtime_nsec as i64
121+
}
122+
}

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

Lines changed: 4 additions & 0 deletions
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 mod raw;

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//! Cygwin-specific raw type definitions
2+
#![stable(feature = "raw_ext", since = "1.1.0")]
3+
#![deprecated(
4+
since = "1.8.0",
5+
note = "these type aliases are no longer supported by \
6+
the standard library, the `libc` crate on \
7+
crates.io should be used instead for the correct \
8+
definitions"
9+
)]
10+
#![allow(deprecated)]
11+
use crate::os::raw::{c_long, c_void};
12+
#[stable(feature = "raw_ext", since = "1.1.0")]
13+
pub type blkcnt_t = i64;
14+
#[stable(feature = "raw_ext", since = "1.1.0")]
15+
pub type blksize_t = i32;
16+
#[stable(feature = "raw_ext", since = "1.1.0")]
17+
pub type dev_t = u32;
18+
#[stable(feature = "raw_ext", since = "1.1.0")]
19+
pub type ino_t = u64;
20+
#[stable(feature = "raw_ext", since = "1.1.0")]
21+
pub type mode_t = u32;
22+
#[stable(feature = "raw_ext", since = "1.1.0")]
23+
pub type nlink_t = u16;
24+
#[stable(feature = "raw_ext", since = "1.1.0")]
25+
pub type off_t = i64;
26+
#[stable(feature = "raw_ext", since = "1.1.0")]
27+
pub type time_t = i64;
28+
#[stable(feature = "pthread_t", since = "1.8.0")]
29+
pub type pthread_t = *mut c_void;
30+
#[repr(C)]
31+
#[derive(Clone)]
32+
#[stable(feature = "raw_ext", since = "1.1.0")]
33+
pub struct stat {
34+
#[stable(feature = "raw_ext", since = "1.1.0")]
35+
pub st_dev: dev_t,
36+
#[stable(feature = "raw_ext", since = "1.1.0")]
37+
pub st_ino: ino_t,
38+
#[stable(feature = "raw_ext", since = "1.1.0")]
39+
pub st_mode: mode_t,
40+
#[stable(feature = "raw_ext", since = "1.1.0")]
41+
pub st_nlink: nlink_t,
42+
#[stable(feature = "raw_ext", since = "1.1.0")]
43+
pub st_uid: u32,
44+
#[stable(feature = "raw_ext", since = "1.1.0")]
45+
pub st_gid: u32,
46+
#[stable(feature = "raw_ext", since = "1.1.0")]
47+
pub st_rdev: dev_t,
48+
#[stable(feature = "raw_ext", since = "1.1.0")]
49+
pub st_size: off_t,
50+
#[stable(feature = "raw_ext", since = "1.1.0")]
51+
pub st_atime: time_t,
52+
#[stable(feature = "raw_ext", since = "1.1.0")]
53+
pub st_atime_nsec: c_long,
54+
#[stable(feature = "raw_ext", since = "1.1.0")]
55+
pub st_mtime: time_t,
56+
#[stable(feature = "raw_ext", since = "1.1.0")]
57+
pub st_mtime_nsec: c_long,
58+
#[stable(feature = "raw_ext", since = "1.1.0")]
59+
pub st_ctime: time_t,
60+
#[stable(feature = "raw_ext", since = "1.1.0")]
61+
pub st_ctime_nsec: c_long,
62+
#[stable(feature = "raw_ext", since = "1.1.0")]
63+
pub st_blksize: blksize_t,
64+
#[stable(feature = "raw_ext", since = "1.1.0")]
65+
pub st_blocks: blkcnt_t,
66+
#[stable(feature = "raw_ext", since = "1.1.0")]
67+
pub st_birthtime: time_t,
68+
#[stable(feature = "raw_ext", since = "1.1.0")]
69+
pub st_birthtime_nsec: c_long,
70+
}

library/std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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/sys/net/connection/socket.rs

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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))?;

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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
@@ -500,6 +501,7 @@ impl FileDesc {
500501
target_os = "fuchsia",
501502
target_os = "l4re",
502503
target_os = "linux",
504+
target_os = "cygwin",
503505
target_os = "haiku",
504506
target_os = "redox",
505507
target_os = "vxworks",
@@ -522,6 +524,7 @@ impl FileDesc {
522524
target_os = "fuchsia",
523525
target_os = "l4re",
524526
target_os = "linux",
527+
target_os = "cygwin",
525528
target_os = "haiku",
526529
target_os = "redox",
527530
target_os = "vxworks",

0 commit comments

Comments
 (0)