Skip to content

Commit

Permalink
Remove mach dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Aug 1, 2019
1 parent 0b9d0b0 commit 74dc2b6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 0 additions & 3 deletions src/libstd/Cargo.toml
Expand Up @@ -53,9 +53,6 @@ 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'] }

Expand Down
4 changes: 0 additions & 4 deletions src/libstd/lib.rs
Expand Up @@ -338,10 +338,6 @@ 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)]
Expand Down
26 changes: 21 additions & 5 deletions src/libstd/sys/unix/time.rs
Expand Up @@ -137,9 +137,21 @@ mod inner {
t: Timespec::zero(),
};

#[repr(C)]
#[derive(Copy, Clone)]
struct mach_timebase_info {
numer: u32,
denom: u32,
}
type mach_timebase_info_t = *mut mach_timebase_info;
type kern_return_t = libc::c_int;

impl Instant {
pub fn now() -> Instant {
Instant { t: unsafe { mach::mach_time::mach_absolute_time() } }
extern "C" {
fn mach_absolute_time() -> u64;
}
Instant { t: unsafe { mach_absolute_time() } }
}

pub const fn zero() -> Instant {
Expand Down Expand Up @@ -230,9 +242,8 @@ mod inner {
Some(mul_div_u64(nanos, info.denom as u64, info.numer as u64))
}

fn info() -> mach::mach_time::mach_timebase_info {
static mut INFO: mach::mach_time::mach_timebase_info
= mach::mach_time::mach_timebase_info {
fn info() -> mach_timebase_info {
static mut INFO: mach_timebase_info = mach_timebase_info {
numer: 0,
denom: 0,
};
Expand All @@ -246,7 +257,12 @@ mod inner {

// ... otherwise learn for ourselves ...
let mut info = mem::zeroed();
mach::mach_time::mach_timebase_info(&mut info);
extern "C" {
fn mach_timebase_info(info: mach_timebase_info_t)
-> kern_return_t;
}

mach_timebase_info(&mut info);

// ... and attempt to be the one thread that stores it globally for
// all other threads
Expand Down
3 changes: 2 additions & 1 deletion src/tools/tidy/src/deps.rs
Expand Up @@ -48,11 +48,12 @@ const EXCEPTIONS: &[&str] = &[
"bytesize", // Apache-2.0, cargo
"im-rc", // MPL-2.0+, cargo
"adler32", // BSD-3-Clause AND Zlib, cargo dep that isn't used
"fortanix-sgx-abi", // MPL-2.0+, libstd but only for `sgx` target
"constant_time_eq", // CC0-1.0, rustfmt
"utf8parse", // Apache-2.0 OR MIT, cargo via strip-ansi-escapes
"vte", // Apache-2.0 OR MIT, cargo via strip-ansi-escapes
"sized-chunks", // MPL-2.0+, cargo via im-rc
// FIXME: this dependency violates the documentation comment above:
"fortanix-sgx-abi", // MPL-2.0+, libstd but only for `sgx` target
];

/// Which crates to check against the whitelist?
Expand Down

0 comments on commit 74dc2b6

Please sign in to comment.