Skip to content

Commit 3db94e8

Browse files
committed
Support for visionOS
1 parent b6679c0 commit 3db94e8

File tree

28 files changed

+391
-21
lines changed

28 files changed

+391
-21
lines changed

std/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
|| target_os == "ios"
2323
|| target_os == "tvos"
2424
|| target_os == "watchos"
25+
|| target_os == "visionos"
2526
|| target_os == "windows"
2627
|| target_os == "fuchsia"
2728
|| (target_vendor == "fortanix" && target_env == "sgx")

std/src/fs/tests.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,8 +1644,8 @@ fn test_file_times() {
16441644
use crate::os::macos::fs::FileTimesExt;
16451645
#[cfg(target_os = "tvos")]
16461646
use crate::os::tvos::fs::FileTimesExt;
1647-
#[cfg(target_os = "tvos")]
1648-
use crate::os::tvos::fs::FileTimesExt;
1647+
#[cfg(target_os = "visionos")]
1648+
use crate::os::visionos::fs::FileTimesExt;
16491649
#[cfg(target_os = "watchos")]
16501650
use crate::os::watchos::fs::FileTimesExt;
16511651
#[cfg(windows)]
@@ -1662,6 +1662,7 @@ fn test_file_times() {
16621662
target_os = "macos",
16631663
target_os = "ios",
16641664
target_os = "watchos",
1665+
target_os = "visionos",
16651666
target_os = "tvos",
16661667
))]
16671668
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
@@ -1670,6 +1671,7 @@ fn test_file_times() {
16701671
target_os = "macos",
16711672
target_os = "ios",
16721673
target_os = "watchos",
1674+
target_os = "visionos",
16731675
target_os = "tvos",
16741676
))]
16751677
{
@@ -1701,6 +1703,7 @@ fn test_file_times() {
17011703
target_os = "macos",
17021704
target_os = "ios",
17031705
target_os = "watchos",
1706+
target_os = "visionos",
17041707
target_os = "tvos",
17051708
))]
17061709
{
@@ -1709,14 +1712,22 @@ fn test_file_times() {
17091712
}
17101713

17111714
#[test]
1712-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
1715+
#[cfg(any(
1716+
target_os = "macos",
1717+
target_os = "ios",
1718+
target_os = "tvos",
1719+
target_os = "watchos",
1720+
target_os = "visionos"
1721+
))]
17131722
fn test_file_times_pre_epoch_with_nanos() {
17141723
#[cfg(target_os = "ios")]
17151724
use crate::os::ios::fs::FileTimesExt;
17161725
#[cfg(target_os = "macos")]
17171726
use crate::os::macos::fs::FileTimesExt;
17181727
#[cfg(target_os = "tvos")]
17191728
use crate::os::tvos::fs::FileTimesExt;
1729+
#[cfg(target_os = "visionos")]
1730+
use crate::os::visionos::fs::FileTimesExt;
17201731
#[cfg(target_os = "watchos")]
17211732
use crate::os::watchos::fs::FileTimesExt;
17221733

std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ pub mod solid;
149149
pub(crate) mod tvos;
150150
#[cfg(target_os = "uefi")]
151151
pub mod uefi;
152+
#[cfg(target_os = "visionos")]
153+
pub(crate) mod visionos;
152154
#[cfg(target_os = "vita")]
153155
pub mod vita;
154156
#[cfg(target_os = "vxworks")]

std/src/os/unix/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ mod platform {
7979
pub use crate::os::solaris::*;
8080
#[cfg(target_os = "tvos")]
8181
pub use crate::os::tvos::*;
82+
#[cfg(target_os = "visionos")]
83+
pub use crate::os::visionos::*;
8284
#[cfg(target_os = "vita")]
8385
pub use crate::os::vita::*;
8486
#[cfg(target_os = "vxworks")]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl UnixStream {
233233
target_os = "tvos",
234234
target_os = "macos",
235235
target_os = "watchos",
236+
target_os = "visionos",
236237
target_os = "netbsd",
237238
target_os = "openbsd"
238239
))]

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ pub(super) use self::impl_linux::peer_cred;
3434
))]
3535
pub(super) use self::impl_bsd::peer_cred;
3636

37-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
37+
#[cfg(any(
38+
target_os = "macos",
39+
target_os = "ios",
40+
target_os = "tvos",
41+
target_os = "watchos",
42+
target_os = "visionos"
43+
))]
3844
pub(super) use self::impl_mac::peer_cred;
3945

4046
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -96,7 +102,13 @@ mod impl_bsd {
96102
}
97103
}
98104

99-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
105+
#[cfg(any(
106+
target_os = "macos",
107+
target_os = "ios",
108+
target_os = "tvos",
109+
target_os = "watchos",
110+
target_os = "visionos"
111+
))]
100112
mod impl_mac {
101113
use super::UCred;
102114
use crate::os::unix::io::AsRawFd;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use libc::{getegid, geteuid, getpid};
1111
target_os = "tvos",
1212
target_os = "macos",
1313
target_os = "watchos",
14+
target_os = "visionos",
1415
target_os = "openbsd"
1516
))]
1617
fn test_socket_pair() {
@@ -32,6 +33,7 @@ fn test_socket_pair() {
3233
target_os = "ios",
3334
target_os = "macos",
3435
target_os = "watchos",
36+
target_os = "visionos",
3537
target_os = "tvos",
3638
))]
3739
fn test_socket_pair_pids(arg: Type) -> RetType {

std/src/os/xros/fs.rs

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
3+
use crate::fs::{self, Metadata};
4+
use crate::sealed::Sealed;
5+
use crate::sys_common::{AsInner, AsInnerMut, IntoInner};
6+
use crate::time::SystemTime;
7+
8+
#[allow(deprecated)]
9+
use super::raw;
10+
11+
/// OS-specific extensions to [`fs::Metadata`].
12+
///
13+
/// [`fs::Metadata`]: crate::fs::Metadata
14+
#[stable(feature = "metadata_ext", since = "1.1.0")]
15+
pub trait MetadataExt {
16+
/// Gain a reference to the underlying `stat` structure which contains
17+
/// the raw information returned by the OS.
18+
///
19+
/// The contents of the returned `stat` are **not** consistent across
20+
/// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
21+
/// cross-Unix abstractions contained within the raw stat.
22+
#[stable(feature = "metadata_ext", since = "1.1.0")]
23+
#[deprecated(
24+
since = "1.8.0",
25+
note = "deprecated in favor of the accessor \
26+
methods of this trait"
27+
)]
28+
#[allow(deprecated)]
29+
fn as_raw_stat(&self) -> &raw::stat;
30+
31+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
32+
fn st_dev(&self) -> u64;
33+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
34+
fn st_ino(&self) -> u64;
35+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
36+
fn st_mode(&self) -> u32;
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_nlink(&self) -> u64;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_uid(&self) -> u32;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_gid(&self) -> u32;
43+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
44+
fn st_rdev(&self) -> u64;
45+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
46+
fn st_size(&self) -> u64;
47+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
48+
fn st_atime(&self) -> i64;
49+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
50+
fn st_atime_nsec(&self) -> i64;
51+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
52+
fn st_mtime(&self) -> i64;
53+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
54+
fn st_mtime_nsec(&self) -> i64;
55+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
56+
fn st_ctime(&self) -> i64;
57+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
58+
fn st_ctime_nsec(&self) -> i64;
59+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
60+
fn st_birthtime(&self) -> i64;
61+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
62+
fn st_birthtime_nsec(&self) -> i64;
63+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
64+
fn st_blksize(&self) -> u64;
65+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
66+
fn st_blocks(&self) -> u64;
67+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
68+
fn st_flags(&self) -> u32;
69+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
70+
fn st_gen(&self) -> u32;
71+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
72+
fn st_lspare(&self) -> u32;
73+
}
74+
75+
#[stable(feature = "metadata_ext", since = "1.1.0")]
76+
impl MetadataExt for Metadata {
77+
#[allow(deprecated)]
78+
fn as_raw_stat(&self) -> &raw::stat {
79+
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
80+
}
81+
fn st_dev(&self) -> u64 {
82+
self.as_inner().as_inner().st_dev as u64
83+
}
84+
fn st_ino(&self) -> u64 {
85+
self.as_inner().as_inner().st_ino as u64
86+
}
87+
fn st_mode(&self) -> u32 {
88+
self.as_inner().as_inner().st_mode as u32
89+
}
90+
fn st_nlink(&self) -> u64 {
91+
self.as_inner().as_inner().st_nlink as u64
92+
}
93+
fn st_uid(&self) -> u32 {
94+
self.as_inner().as_inner().st_uid as u32
95+
}
96+
fn st_gid(&self) -> u32 {
97+
self.as_inner().as_inner().st_gid as u32
98+
}
99+
fn st_rdev(&self) -> u64 {
100+
self.as_inner().as_inner().st_rdev as u64
101+
}
102+
fn st_size(&self) -> u64 {
103+
self.as_inner().as_inner().st_size as u64
104+
}
105+
fn st_atime(&self) -> i64 {
106+
self.as_inner().as_inner().st_atime as i64
107+
}
108+
fn st_atime_nsec(&self) -> i64 {
109+
self.as_inner().as_inner().st_atime_nsec as i64
110+
}
111+
fn st_mtime(&self) -> i64 {
112+
self.as_inner().as_inner().st_mtime as i64
113+
}
114+
fn st_mtime_nsec(&self) -> i64 {
115+
self.as_inner().as_inner().st_mtime_nsec as i64
116+
}
117+
fn st_ctime(&self) -> i64 {
118+
self.as_inner().as_inner().st_ctime as i64
119+
}
120+
fn st_ctime_nsec(&self) -> i64 {
121+
self.as_inner().as_inner().st_ctime_nsec as i64
122+
}
123+
fn st_birthtime(&self) -> i64 {
124+
self.as_inner().as_inner().st_birthtime as i64
125+
}
126+
fn st_birthtime_nsec(&self) -> i64 {
127+
self.as_inner().as_inner().st_birthtime_nsec as i64
128+
}
129+
fn st_blksize(&self) -> u64 {
130+
self.as_inner().as_inner().st_blksize as u64
131+
}
132+
fn st_blocks(&self) -> u64 {
133+
self.as_inner().as_inner().st_blocks as u64
134+
}
135+
fn st_gen(&self) -> u32 {
136+
self.as_inner().as_inner().st_gen as u32
137+
}
138+
fn st_flags(&self) -> u32 {
139+
self.as_inner().as_inner().st_flags as u32
140+
}
141+
fn st_lspare(&self) -> u32 {
142+
self.as_inner().as_inner().st_lspare as u32
143+
}
144+
}
145+
146+
/// OS-specific extensions to [`fs::FileTimes`].
147+
#[stable(feature = "file_set_times", since = "1.75.0")]
148+
pub trait FileTimesExt: Sealed {
149+
/// Set the creation time of a file.
150+
#[stable(feature = "file_set_times", since = "1.75.0")]
151+
fn set_created(self, t: SystemTime) -> Self;
152+
}
153+
154+
#[stable(feature = "file_set_times", since = "1.75.0")]
155+
impl FileTimesExt for fs::FileTimes {
156+
fn set_created(mut self, t: SystemTime) -> Self {
157+
self.as_inner_mut().set_created(t.into_inner());
158+
self
159+
}
160+
}

std/src/os/xros/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! visionos-specific definitions
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
5+
pub mod fs;
6+
pub mod raw;

std/src/os/xros/raw.rs

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

0 commit comments

Comments
 (0)