Skip to content

Commit b01797c

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

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
@@ -3684,22 +3684,37 @@ fn test_vxworks(target: &str) {
36843684
}
36853685

36863686
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3687-
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3688-
Ok(val) if val == "64" => {
3689-
if target.contains("gnu")
3690-
&& target.contains("linux")
3691-
&& !target.ends_with("x32")
3692-
&& !target.contains("riscv32")
3693-
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3694-
{
3687+
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
3688+
if target.contains("gnu")
3689+
&& target.contains("linux")
3690+
&& !target.ends_with("x32")
3691+
&& !target.contains("riscv32")
3692+
&& pointer_width == "32"
3693+
{
3694+
match env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") {
3695+
Ok(val) if val == "64" => {
36953696
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3697+
cfg.define("_TIME_BITS", Some("64"));
36963698
cfg.cfg("gnu_file_offset_bits64", None);
3699+
cfg.cfg("linux_time_bits64", None);
3700+
cfg.cfg("gnu_time_bits64", None);
3701+
}
3702+
Ok(val) if val != "32" => {
3703+
panic!("RUST_LIBC_UNSTABLE_GNU_TIME_BITS may only be set to '32' or '64'")
3704+
}
3705+
_ => {
3706+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3707+
Ok(val) if val == "64" => {
3708+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3709+
cfg.cfg("gnu_file_offset_bits64", None);
3710+
}
3711+
Ok(val) if val != "32" => {
3712+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3713+
}
3714+
_ => {}
3715+
}
36973716
}
36983717
}
3699-
Ok(val) if val != "32" => {
3700-
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3701-
}
3702-
_ => {}
37033718
}
37043719
}
37053720

0 commit comments

Comments
 (0)