Skip to content

Commit e95162f

Browse files
authored
refactor: enable most macOS funcs for apple_targets (#2241)
* refactor: enable most macOS funcs for apple_targets * respond to review * respond to review
1 parent 83dfd90 commit e95162f

File tree

16 files changed

+69
-76
lines changed

16 files changed

+69
-76
lines changed

changelog/2241.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`ClockId::set_time()` and `time::clock_settime()` are now enabled on macOS

src/mount/bsd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ libc_bitflags!(
3030
#[cfg(target_os = "freebsd")]
3131
MNT_GJOURNAL;
3232
/// MAC support for objects.
33-
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
33+
#[cfg(any(apple_targets, target_os = "freebsd"))]
3434
MNT_MULTILABEL;
3535
/// Disable read clustering.
3636
#[cfg(freebsdlike)]
@@ -58,7 +58,7 @@ libc_bitflags!(
5858
/// Create a snapshot of the file system.
5959
///
6060
/// See [mksnap_ffs(8)](https://www.freebsd.org/cgi/man.cgi?query=mksnap_ffs)
61-
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
61+
#[cfg(any(apple_targets, target_os = "freebsd"))]
6262
MNT_SNAPSHOT;
6363
/// Using soft updates.
6464
#[cfg(any(freebsdlike, netbsdlike))]
@@ -71,7 +71,7 @@ libc_bitflags!(
7171
MNT_SYNCHRONOUS;
7272
/// Union with underlying fs.
7373
#[cfg(any(
74-
target_os = "macos",
74+
apple_targets,
7575
target_os = "freebsd",
7676
target_os = "netbsd"
7777
))]

src/mount/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ mod linux;
55
#[cfg(linux_android)]
66
pub use self::linux::*;
77

8-
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
8+
#[cfg(bsd)]
99
mod bsd;
1010

11-
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
11+
#[cfg(bsd)]
1212
pub use self::bsd::*;

src/net/if_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ libc_bitflags!(
8282
#[cfg(any(linux_android, target_os = "fuchsia"))]
8383
IFF_SLAVE;
8484
/// Can't hear own transmissions.
85-
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
85+
#[cfg(bsd)]
8686
IFF_SIMPLEX;
8787
/// Supports multicast. (see
8888
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))

src/sys/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ libc_bitflags! {
191191
EV_NODATA;
192192
#[allow(missing_docs)]
193193
EV_ONESHOT;
194-
#[cfg(any(target_os = "macos", target_os = "tvos"))]
194+
#[cfg(apple_targets)]
195195
#[allow(missing_docs)]
196196
EV_OOBAND;
197197
#[cfg(apple_targets)]

src/sys/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ feature! {
6666
pub mod pthread;
6767
}
6868

69-
#[cfg(any(linux_android, freebsdlike, target_os = "macos", netbsdlike))]
69+
#[cfg(any(linux_android, bsd))]
7070
feature! {
7171
#![feature = "ptrace"]
7272
#[allow(missing_docs)]

src/sys/ptrace/bsd.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::ptr;
99
pub type RequestType = c_int;
1010

1111
cfg_if! {
12-
if #[cfg(any(freebsdlike, target_os = "macos", target_os = "openbsd"))] {
12+
if #[cfg(any(freebsdlike, apple_targets, target_os = "openbsd"))] {
1313
#[doc(hidden)]
1414
pub type AddressType = *mut ::libc::c_char;
1515
} else {
@@ -26,26 +26,26 @@ libc_enum! {
2626
PT_TRACE_ME,
2727
PT_READ_I,
2828
PT_READ_D,
29-
#[cfg(target_os = "macos")]
29+
#[cfg(apple_targets)]
3030
PT_READ_U,
3131
PT_WRITE_I,
3232
PT_WRITE_D,
33-
#[cfg(target_os = "macos")]
33+
#[cfg(apple_targets)]
3434
PT_WRITE_U,
3535
PT_CONTINUE,
3636
PT_KILL,
37-
#[cfg(any(any(freebsdlike, target_os = "macos"),
37+
#[cfg(any(any(freebsdlike, apple_targets),
3838
all(target_os = "openbsd", target_arch = "x86_64"),
3939
all(target_os = "netbsd", any(target_arch = "x86_64",
4040
target_arch = "powerpc"))))]
4141
PT_STEP,
4242
PT_ATTACH,
4343
PT_DETACH,
44-
#[cfg(target_os = "macos")]
44+
#[cfg(apple_targets)]
4545
PT_SIGEXC,
46-
#[cfg(target_os = "macos")]
46+
#[cfg(apple_targets)]
4747
PT_THUPDATE,
48-
#[cfg(target_os = "macos")]
48+
#[cfg(apple_targets)]
4949
PT_ATTACHEXC
5050
}
5151
}
@@ -149,7 +149,7 @@ pub fn kill(pid: Pid) -> Result<()> {
149149
/// }
150150
/// ```
151151
#[cfg(any(
152-
any(freebsdlike, target_os = "macos"),
152+
any(freebsdlike, apple_targets),
153153
all(target_os = "openbsd", target_arch = "x86_64"),
154154
all(
155155
target_os = "netbsd",

src/sys/ptrace/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ mod linux;
66
#[cfg(linux_android)]
77
pub use self::linux::*;
88

9-
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
9+
#[cfg(bsd)]
1010
mod bsd;
1111

12-
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
12+
#[cfg(bsd)]
1313
pub use self::bsd::*;

src/sys/socket/addr.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
))]
99
#[cfg(feature = "net")]
1010
pub use self::datalink::LinkAddr;
11-
#[cfg(any(linux_android, target_os = "macos"))]
11+
#[cfg(any(linux_android, apple_targets))]
1212
pub use self::vsock::VsockAddr;
1313
use super::sa_family_t;
1414
use crate::errno::Errno;
@@ -197,7 +197,7 @@ pub enum AddressFamily {
197197
#[cfg(target_os = "linux")]
198198
Nfc = libc::AF_NFC,
199199
/// VMWare VSockets protocol for hypervisor-guest interaction.
200-
#[cfg(any(linux_android, target_os = "macos"))]
200+
#[cfg(any(linux_android, apple_targets))]
201201
Vsock = libc::AF_VSOCK,
202202
/// ARPANet IMP addresses
203203
#[cfg(bsd)]
@@ -259,15 +259,15 @@ impl AddressFamily {
259259
libc::AF_INET6 => Some(AddressFamily::Inet6),
260260
#[cfg(linux_android)]
261261
libc::AF_NETLINK => Some(AddressFamily::Netlink),
262-
#[cfg(target_os = "macos")]
262+
#[cfg(apple_targets)]
263263
libc::AF_SYSTEM => Some(AddressFamily::System),
264264
#[cfg(not(any(linux_android, target_os = "redox")))]
265265
libc::PF_ROUTE => Some(AddressFamily::Route),
266266
#[cfg(linux_android)]
267267
libc::AF_PACKET => Some(AddressFamily::Packet),
268268
#[cfg(any(bsd, target_os = "illumos"))]
269269
libc::AF_LINK => Some(AddressFamily::Link),
270-
#[cfg(any(linux_android, target_os = "macos"))]
270+
#[cfg(any(linux_android, apple_targets))]
271271
libc::AF_VSOCK => Some(AddressFamily::Vsock),
272272
_ => None,
273273
}
@@ -1078,7 +1078,7 @@ pub union SockaddrStorage {
10781078
sin6: SockaddrIn6,
10791079
ss: libc::sockaddr_storage,
10801080
su: UnixAddr,
1081-
#[cfg(any(linux_android, target_os = "macos"))]
1081+
#[cfg(any(linux_android, apple_targets))]
10821082
vsock: VsockAddr,
10831083
}
10841084
impl private::SockaddrLikePriv for SockaddrStorage {}
@@ -1154,7 +1154,7 @@ impl SockaddrLike for SockaddrStorage {
11541154
libc::AF_SYSTEM => unsafe {
11551155
SysControlAddr::from_raw(addr, l).map(|sctl| Self { sctl })
11561156
},
1157-
#[cfg(any(linux_android, target_os = "macos"))]
1157+
#[cfg(any(linux_android, apple_targets))]
11581158
libc::AF_VSOCK => unsafe {
11591159
VsockAddr::from_raw(addr, l).map(|vsock| Self { vsock })
11601160
},
@@ -1312,7 +1312,7 @@ impl SockaddrStorage {
13121312
accessors! {as_sys_control_addr, as_sys_control_addr_mut, SysControlAddr,
13131313
AddressFamily::System, libc::sockaddr_ctl, sctl}
13141314

1315-
#[cfg(any(linux_android, target_os = "macos"))]
1315+
#[cfg(any(linux_android, apple_targets))]
13161316
accessors! {as_vsock_addr, as_vsock_addr_mut, VsockAddr,
13171317
AddressFamily::Vsock, libc::sockaddr_vm, vsock}
13181318
}
@@ -1349,7 +1349,7 @@ impl fmt::Display for SockaddrStorage {
13491349
#[cfg(feature = "ioctl")]
13501350
libc::AF_SYSTEM => self.sctl.fmt(f),
13511351
libc::AF_UNIX => self.su.fmt(f),
1352-
#[cfg(any(linux_android, target_os = "macos"))]
1352+
#[cfg(any(linux_android, apple_targets))]
13531353
libc::AF_VSOCK => self.vsock.fmt(f),
13541354
_ => "<Address family unspecified>".fmt(f),
13551355
}
@@ -1411,7 +1411,7 @@ impl Hash for SockaddrStorage {
14111411
#[cfg(feature = "ioctl")]
14121412
libc::AF_SYSTEM => self.sctl.hash(s),
14131413
libc::AF_UNIX => self.su.hash(s),
1414-
#[cfg(any(linux_android, target_os = "macos"))]
1414+
#[cfg(any(linux_android, apple_targets))]
14151415
libc::AF_VSOCK => self.vsock.hash(s),
14161416
_ => self.ss.hash(s),
14171417
}
@@ -1441,7 +1441,7 @@ impl PartialEq for SockaddrStorage {
14411441
#[cfg(feature = "ioctl")]
14421442
(libc::AF_SYSTEM, libc::AF_SYSTEM) => self.sctl == other.sctl,
14431443
(libc::AF_UNIX, libc::AF_UNIX) => self.su == other.su,
1444-
#[cfg(any(linux_android, target_os = "macos"))]
1444+
#[cfg(any(linux_android, apple_targets))]
14451445
(libc::AF_VSOCK, libc::AF_VSOCK) => self.vsock == other.vsock,
14461446
_ => false,
14471447
}
@@ -1972,7 +1972,7 @@ mod datalink {
19721972
}
19731973
}
19741974

1975-
#[cfg(any(linux_android, target_os = "macos"))]
1975+
#[cfg(any(linux_android, apple_targets))]
19761976
pub mod vsock {
19771977
use super::*;
19781978
use crate::sys::socket::addr::AddressFamily;
@@ -2023,7 +2023,7 @@ pub mod vsock {
20232023
(inner.svm_family, inner.svm_cid, inner.svm_port)
20242024
== (other.svm_family, other.svm_cid, other.svm_port)
20252025
}
2026-
#[cfg(target_os = "macos")]
2026+
#[cfg(apple_targets)]
20272027
fn eq(&self, other: &Self) -> bool {
20282028
let (inner, other) = (self.0, other.0);
20292029
(
@@ -2048,7 +2048,7 @@ pub mod vsock {
20482048
let inner = self.0;
20492049
(inner.svm_family, inner.svm_cid, inner.svm_port).hash(s);
20502050
}
2051-
#[cfg(target_os = "macos")]
2051+
#[cfg(apple_targets)]
20522052
fn hash<H: Hasher>(&self, s: &mut H) {
20532053
let inner = self.0;
20542054
(
@@ -2073,7 +2073,7 @@ pub mod vsock {
20732073
addr.svm_cid = cid;
20742074
addr.svm_port = port;
20752075

2076-
#[cfg(target_os = "macos")]
2076+
#[cfg(apple_targets)]
20772077
{
20782078
addr.svm_len = std::mem::size_of::<sockaddr_vm>() as u8;
20792079
}

src/sys/socket/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub use crate::sys::socket::addr::netlink::NetlinkAddr;
5252
#[cfg(apple_targets)]
5353
#[cfg(feature = "ioctl")]
5454
pub use crate::sys::socket::addr::sys_control::SysControlAddr;
55-
#[cfg(any(linux_android, target_os = "macos"))]
55+
#[cfg(any(linux_android, apple_targets))]
5656
pub use crate::sys::socket::addr::vsock::VsockAddr;
5757

5858
#[cfg(all(feature = "uio", not(target_os = "redox")))]

0 commit comments

Comments
 (0)