Skip to content

Commit dda7364

Browse files
committed
Auto merge of rust-lang#124491 - madsmtm:target_vendor-apple, r=workingjubilee
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
2 parents ddf4a17 + 4a2abd3 commit dda7364

File tree

20 files changed

+88
-370
lines changed

20 files changed

+88
-370
lines changed

Diff for: core/src/ffi/mod.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl fmt::Debug for c_void {
213213
not(target_arch = "s390x"),
214214
not(target_arch = "x86_64")
215215
),
216-
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
216+
all(target_arch = "aarch64", target_vendor = "apple"),
217217
target_family = "wasm",
218218
target_os = "uefi",
219219
windows,
@@ -241,7 +241,7 @@ pub struct VaListImpl<'f> {
241241
not(target_arch = "s390x"),
242242
not(target_arch = "x86_64")
243243
),
244-
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
244+
all(target_arch = "aarch64", target_vendor = "apple"),
245245
target_family = "wasm",
246246
target_os = "uefi",
247247
windows,
@@ -265,7 +265,7 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
265265
/// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf
266266
#[cfg(all(
267267
target_arch = "aarch64",
268-
not(any(target_os = "macos", target_os = "ios", target_os = "tvos")),
268+
not(target_vendor = "apple"),
269269
not(target_os = "uefi"),
270270
not(windows),
271271
))]
@@ -362,10 +362,7 @@ pub struct VaList<'a, 'f: 'a> {
362362
not(target_arch = "s390x"),
363363
not(target_arch = "x86_64")
364364
),
365-
all(
366-
target_arch = "aarch64",
367-
any(target_os = "macos", target_os = "ios", target_os = "tvos")
368-
),
365+
all(target_arch = "aarch64", target_vendor = "apple"),
369366
target_family = "wasm",
370367
target_os = "uefi",
371368
windows,
@@ -379,10 +376,7 @@ pub struct VaList<'a, 'f: 'a> {
379376
target_arch = "s390x",
380377
target_arch = "x86_64"
381378
),
382-
any(
383-
not(target_arch = "aarch64"),
384-
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
385-
),
379+
any(not(target_arch = "aarch64"), not(target_vendor = "apple")),
386380
not(target_family = "wasm"),
387381
not(target_os = "uefi"),
388382
not(windows),
@@ -399,7 +393,7 @@ pub struct VaList<'a, 'f: 'a> {
399393
not(target_arch = "s390x"),
400394
not(target_arch = "x86_64")
401395
),
402-
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
396+
all(target_arch = "aarch64", target_vendor = "apple"),
403397
target_family = "wasm",
404398
target_os = "uefi",
405399
windows,
@@ -425,10 +419,7 @@ impl<'f> VaListImpl<'f> {
425419
target_arch = "s390x",
426420
target_arch = "x86_64"
427421
),
428-
any(
429-
not(target_arch = "aarch64"),
430-
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
431-
),
422+
any(not(target_arch = "aarch64"), not(target_vendor = "apple")),
432423
not(target_family = "wasm"),
433424
not(target_os = "uefi"),
434425
not(windows),

Diff for: std/src/fs/tests.rs

+4-31
Original file line numberDiff line numberDiff line change
@@ -1657,23 +1657,9 @@ fn test_file_times() {
16571657
let accessed = SystemTime::UNIX_EPOCH + Duration::from_secs(12345);
16581658
let modified = SystemTime::UNIX_EPOCH + Duration::from_secs(54321);
16591659
times = times.set_accessed(accessed).set_modified(modified);
1660-
#[cfg(any(
1661-
windows,
1662-
target_os = "macos",
1663-
target_os = "ios",
1664-
target_os = "watchos",
1665-
target_os = "visionos",
1666-
target_os = "tvos",
1667-
))]
1660+
#[cfg(any(windows, target_vendor = "apple"))]
16681661
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
1669-
#[cfg(any(
1670-
windows,
1671-
target_os = "macos",
1672-
target_os = "ios",
1673-
target_os = "watchos",
1674-
target_os = "visionos",
1675-
target_os = "tvos",
1676-
))]
1662+
#[cfg(any(windows, target_vendor = "apple"))]
16771663
{
16781664
times = times.set_created(created);
16791665
}
@@ -1698,27 +1684,14 @@ fn test_file_times() {
16981684
let metadata = file.metadata().unwrap();
16991685
assert_eq!(metadata.accessed().unwrap(), accessed);
17001686
assert_eq!(metadata.modified().unwrap(), modified);
1701-
#[cfg(any(
1702-
windows,
1703-
target_os = "macos",
1704-
target_os = "ios",
1705-
target_os = "watchos",
1706-
target_os = "visionos",
1707-
target_os = "tvos",
1708-
))]
1687+
#[cfg(any(windows, target_vendor = "apple"))]
17091688
{
17101689
assert_eq!(metadata.created().unwrap(), created);
17111690
}
17121691
}
17131692

17141693
#[test]
1715-
#[cfg(any(
1716-
target_os = "macos",
1717-
target_os = "ios",
1718-
target_os = "tvos",
1719-
target_os = "watchos",
1720-
target_os = "visionos"
1721-
))]
1694+
#[cfg(target_vendor = "apple")]
17221695
fn test_file_times_pre_epoch_with_nanos() {
17231696
#[cfg(target_os = "ios")]
17241697
use crate::os::ios::fs::FileTimesExt;

Diff for: std/src/os/unix/net/mod.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ mod tests;
1717
target_os = "linux",
1818
target_os = "dragonfly",
1919
target_os = "freebsd",
20-
target_os = "ios",
21-
target_os = "tvos",
22-
target_os = "watchos",
23-
target_os = "visionos",
24-
target_os = "macos",
2520
target_os = "netbsd",
2621
target_os = "openbsd",
2722
target_os = "nto",
23+
target_vendor = "apple",
2824
))]
2925
mod ucred;
3026

@@ -44,14 +40,10 @@ pub use self::stream::*;
4440
target_os = "linux",
4541
target_os = "dragonfly",
4642
target_os = "freebsd",
47-
target_os = "ios",
48-
target_os = "tvos",
49-
target_os = "watchos",
50-
target_os = "visionos",
51-
target_os = "macos",
5243
target_os = "netbsd",
5344
target_os = "openbsd",
5445
target_os = "nto",
46+
target_vendor = "apple",
5547
))]
5648
#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
5749
pub use self::ucred::*;

Diff for: std/src/os/unix/net/stream.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
target_os = "linux",
44
target_os = "dragonfly",
55
target_os = "freebsd",
6-
target_os = "ios",
7-
target_os = "tvos",
8-
target_os = "macos",
9-
target_os = "watchos",
10-
target_os = "visionos",
116
target_os = "netbsd",
127
target_os = "openbsd",
13-
target_os = "nto"
8+
target_os = "nto",
9+
target_vendor = "apple",
1410
))]
1511
use super::{peer_cred, UCred};
1612
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
@@ -231,14 +227,10 @@ impl UnixStream {
231227
target_os = "linux",
232228
target_os = "dragonfly",
233229
target_os = "freebsd",
234-
target_os = "ios",
235-
target_os = "tvos",
236-
target_os = "macos",
237-
target_os = "watchos",
238-
target_os = "visionos",
239230
target_os = "netbsd",
240231
target_os = "openbsd",
241-
target_os = "nto"
232+
target_os = "nto",
233+
target_vendor = "apple",
242234
))]
243235
pub fn peer_cred(&self) -> io::Result<UCred> {
244236
peer_cred(self)

Diff for: std/src/os/unix/net/ucred.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,8 @@ pub(super) use self::impl_linux::peer_cred;
3535
))]
3636
pub(super) use self::impl_bsd::peer_cred;
3737

38-
#[cfg(any(
39-
target_os = "macos",
40-
target_os = "ios",
41-
target_os = "tvos",
42-
target_os = "watchos",
43-
target_os = "visionos"
44-
))]
45-
pub(super) use self::impl_mac::peer_cred;
38+
#[cfg(target_vendor = "apple")]
39+
pub(super) use self::impl_apple::peer_cred;
4640

4741
#[cfg(any(target_os = "linux", target_os = "android"))]
4842
mod impl_linux {
@@ -103,14 +97,8 @@ mod impl_bsd {
10397
}
10498
}
10599

106-
#[cfg(any(
107-
target_os = "macos",
108-
target_os = "ios",
109-
target_os = "tvos",
110-
target_os = "watchos",
111-
target_os = "visionos"
112-
))]
113-
mod impl_mac {
100+
#[cfg(target_vendor = "apple")]
101+
mod impl_apple {
114102
use super::UCred;
115103
use crate::os::unix::io::AsRawFd;
116104
use crate::os::unix::net::UnixStream;

Diff for: std/src/os/unix/net/ucred/tests.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ use libc::{getegid, geteuid, getpid};
77
target_os = "linux",
88
target_os = "dragonfly",
99
target_os = "freebsd",
10-
target_os = "ios",
11-
target_os = "tvos",
12-
target_os = "macos",
13-
target_os = "watchos",
14-
target_os = "visionos",
15-
target_os = "openbsd"
10+
target_os = "openbsd",
11+
target_vendor = "apple",
1612
))]
1713
fn test_socket_pair() {
1814
// Create two connected sockets and get their peer credentials. They should be equal.
@@ -28,14 +24,7 @@ fn test_socket_pair() {
2824
}
2925

3026
#[test]
31-
#[cfg(any(
32-
target_os = "linux",
33-
target_os = "ios",
34-
target_os = "macos",
35-
target_os = "watchos",
36-
target_os = "visionos",
37-
target_os = "tvos",
38-
))]
27+
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
3928
fn test_socket_pair_pids(arg: Type) -> RetType {
4029
// Create two connected sockets and get their peer credentials.
4130
let (sock_a, sock_b) = UnixStream::pair().unwrap();

Diff for: std/src/sys/pal/unix/args.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,7 @@ mod imp {
168168
}
169169
}
170170

171-
#[cfg(any(
172-
target_os = "macos",
173-
target_os = "ios",
174-
target_os = "watchos",
175-
target_os = "visionos",
176-
target_os = "tvos"
177-
))]
171+
#[cfg(target_vendor = "apple")]
178172
mod imp {
179173
use super::Args;
180174
use crate::ffi::CStr;
@@ -215,12 +209,7 @@ mod imp {
215209
// for i in (0..[args count])
216210
// res.push([args objectAtIndex:i])
217211
// res
218-
#[cfg(any(
219-
target_os = "ios",
220-
target_os = "tvos",
221-
target_os = "watchos",
222-
target_os = "visionos"
223-
))]
212+
#[cfg(not(target_os = "macos"))]
224213
pub fn args() -> Args {
225214
use crate::ffi::{c_char, c_void, OsString};
226215
use crate::mem;

0 commit comments

Comments
 (0)