Skip to content

Commit

Permalink
Auto merge of rust-lang#124491 - madsmtm:target_vendor-apple, r=worki…
Browse files Browse the repository at this point in the history
…ngjubilee

Use `target_vendor = "apple"` instead of `target_os = "..."`

Use `target_vendor = "apple"` instead of `all(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos")`.

The apple targets are quite close to being identical, with iOS, tvOS, watchOS and visionOS being even closer, so using `target_vendor` when possible makes it clearer when something is actually OS-specific, or just Apple-specific.
Note that `target_vendor` will [be deprecated in the future](rust-lang#100343), but not before an alternative (like `target_family = "apple"`) is available.

While doing this, I found various inconsistencies and small mistakes in the standard library, see the commits for details. Will follow-up with an extra PR for a similar issue that need a bit more discussion. EDIT: rust-lang#124494

Since you've talked about using `target_vendor = "apple"` in the past:
r? workingjubilee

CC `@simlay,` `@thomcc`
`@rustbot` label O-macos O-ios O-tvos O-watchos O-visionos
  • Loading branch information
bors committed Apr 30, 2024
2 parents f705de5 + f9f3573 commit cc65a5f
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 372 deletions.
23 changes: 7 additions & 16 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl fmt::Debug for c_void {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
all(target_arch = "aarch64", target_vendor = "apple"),
target_family = "wasm",
target_os = "uefi",
windows,
Expand Down Expand Up @@ -241,7 +241,7 @@ pub struct VaListImpl<'f> {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
all(target_arch = "aarch64", target_vendor = "apple"),
target_family = "wasm",
target_os = "uefi",
windows,
Expand All @@ -265,7 +265,7 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
/// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf
#[cfg(all(
target_arch = "aarch64",
not(any(target_os = "macos", target_os = "ios", target_os = "tvos")),
not(target_vendor = "apple"),
not(target_os = "uefi"),
not(windows),
))]
Expand Down Expand Up @@ -362,10 +362,7 @@ pub struct VaList<'a, 'f: 'a> {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(
target_arch = "aarch64",
any(target_os = "macos", target_os = "ios", target_os = "tvos")
),
all(target_arch = "aarch64", target_vendor = "apple"),
target_family = "wasm",
target_os = "uefi",
windows,
Expand All @@ -379,10 +376,7 @@ pub struct VaList<'a, 'f: 'a> {
target_arch = "s390x",
target_arch = "x86_64"
),
any(
not(target_arch = "aarch64"),
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
),
any(not(target_arch = "aarch64"), not(target_vendor = "apple")),
not(target_family = "wasm"),
not(target_os = "uefi"),
not(windows),
Expand All @@ -399,7 +393,7 @@ pub struct VaList<'a, 'f: 'a> {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
all(target_arch = "aarch64", target_vendor = "apple"),
target_family = "wasm",
target_os = "uefi",
windows,
Expand All @@ -425,10 +419,7 @@ impl<'f> VaListImpl<'f> {
target_arch = "s390x",
target_arch = "x86_64"
),
any(
not(target_arch = "aarch64"),
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
),
any(not(target_arch = "aarch64"), not(target_vendor = "apple")),
not(target_family = "wasm"),
not(target_os = "uefi"),
not(windows),
Expand Down
35 changes: 4 additions & 31 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,23 +1657,9 @@ fn test_file_times() {
let accessed = SystemTime::UNIX_EPOCH + Duration::from_secs(12345);
let modified = SystemTime::UNIX_EPOCH + Duration::from_secs(54321);
times = times.set_accessed(accessed).set_modified(modified);
#[cfg(any(
windows,
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
#[cfg(any(windows, target_vendor = "apple"))]
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
#[cfg(any(
windows,
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
#[cfg(any(windows, target_vendor = "apple"))]
{
times = times.set_created(created);
}
Expand All @@ -1698,27 +1684,14 @@ fn test_file_times() {
let metadata = file.metadata().unwrap();
assert_eq!(metadata.accessed().unwrap(), accessed);
assert_eq!(metadata.modified().unwrap(), modified);
#[cfg(any(
windows,
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
#[cfg(any(windows, target_vendor = "apple"))]
{
assert_eq!(metadata.created().unwrap(), created);
}
}

#[test]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
#[cfg(target_vendor = "apple")]
fn test_file_times_pre_epoch_with_nanos() {
#[cfg(target_os = "ios")]
use crate::os::ios::fs::FileTimesExt;
Expand Down
12 changes: 2 additions & 10 deletions library/std/src/os/unix/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ mod tests;
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "nto",
target_vendor = "apple",
))]
mod ucred;

Expand All @@ -44,14 +40,10 @@ pub use self::stream::*;
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "nto",
target_vendor = "apple",
))]
#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
pub use self::ucred::*;
16 changes: 4 additions & 12 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "nto"
target_os = "nto",
target_vendor = "apple",
))]
use super::{peer_cred, UCred};
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
Expand Down Expand Up @@ -231,14 +227,10 @@ impl UnixStream {
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "nto"
target_os = "nto",
target_vendor = "apple",
))]
pub fn peer_cred(&self) -> io::Result<UCred> {
peer_cred(self)
Expand Down
20 changes: 4 additions & 16 deletions library/std/src/os/unix/net/ucred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ pub(super) use self::impl_linux::peer_cred;
))]
pub(super) use self::impl_bsd::peer_cred;

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
pub(super) use self::impl_mac::peer_cred;
#[cfg(target_vendor = "apple")]
pub(super) use self::impl_apple::peer_cred;

#[cfg(any(target_os = "linux", target_os = "android"))]
mod impl_linux {
Expand Down Expand Up @@ -103,14 +97,8 @@ mod impl_bsd {
}
}

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
mod impl_mac {
#[cfg(target_vendor = "apple")]
mod impl_apple {
use super::UCred;
use crate::os::unix::io::AsRawFd;
use crate::os::unix::net::UnixStream;
Expand Down
17 changes: 3 additions & 14 deletions library/std/src/os/unix/net/ucred/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ use libc::{getegid, geteuid, getpid};
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "openbsd"
target_os = "openbsd",
target_vendor = "apple",
))]
fn test_socket_pair() {
// Create two connected sockets and get their peer credentials. They should be equal.
Expand All @@ -28,14 +24,7 @@ fn test_socket_pair() {
}

#[test]
#[cfg(any(
target_os = "linux",
target_os = "ios",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
fn test_socket_pair_pids(arg: Type) -> RetType {
// Create two connected sockets and get their peer credentials.
let (sock_a, sock_b) = UnixStream::pair().unwrap();
Expand Down
15 changes: 2 additions & 13 deletions library/std/src/sys/pal/unix/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,7 @@ mod imp {
}
}

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos"
))]
#[cfg(target_vendor = "apple")]
mod imp {
use super::Args;
use crate::ffi::CStr;
Expand Down Expand Up @@ -215,12 +209,7 @@ mod imp {
// for i in (0..[args count])
// res.push([args objectAtIndex:i])
// res
#[cfg(any(
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
#[cfg(not(target_os = "macos"))]
pub fn args() -> Args {
use crate::ffi::{c_char, c_void, OsString};
use crate::mem;
Expand Down

0 comments on commit cc65a5f

Please sign in to comment.