Skip to content

Commit

Permalink
Merge Apple std::os extensions modules into std::os::darwin
Browse files Browse the repository at this point in the history
The functionality available on Apple platforms are very similar, and
were duplicated for each platform.

Additionally, this fixes a warning when compiling the standard library
for tvOS, watchOS and visionOS by marking the corresponding code as
dead code.
  • Loading branch information
madsmtm committed Jul 14, 2024
1 parent 12ec5b7 commit cfb0556
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 797 deletions.
23 changes: 3 additions & 20 deletions std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,16 +1638,8 @@ fn rename_directory() {

#[test]
fn test_file_times() {
#[cfg(target_os = "ios")]
use crate::os::ios::fs::FileTimesExt;
#[cfg(target_os = "macos")]
use crate::os::macos::fs::FileTimesExt;
#[cfg(target_os = "tvos")]
use crate::os::tvos::fs::FileTimesExt;
#[cfg(target_os = "visionos")]
use crate::os::visionos::fs::FileTimesExt;
#[cfg(target_os = "watchos")]
use crate::os::watchos::fs::FileTimesExt;
#[cfg(target_vendor = "apple")]
use crate::os::darwin::fs::FileTimesExt;
#[cfg(windows)]
use crate::os::windows::fs::FileTimesExt;

Expand Down Expand Up @@ -1693,16 +1685,7 @@ fn test_file_times() {
#[test]
#[cfg(target_vendor = "apple")]
fn test_file_times_pre_epoch_with_nanos() {
#[cfg(target_os = "ios")]
use crate::os::ios::fs::FileTimesExt;
#[cfg(target_os = "macos")]
use crate::os::macos::fs::FileTimesExt;
#[cfg(target_os = "tvos")]
use crate::os::tvos::fs::FileTimesExt;
#[cfg(target_os = "visionos")]
use crate::os::visionos::fs::FileTimesExt;
#[cfg(target_os = "watchos")]
use crate::os::watchos::fs::FileTimesExt;
use crate::os::darwin::fs::FileTimesExt;

let tmp = tmpdir();
let file = File::create(tmp.join("foo")).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions std/src/os/macos/fs.rs → std/src/os/darwin/fs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]
#![allow(dead_code)]

use crate::fs::{self, Metadata};
use crate::sealed::Sealed;
use crate::sys_common::{AsInner, AsInnerMut, IntoInner};
use crate::time::SystemTime;

#[allow(deprecated)]
use crate::os::macos::raw;
use super::raw;

/// OS-specific extensions to [`fs::Metadata`].
///
Expand Down Expand Up @@ -70,6 +70,7 @@ pub trait MetadataExt {
fn st_gen(&self) -> u32;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_lspare(&self) -> u32;
#[cfg(target_os = "macos")]
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_qspare(&self) -> [u64; 2];
}
Expand Down Expand Up @@ -143,6 +144,7 @@ impl MetadataExt for Metadata {
fn st_lspare(&self) -> u32 {
self.as_inner().as_inner().st_lspare as u32
}
#[cfg(target_os = "macos")]
fn st_qspare(&self) -> [u64; 2] {
let qspare = self.as_inner().as_inner().st_qspare;
[qspare[0] as u64, qspare[1] as u64]
Expand Down
20 changes: 20 additions & 0 deletions std/src/os/darwin/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Platform-specific extensions to `std` for Darwin / Apple platforms.
//!
//! This is available on the following operating systems:
//! - macOS
//! - iOS
//! - tvOS
//! - watchOS
//! - visionOS
//!
//! Note: This module is called "Darwin" as that's the name of the underlying
//! core OS of the above operating systems, but it should not be confused with
//! the `-darwin` suffix in the `x86_64-apple-darwin` and
//! `aarch64-apple-darwin` target names, which are mostly named that way for
//! legacy reasons.
pub(crate) mod fs;
// deprecated, but used for public reexport under `std::os::unix::raw`, as
// well as `std::os::macos`/`std::os::ios`, because those modules precede the
// decision to remove these.
pub(super) mod raw;
14 changes: 2 additions & 12 deletions std/src/os/ios/raw.rs → std/src/os/darwin/raw.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
//! iOS-specific raw type definitions
#![stable(feature = "raw_ext", since = "1.1.0")]
#![deprecated(
since = "1.8.0",
note = "these type aliases are no longer supported by \
the standard library, the `libc` crate on \
crates.io should be used instead for the correct \
definitions"
)]
#![allow(deprecated)]

//! Apple-specific raw type definitions
use crate::os::raw::c_long;

#[stable(feature = "raw_ext", since = "1.1.0")]
Expand All @@ -35,6 +24,7 @@ pub type pthread_t = usize;
#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
#[allow(dead_code)]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_dev: i32,
Expand Down
160 changes: 0 additions & 160 deletions std/src/os/ios/fs.rs

This file was deleted.

28 changes: 26 additions & 2 deletions std/src/os/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,29 @@
#![stable(feature = "raw_ext", since = "1.1.0")]

pub mod fs;
pub mod raw;
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub mod fs {
#[doc(inline)]
#[stable(feature = "file_set_times", since = "1.75.0")]
pub use crate::os::darwin::fs::FileTimesExt;

#[doc(inline)]
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub use crate::os::darwin::fs::MetadataExt;
}

/// iOS-specific raw type definitions
#[stable(feature = "raw_ext", since = "1.1.0")]
#[deprecated(
since = "1.8.0",
note = "these type aliases are no longer supported by \
the standard library, the `libc` crate on \
crates.io should be used instead for the correct \
definitions"
)]
#[allow(deprecated)]
pub mod raw {
#[doc(inline)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub use crate::os::darwin::raw::*;
}
28 changes: 26 additions & 2 deletions std/src/os/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,29 @@
#![stable(feature = "raw_ext", since = "1.1.0")]

pub mod fs;
pub mod raw;
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub mod fs {
#[doc(inline)]
#[stable(feature = "file_set_times", since = "1.75.0")]
pub use crate::os::darwin::fs::FileTimesExt;

#[doc(inline)]
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub use crate::os::darwin::fs::MetadataExt;
}

/// macOS-specific raw type definitions
#[stable(feature = "raw_ext", since = "1.1.0")]
#[deprecated(
since = "1.8.0",
note = "these type aliases are no longer supported by \
the standard library, the `libc` crate on \
crates.io should be used instead for the correct \
definitions"
)]
#[allow(deprecated)]
pub mod raw {
#[doc(inline)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub use crate::os::darwin::raw::*;
}
Loading

0 comments on commit cfb0556

Please sign in to comment.