Skip to content

Commit

Permalink
time.rs: fix branching error conditional compilation
Browse files Browse the repository at this point in the history
libc uses macro cfg_if, which is if-else branching, so conditions based
on environments have precedence over os-based cases. For instance, a
value that exists in the linux mod of libc would not only require the OS
to be linux, but the environment to NOT be uclibc or newlib
  • Loading branch information
kevinwern committed Sep 22, 2019
1 parent 135c440 commit 396b189
Showing 1 changed file with 71 additions and 40 deletions.
111 changes: 71 additions & 40 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,51 @@ use libc;

libc_enum! {
#[cfg_attr(any(
target_env = "uclibc",
all(target_env = "newlib", target_arch = "arm"),
target_os = "fuchsia",
target_os = "redox",
target_env = "uclibc",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "haiku",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "solaris",
target_os = "illumos",
all(target_env = "newlib", target_arch = "arm"),
all(not(target_env = "newlib"),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "solaris",
target_os = "illumos")),
), repr(i32))]
#[cfg_attr(any(target_os = "macos", target_os = "ios"), repr(u32))]
#[cfg_attr(any(
target_os = "hermit",
all(target_env = "newlib", target_arch = "aarch64"),
all(not(any(target_env = "newlib", target_env = "uclibc")), target_os = "hermit"),
target_os = "dragonfly",
), repr(u64))]
pub enum ClockId {
#[cfg(any(target_os = "fuchsia",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
all(not(any(target_env = "uclibc",
target_env = "newlib")),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten"),
)
))]
CLOCK_BOOTTIME,
#[cfg(any(target_os = "fuchsia",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
all(not(any(target_env = "uclibc",
target_env = "newlib")),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))))]
CLOCK_BOOTTIME_ALARM,
CLOCK_MONOTONIC,
#[cfg(any(target_os = "fuchsia",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
all(not(any(target_env = "uclibc",
target_env = "newlib")),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))))]
CLOCK_MONOTONIC_COARSE,
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly"))]
Expand All @@ -49,33 +58,40 @@ libc_enum! {
target_os = "dragonfly"))]
CLOCK_MONOTONIC_PRECISE,
#[cfg(any(target_os = "fuchsia",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
all(not(any(target_env = "uclibc",
target_env = "newlib")),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))))]
CLOCK_MONOTONIC_RAW,
#[cfg(any(target_os = "fuchsia",
target_env = "uclibc",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
all(not(target_env = "newlib"),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))))]
CLOCK_PROCESS_CPUTIME_ID,
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly"))]
CLOCK_PROF,
CLOCK_REALTIME,
#[cfg(any(target_os = "fuchsia",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
all(not(any(target_env = "uclibc",
target_env = "newlib")),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))))]
CLOCK_REALTIME_ALARM,
#[cfg(any(target_os = "fuchsia",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
all(not(any(target_env = "uclibc",
target_env = "newlib")),
any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))))]
CLOCK_REALTIME_COARSE,
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly"))]
Expand All @@ -87,22 +103,32 @@ libc_enum! {
target_os = "dragonfly"))]
CLOCK_SECOND,
#[cfg(any(target_os = "fuchsia",
target_os = "emscripten",
all(target_os = "linux", target_env = "musl")))]
all(not(any(target_env = "uclibc", target_env = "newlib")),
any(target_os = "emscripten",
all(target_os = "linux", target_env = "musl")))))]
CLOCK_SGI_CYCLE,
#[cfg(any(target_os = "fuchsia",
target_os = "emscripten",
all(target_os = "linux", target_env = "musl")))]
all(not(any(target_env = "uclibc", target_env = "newlib")),
any(target_os = "emscripten",
all(target_os = "linux", target_env = "musl")))))]
CLOCK_TAI,
#[cfg(any(target_os = "fuchsia",
#[cfg(any(
target_env = "uclibc",
target_os = "fuchsia",
target_os = "ios",
target_os = "macos",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_env = "uclibc"))]
all(
not(target_env = "newlib"),
any(
target_os = "linux",
target_os = "android",
target_os = "emscripten",
),
),
)
)]
CLOCK_THREAD_CPUTIME_ID,
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly"))]
Expand Down Expand Up @@ -139,8 +165,13 @@ pub fn clock_gettime(clk_id: ClockId) -> Result<TimeSpec> {
any(
target_os = "macos",
target_os = "ios",
target_os = "redox",
target_os = "hermit",
all(
not(any(target_env = "uclibc", target_env = "newlibc")),
any(
target_os = "redox",
target_os = "hermit",
),
),
)
)
)]
Expand Down

0 comments on commit 396b189

Please sign in to comment.