Skip to content

Commit e75c749

Browse files
committed
Initial STD support for Cygwin
Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
1 parent 98a4878 commit e75c749

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
@@ -61,6 +61,7 @@ fn main() {
6161
|| target_os == "zkvm"
6262
|| target_os == "rtems"
6363
|| target_os == "nuttx"
64+
|| target_os == "cygwin"
6465

6566
// See src/bootstrap/src/core/build_steps/synthetic_targets.rs
6667
|| 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

0 commit comments

Comments
 (0)