Skip to content

Commit 4e7a641

Browse files
snoggetgross35
authored andcommitted
gnu: build settings for _TIME_BITS=64
(backport <rust-lang#4433>) (cherry picked from commit 5f1eb6c)
1 parent c56fd04 commit 4e7a641

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",
@@ -103,23 +105,35 @@ fn main() {
103105
set_cfg("linux_time_bits64");
104106
}
105107
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
106-
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
107-
Ok(val) if val == "64" => {
108-
if target_env == "gnu"
109-
&& target_os == "linux"
110-
&& target_ptr_width == "32"
111-
&& target_arch != "riscv32"
112-
&& target_arch != "x86_64"
113-
{
108+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS");
109+
if target_env == "gnu"
110+
&& target_os == "linux"
111+
&& target_ptr_width == "32"
112+
&& target_arch != "riscv32"
113+
&& target_arch != "x86_64"
114+
{
115+
match env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") {
116+
Ok(val) if val == "64" => {
114117
set_cfg("gnu_file_offset_bits64");
118+
set_cfg("linux_time_bits64");
119+
set_cfg("gnu_time_bits64");
120+
}
121+
Ok(val) if val != "32" => {
122+
panic!("RUST_LIBC_UNSTABLE_GNU_TIME_BITS may only be set to '32' or '64'")
123+
}
124+
_ => {
125+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
126+
Ok(val) if val == "64" => {
127+
set_cfg("gnu_file_offset_bits64");
128+
}
129+
Ok(val) if val != "32" => {
130+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
131+
}
132+
_ => {}
133+
}
115134
}
116135
}
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-
_ => {}
121136
}
122-
123137
// On CI: deny all warnings
124138
if libc_ci {
125139
set_cfg("libc_deny_warnings");

libc-test/build.rs

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

36913691
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3692-
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3693-
Ok(val) if val == "64" => {
3694-
if target.contains("gnu")
3695-
&& target.contains("linux")
3696-
&& !target.ends_with("x32")
3697-
&& !target.contains("riscv32")
3698-
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3699-
{
3692+
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
3693+
if target.contains("gnu")
3694+
&& target.contains("linux")
3695+
&& !target.ends_with("x32")
3696+
&& !target.contains("riscv32")
3697+
&& pointer_width == "32"
3698+
{
3699+
match env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") {
3700+
Ok(val) if val == "64" => {
37003701
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3702+
cfg.define("_TIME_BITS", Some("64"));
37013703
cfg.cfg("gnu_file_offset_bits64", None);
3704+
cfg.cfg("linux_time_bits64", None);
3705+
cfg.cfg("gnu_time_bits64", None);
3706+
}
3707+
Ok(val) if val != "32" => {
3708+
panic!("RUST_LIBC_UNSTABLE_GNU_TIME_BITS may only be set to '32' or '64'")
3709+
}
3710+
_ => {
3711+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3712+
Ok(val) if val == "64" => {
3713+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3714+
cfg.cfg("gnu_file_offset_bits64", None);
3715+
}
3716+
Ok(val) if val != "32" => {
3717+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3718+
}
3719+
_ => {}
3720+
}
37023721
}
37033722
}
3704-
Ok(val) if val != "32" => {
3705-
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3706-
}
3707-
_ => {}
37083723
}
37093724
}
37103725

0 commit comments

Comments
 (0)