Skip to content

Commit 3a906cc

Browse files
committed
gnu: build settings for _TIME_BITS=64
1 parent c1d2b8e commit 3a906cc

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",
@@ -99,23 +101,35 @@ fn main() {
99101
set_cfg("linux_time_bits64");
100102
}
101103
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
102-
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
103-
Ok(val) if val == "64" => {
104-
if target_env == "gnu"
105-
&& target_os == "linux"
106-
&& target_ptr_width == "32"
107-
&& target_arch != "riscv32"
108-
&& target_arch != "x86_64"
109-
{
104+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS");
105+
if target_env == "gnu"
106+
&& target_os == "linux"
107+
&& target_ptr_width == "32"
108+
&& target_arch != "riscv32"
109+
&& target_arch != "x86_64"
110+
{
111+
match env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") {
112+
Ok(val) if val == "64" => {
110113
set_cfg("gnu_file_offset_bits64");
114+
set_cfg("linux_time_bits64");
115+
set_cfg("gnu_time_bits64");
116+
}
117+
Ok(val) if val != "32" => {
118+
panic!("RUST_LIBC_UNSTABLE_GNU_TIME_BITS may only be set to '32' or '64'")
119+
}
120+
_ => {
121+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
122+
Ok(val) if val == "64" => {
123+
set_cfg("gnu_file_offset_bits64");
124+
}
125+
Ok(val) if val != "32" => {
126+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
127+
}
128+
_ => {}
129+
}
111130
}
112131
}
113-
Ok(val) if val != "32" => {
114-
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
115-
}
116-
_ => {}
117132
}
118-
119133
// On CI: deny all warnings
120134
if libc_ci {
121135
set_cfg("libc_deny_warnings");

libc-test/build.rs

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

36173617
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3618-
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3619-
Ok(val) if val == "64" => {
3620-
if target.contains("gnu")
3621-
&& target.contains("linux")
3622-
&& !target.ends_with("x32")
3623-
&& !target.contains("riscv32")
3624-
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3625-
{
3618+
let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
3619+
if target.contains("gnu")
3620+
&& target.contains("linux")
3621+
&& !target.ends_with("x32")
3622+
&& !target.contains("riscv32")
3623+
&& pointer_width == "32"
3624+
{
3625+
match env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") {
3626+
Ok(val) if val == "64" => {
36263627
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3628+
cfg.define("_TIME_BITS", Some("64"));
36273629
cfg.cfg("gnu_file_offset_bits64", None);
3630+
cfg.cfg("linux_time_bits64", None);
3631+
cfg.cfg("gnu_time_bits64", None);
3632+
}
3633+
Ok(val) if val != "32" => {
3634+
panic!("RUST_LIBC_UNSTABLE_GNU_TIME_BITS may only be set to '32' or '64'")
3635+
}
3636+
_ => {
3637+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3638+
Ok(val) if val == "64" => {
3639+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3640+
cfg.cfg("gnu_file_offset_bits64", None);
3641+
}
3642+
Ok(val) if val != "32" => {
3643+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3644+
}
3645+
_ => {}
3646+
}
36283647
}
36293648
}
3630-
Ok(val) if val != "32" => {
3631-
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3632-
}
3633-
_ => {}
36343649
}
36353650
}
36363651

0 commit comments

Comments
 (0)