Skip to content

Commit 7b9905e

Browse files
committed
windows: expose cfg for 64-bit time_t
Windows has a uniform `time_t`. It's always 64-bits wide. A feature test macro can change that. `libc` has a 32-bit `time_t`. This happens on Windows with GNU. This is wrong. Stable needs to experiment. The `cfg` allows experimenting. It exposes the right `time_t`.
1 parent 69c52f2 commit 7b9905e

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

build.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ALLOWED_CFGS: &[&str] = &[
2424
"freebsd15",
2525
// Corresponds to `_FILE_OFFSET_BITS=64` in glibc
2626
"gnu_file_offset_bits64",
27-
// Corresponds to `_TIME_BITS=64` in glibc
27+
// Corresponds to `_TIME_BITS=64` in glibc. `_USE_32BIT_TIME_T` in Windows.
2828
"gnu_time_bits64",
2929
"libc_deny_warnings",
3030
// Corresponds to `__USE_TIME_BITS64` in UAPI
@@ -143,8 +143,10 @@ fn main() {
143143
set_cfg("linux_time_bits64");
144144
}
145145

146+
// FIXME(1.0): Windows GNU has 64-bit `time_t` by default. In x86 this is
147+
// wrongly bound.
146148
if target_env == "gnu"
147-
&& target_os == "linux"
149+
&& matches!(target_os.as_str(), "linux" | "windows")
148150
&& target_ptr_width == "32"
149151
&& target_arch != "riscv32"
150152
&& target_arch != "x86_64"
@@ -173,7 +175,7 @@ fn main() {
173175
let (timebits, filebits) = match (tb_env.as_deref(), fb_env.as_deref()) {
174176
(Ok(_), Ok(_)) => panic!(
175177
"Do not set both libc_unstable_gnu_time_bits and \
176-
libc_unstable_gnu_file_offset_bits"
178+
libc_unstable_gnu_file_offset_bits"
177179
),
178180
(Err(_), Err(_)) => (defaultbits, defaultbits),
179181
(Ok(tb), Err(_)) if tb == "64" => (tb, tb),

libc-test/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,15 @@ fn test_windows(target: &str) {
784784
}
785785
cfg.define("_WIN32_WINNT", Some("0x8000"));
786786

787+
(gnu && i686).then(|| {
788+
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS")
789+
.map_err(|_| ())
790+
.and_then(|val| val.parse::<usize>().map_err(|_| ()))
791+
.and_then(|v| (v == 64).then_some("gnu_time_bits64").ok_or(()))
792+
.map(|op| _ = cfg.cfg(op, None))
793+
.unwrap_or_default()
794+
});
795+
787796
headers!(
788797
cfg,
789798
"direct.h",

src/windows/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ pub type clock_t = i32;
1919
pub type errno_t = c_int;
2020

2121
cfg_if! {
22-
if #[cfg(all(target_arch = "x86", target_env = "gnu"))] {
22+
if #[cfg(all(
23+
target_arch = "x86",
24+
target_env = "gnu",
25+
not(gnu_time_bits64)
26+
))] {
2327
pub type time_t = i32;
2428
} else {
2529
pub type time_t = i64;

0 commit comments

Comments
 (0)