Skip to content

Commit 1a1d9b7

Browse files
committed
gnu: build settings for _TIME_BITS=64
1 parent ebb82a1 commit 1a1d9b7

File tree

2 files changed

+54
-25
lines changed

2 files changed

+54
-25
lines changed

build.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const ALLOWED_CFGS: &[&str] = &[
1515
"freebsd15",
1616
// Corresponds to `_FILE_OFFSET_BITS=64` in glibc
1717
"gnu_file_offset_bits64",
18+
// Corresponds to `_TIME_BITS=64` in glibc
19+
"gnu_time_bits64",
1820
// FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn`
1921
"libc_const_extern_fn",
2022
"libc_deny_warnings",
@@ -91,23 +93,35 @@ fn main() {
9193
set_cfg("linux_time_bits64");
9294
}
9395
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
94-
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
95-
Ok(val) if val == "64" => {
96-
if target_env == "gnu"
97-
&& target_os == "linux"
98-
&& target_ptr_width == "32"
99-
&& target_arch != "riscv32"
100-
&& target_arch != "x86_64"
101-
{
96+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS");
97+
if target_env == "gnu"
98+
&& target_os == "linux"
99+
&& target_ptr_width == "32"
100+
&& target_arch != "riscv32"
101+
&& target_arch != "x86_64"
102+
{
103+
match env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") {
104+
Ok(val) if val == "64" => {
102105
set_cfg("gnu_file_offset_bits64");
106+
set_cfg("linux_time_bits64");
107+
set_cfg("gnu_time_bits64");
108+
}
109+
Ok(val) if val != "32" => {
110+
panic!("RUST_LIBC_UNSTABLE_GNU_TIME_BITS may only be set to '32' or '64'")
111+
}
112+
_ => {
113+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
114+
Ok(val) if val == "64" => {
115+
set_cfg("gnu_file_offset_bits64");
116+
}
117+
Ok(val) if val != "32" => {
118+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
119+
}
120+
_ => {}
121+
}
103122
}
104123
}
105-
Ok(val) if val != "32" => {
106-
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
107-
}
108-
_ => {}
109124
}
110-
111125
// On CI: deny all warnings
112126
if libc_ci {
113127
set_cfg("libc_deny_warnings");

libc-test/build.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,22 +3604,37 @@ fn test_vxworks(target: &str) {
36043604
}
36053605

36063606
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3607-
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3608-
Ok(val) if val == "64" => {
3609-
if target.contains("gnu")
3610-
&& target.contains("linux")
3611-
&& !target.ends_with("x32")
3612-
&& !target.contains("riscv32")
3613-
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3614-
{
3607+
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
3608+
if target.contains("gnu")
3609+
&& target.contains("linux")
3610+
&& !target.ends_with("x32")
3611+
&& !target.contains("riscv32")
3612+
&& pointer_width == "32"
3613+
{
3614+
match env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") {
3615+
Ok(val) if val == "64" => {
36153616
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3617+
cfg.define("_TIME_BITS", Some("64"));
36163618
cfg.cfg("gnu_file_offset_bits64", None);
3619+
cfg.cfg("linux_time_bits64", None);
3620+
cfg.cfg("gnu_time_bits64", None);
3621+
}
3622+
Ok(val) if val != "32" => {
3623+
panic!("RUST_LIBC_UNSTABLE_GNU_TIME_BITS may only be set to '32' or '64'")
3624+
}
3625+
_ => {
3626+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3627+
Ok(val) if val == "64" => {
3628+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3629+
cfg.cfg("gnu_file_offset_bits64", None);
3630+
}
3631+
Ok(val) if val != "32" => {
3632+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3633+
}
3634+
_ => {}
3635+
}
36173636
}
36183637
}
3619-
Ok(val) if val != "32" => {
3620-
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3621-
}
3622-
_ => {}
36233638
}
36243639
}
36253640

0 commit comments

Comments
 (0)