Skip to content

Commit 8d51e85

Browse files
Rollup merge of rust-lang#124788 - madsmtm:reduce-target_os-macos, r=workingjubilee
Convert instances of `target_os = "macos"` to `target_vendor = "apple"` rust-lang#124491 migrated towards using `target_vendor = "apple"` more, as there's very little difference between iOS, tvOS, watchOS and visionOS. In that PR, I only did the changes where the standard library already had fixes for iOS, that I could confidently apply to the other targets. However, there's actually also not that big of a gap between macOS and the aforementioned platforms - so in this PR, I've gone through a few of the instances of `target_os = "macos"` and replaced it with `target_vendor = "apple"` to improve support on those platforms, see the commits for details. r? workingjubilee CC `@thomcc` `@simlay` (do tell me if I should stop pinging you on these Apple PRs) `@rustbot` label O-apple
2 parents ce2c462 + c4e5d54 commit 8d51e85

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,25 @@ impl UnixListener {
8181
))]
8282
const backlog: core::ffi::c_int = 128;
8383
#[cfg(any(
84+
// Silently capped to `/proc/sys/net/core/somaxconn`.
8485
target_os = "linux",
86+
// Silently capped to `kern.ipc.soacceptqueue`.
8587
target_os = "freebsd",
88+
// Silently capped to `kern.somaxconn sysctl`.
8689
target_os = "openbsd",
87-
target_os = "macos"
90+
// Silently capped to the default 128.
91+
target_vendor = "apple",
8892
))]
8993
const backlog: core::ffi::c_int = -1;
9094
#[cfg(not(any(
9195
target_os = "windows",
9296
target_os = "redox",
97+
target_os = "espidf",
98+
target_os = "horizon",
9399
target_os = "linux",
94100
target_os = "freebsd",
95101
target_os = "openbsd",
96-
target_os = "macos",
97-
target_os = "espidf",
98-
target_os = "horizon"
102+
target_vendor = "apple",
99103
)))]
100104
const backlog: libc::c_int = libc::SOMAXCONN;
101105

std/src/sys/pal/unix/alloc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ unsafe impl GlobalAlloc for System {
1313
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
1414
libc::malloc(layout.size()) as *mut u8
1515
} else {
16-
#[cfg(target_os = "macos")]
16+
// `posix_memalign` returns a non-aligned value if supplied a very
17+
// large alignment on older versions of Apple's platforms (unknown
18+
// exactly which version range, but the issue is definitely
19+
// present in macOS 10.14 and iOS 13.3).
20+
//
21+
// <https://github.com/rust-lang/rust/issues/30170>
22+
#[cfg(target_vendor = "apple")]
1723
{
1824
if layout.align() > (1 << 31) {
1925
return ptr::null_mut();

std/src/sys/pal/unix/fd.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ pub struct FileDesc(OwnedFd);
3333
// with the man page quoting that if the count of bytes to read is
3434
// greater than `SSIZE_MAX` the result is "unspecified".
3535
//
36-
// On macOS, however, apparently the 64-bit libc is either buggy or
36+
// On Apple targets however, apparently the 64-bit libc is either buggy or
3737
// intentionally showing odd behavior by rejecting any read with a size
3838
// larger than or equal to INT_MAX. To handle both of these the read
3939
// size is capped on both platforms.
40-
#[cfg(target_os = "macos")]
41-
const READ_LIMIT: usize = libc::c_int::MAX as usize - 1;
42-
#[cfg(not(target_os = "macos"))]
43-
const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
40+
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
41+
libc::c_int::MAX as usize - 1
42+
} else {
43+
libc::ssize_t::MAX as usize
44+
};
4445

4546
#[cfg(any(
4647
target_os = "dragonfly",

std/src/sys/pal/unix/fs.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1493,11 +1493,11 @@ impl fmt::Debug for File {
14931493
readlink(&p).ok()
14941494
}
14951495

1496-
#[cfg(target_os = "macos")]
1496+
#[cfg(target_vendor = "apple")]
14971497
fn get_path(fd: c_int) -> Option<PathBuf> {
14981498
// FIXME: The use of PATH_MAX is generally not encouraged, but it
1499-
// is inevitable in this case because macOS defines `fcntl` with
1500-
// `F_GETPATH` in terms of `MAXPATHLEN`, and there are no
1499+
// is inevitable in this case because Apple targets define `fcntl`
1500+
// with `F_GETPATH` in terms of `MAXPATHLEN`, and there are no
15011501
// alternatives. If a better method is invented, it should be used
15021502
// instead.
15031503
let mut buf = vec![0; libc::PATH_MAX as usize];
@@ -1538,12 +1538,12 @@ impl fmt::Debug for File {
15381538

15391539
#[cfg(not(any(
15401540
target_os = "linux",
1541-
target_os = "macos",
15421541
target_os = "vxworks",
15431542
all(target_os = "freebsd", target_arch = "x86_64"),
15441543
target_os = "netbsd",
15451544
target_os = "illumos",
1546-
target_os = "solaris"
1545+
target_os = "solaris",
1546+
target_vendor = "apple",
15471547
)))]
15481548
fn get_path(_fd: c_int) -> Option<PathBuf> {
15491549
// FIXME(#24570): implement this for other Unix platforms
@@ -1552,12 +1552,12 @@ impl fmt::Debug for File {
15521552

15531553
#[cfg(any(
15541554
target_os = "linux",
1555-
target_os = "macos",
15561555
target_os = "freebsd",
15571556
target_os = "hurd",
15581557
target_os = "netbsd",
15591558
target_os = "openbsd",
1560-
target_os = "vxworks"
1559+
target_os = "vxworks",
1560+
target_vendor = "apple",
15611561
))]
15621562
fn get_mode(fd: c_int) -> Option<(bool, bool)> {
15631563
let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) };
@@ -1574,12 +1574,12 @@ impl fmt::Debug for File {
15741574

15751575
#[cfg(not(any(
15761576
target_os = "linux",
1577-
target_os = "macos",
15781577
target_os = "freebsd",
15791578
target_os = "hurd",
15801579
target_os = "netbsd",
15811580
target_os = "openbsd",
1582-
target_os = "vxworks"
1581+
target_os = "vxworks",
1582+
target_vendor = "apple",
15831583
)))]
15841584
fn get_mode(_fd: c_int) -> Option<(bool, bool)> {
15851585
// FIXME(#24570): implement this for other Unix platforms

std/src/sys/pal/unix/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
6363
args::init(argc, argv);
6464

6565
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread
66-
// already exists, we have to call it ourselves. We only do this on macos
66+
// already exists, we have to call it ourselves. We only do this on Apple targets
6767
// because some unix-like operating systems such as Linux share process-id and
6868
// thread-id for the main thread and so renaming the main thread will rename the
6969
// process and we only want to enable this on platforms we've tested.
70-
if cfg!(target_os = "macos") {
70+
if cfg!(target_vendor = "apple") {
7171
thread::Thread::set_name(&c"main");
7272
}
7373

0 commit comments

Comments
 (0)