diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 5334c4dfc68cc..c953a53e0f9db 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -53,6 +53,9 @@ rustc_tsan = { path = "../librustc_tsan" } [target.'cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies] dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] } +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] +mach = { version = "0.3.2", default-features = false, features = ['rustc-dep-of-std'] } + [target.x86_64-fortanix-unknown-sgx.dependencies] fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 8fd76eabe3943..460d92d051966 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -338,6 +338,10 @@ extern crate alloc as alloc_crate; #[allow(unused_extern_crates)] extern crate libc; +#[cfg(any(target_os = "macos", target_os = "ios"))] +#[allow(unused_extern_crates)] +extern crate mach; + // We always need an unwinder currently for backtraces #[doc(masked)] #[allow(unused_extern_crates)] diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index e21c32cd91b1e..b7d2c4562f765 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -139,7 +139,7 @@ mod inner { impl Instant { pub fn now() -> Instant { - Instant { t: unsafe { libc::mach_absolute_time() } } + Instant { t: unsafe { mach::mach_time::mach_absolute_time() } } } pub const fn zero() -> Instant { @@ -230,8 +230,9 @@ mod inner { Some(mul_div_u64(nanos, info.denom as u64, info.numer as u64)) } - fn info() -> libc::mach_timebase_info { - static mut INFO: libc::mach_timebase_info = libc::mach_timebase_info { + fn info() -> mach::mach_time::mach_timebase_info { + static mut INFO: mach::mach_time::mach_timebase_info + = mach::mach_time::mach_timebase_info { numer: 0, denom: 0, }; @@ -245,7 +246,7 @@ mod inner { // ... otherwise learn for ourselves ... let mut info = mem::zeroed(); - libc::mach_timebase_info(&mut info); + mach::mach_time::mach_timebase_info(&mut info); // ... and attempt to be the one thread that stores it globally for // all other threads