Skip to content

Commit 795d7c4

Browse files
committed
time.rs: fix branching error conditional compilation
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
1 parent d1d2cae commit 795d7c4

File tree

1 file changed

+71
-40
lines changed

1 file changed

+71
-40
lines changed

src/time.rs

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,51 @@ use libc;
55

66
libc_enum! {
77
#[cfg_attr(any(
8+
target_env = "uclibc",
9+
all(target_env = "newlib", target_arch = "arm"),
810
target_os = "fuchsia",
911
target_os = "redox",
10-
target_env = "uclibc",
1112
target_os = "freebsd",
1213
target_os = "netbsd",
1314
target_os = "openbsd",
1415
target_os = "haiku",
15-
target_os = "linux",
16-
target_os = "android",
17-
target_os = "emscripten",
18-
target_os = "solaris",
19-
target_os = "illumos",
20-
all(target_env = "newlib", target_arch = "arm"),
16+
all(not(target_env = "newlib"),
17+
any(target_os = "linux",
18+
target_os = "android",
19+
target_os = "emscripten",
20+
target_os = "solaris",
21+
target_os = "illumos")),
2122
), repr(i32))]
2223
#[cfg_attr(any(target_os = "macos", target_os = "ios"), repr(u32))]
2324
#[cfg_attr(any(
24-
target_os = "hermit",
2525
all(target_env = "newlib", target_arch = "aarch64"),
26+
all(not(any(target_env = "newlib", target_env = "uclibc")), target_os = "hermit"),
2627
target_os = "dragonfly",
2728
), repr(u64))]
2829
pub enum ClockId {
2930
#[cfg(any(target_os = "fuchsia",
30-
target_os = "linux",
31-
target_os = "android",
32-
target_os = "emscripten"))]
31+
all(not(any(target_env = "uclibc",
32+
target_env = "newlib")),
33+
any(target_os = "linux",
34+
target_os = "android",
35+
target_os = "emscripten"),
36+
)
37+
))]
3338
CLOCK_BOOTTIME,
3439
#[cfg(any(target_os = "fuchsia",
35-
target_os = "linux",
36-
target_os = "android",
37-
target_os = "emscripten"))]
40+
all(not(any(target_env = "uclibc",
41+
target_env = "newlib")),
42+
any(target_os = "linux",
43+
target_os = "android",
44+
target_os = "emscripten"))))]
3845
CLOCK_BOOTTIME_ALARM,
3946
CLOCK_MONOTONIC,
4047
#[cfg(any(target_os = "fuchsia",
41-
target_os = "linux",
42-
target_os = "android",
43-
target_os = "emscripten"))]
48+
all(not(any(target_env = "uclibc",
49+
target_env = "newlib")),
50+
any(target_os = "linux",
51+
target_os = "android",
52+
target_os = "emscripten"))))]
4453
CLOCK_MONOTONIC_COARSE,
4554
#[cfg(any(target_os = "freebsd",
4655
target_os = "dragonfly"))]
@@ -49,33 +58,40 @@ libc_enum! {
4958
target_os = "dragonfly"))]
5059
CLOCK_MONOTONIC_PRECISE,
5160
#[cfg(any(target_os = "fuchsia",
52-
target_os = "linux",
53-
target_os = "android",
54-
target_os = "emscripten"))]
61+
all(not(any(target_env = "uclibc",
62+
target_env = "newlib")),
63+
any(target_os = "linux",
64+
target_os = "android",
65+
target_os = "emscripten"))))]
5566
CLOCK_MONOTONIC_RAW,
5667
#[cfg(any(target_os = "fuchsia",
5768
target_env = "uclibc",
5869
target_os = "macos",
5970
target_os = "ios",
6071
target_os = "freebsd",
6172
target_os = "dragonfly",
62-
target_os = "linux",
63-
target_os = "android",
64-
target_os = "emscripten"))]
73+
all(not(target_env = "newlib"),
74+
any(target_os = "linux",
75+
target_os = "android",
76+
target_os = "emscripten"))))]
6577
CLOCK_PROCESS_CPUTIME_ID,
6678
#[cfg(any(target_os = "freebsd",
6779
target_os = "dragonfly"))]
6880
CLOCK_PROF,
6981
CLOCK_REALTIME,
7082
#[cfg(any(target_os = "fuchsia",
71-
target_os = "linux",
72-
target_os = "android",
73-
target_os = "emscripten"))]
83+
all(not(any(target_env = "uclibc",
84+
target_env = "newlib")),
85+
any(target_os = "linux",
86+
target_os = "android",
87+
target_os = "emscripten"))))]
7488
CLOCK_REALTIME_ALARM,
7589
#[cfg(any(target_os = "fuchsia",
76-
target_os = "linux",
77-
target_os = "android",
78-
target_os = "emscripten"))]
90+
all(not(any(target_env = "uclibc",
91+
target_env = "newlib")),
92+
any(target_os = "linux",
93+
target_os = "android",
94+
target_os = "emscripten"))))]
7995
CLOCK_REALTIME_COARSE,
8096
#[cfg(any(target_os = "freebsd",
8197
target_os = "dragonfly"))]
@@ -87,22 +103,32 @@ libc_enum! {
87103
target_os = "dragonfly"))]
88104
CLOCK_SECOND,
89105
#[cfg(any(target_os = "fuchsia",
90-
target_os = "emscripten",
91-
all(target_os = "linux", target_env = "musl")))]
106+
all(not(any(target_env = "uclibc", target_env = "newlib")),
107+
any(target_os = "emscripten",
108+
all(target_os = "linux", target_env = "musl")))))]
92109
CLOCK_SGI_CYCLE,
93110
#[cfg(any(target_os = "fuchsia",
94-
target_os = "emscripten",
95-
all(target_os = "linux", target_env = "musl")))]
111+
all(not(any(target_env = "uclibc", target_env = "newlib")),
112+
any(target_os = "emscripten",
113+
all(target_os = "linux", target_env = "musl")))))]
96114
CLOCK_TAI,
97-
#[cfg(any(target_os = "fuchsia",
115+
#[cfg(any(
116+
target_env = "uclibc",
117+
target_os = "fuchsia",
98118
target_os = "ios",
99119
target_os = "macos",
100120
target_os = "freebsd",
101121
target_os = "dragonfly",
102-
target_os = "linux",
103-
target_os = "android",
104-
target_os = "emscripten",
105-
target_env = "uclibc"))]
122+
all(
123+
not(target_env = "newlib"),
124+
any(
125+
target_os = "linux",
126+
target_os = "android",
127+
target_os = "emscripten",
128+
),
129+
),
130+
)
131+
)]
106132
CLOCK_THREAD_CPUTIME_ID,
107133
#[cfg(any(target_os = "freebsd",
108134
target_os = "dragonfly"))]
@@ -139,8 +165,13 @@ pub fn clock_gettime(clk_id: ClockId) -> Result<TimeSpec> {
139165
any(
140166
target_os = "macos",
141167
target_os = "ios",
142-
target_os = "redox",
143-
target_os = "hermit",
168+
all(
169+
not(any(target_env = "uclibc", target_env = "newlibc")),
170+
any(
171+
target_os = "redox",
172+
target_os = "hermit",
173+
),
174+
),
144175
)
145176
)
146177
)]

0 commit comments

Comments
 (0)