Skip to content

Commit 4c60787

Browse files
committed
musl: add musl_time64 feature
This feature is enabled with independently from musl_v1_2_3 to support time64. This also sets a musl_not_time64 feature to make `cfg` statements easier to read. Defining linux_time_bits64 makes this roughly equivalent to upstream commit bminor/musl@f12bd8e.
1 parent b8e90fc commit 4c60787

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

build.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const ALLOWED_CFGS: &[&str] = &[
2424
// Corresponds to `__USE_TIME_BITS64` in UAPI
2525
"linux_time_bits64",
2626
"musl_v1_2_3",
27+
"musl_time64",
28+
"musl_not_time64",
2729
];
2830

2931
// Extra values to allow for check-cfg.
@@ -44,6 +46,8 @@ const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
4446
),
4547
];
4648

49+
const MUSL_TIME64_ARCHS: &[&str] = &["arm", "mips", "powerpc", "x86"];
50+
4751
fn main() {
4852
// Avoid unnecessary re-building.
4953
println!("cargo:rerun-if-changed=build.rs");
@@ -90,10 +94,20 @@ fn main() {
9094

9195
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
9296
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
97+
let musl_time64 = env::var("RUST_LIBC_UNSTABLE_MUSL_TIME64").is_ok();
98+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_TIME64");
9399
// loongarch64 and ohos have already updated
94-
if musl_v1_2_3 || target_os == "loongarch64" || target_env == "ohos" {
95-
// FIXME(musl): enable time64 api as well
100+
if ((musl_v1_2_3 || target_os == "loongarch64") && target_env == "musl") || target_env == "ohos"
101+
{
96102
set_cfg("musl_v1_2_3");
103+
if musl_time64 && MUSL_TIME64_ARCHS.contains(&target_arch.as_str()) {
104+
set_cfg("musl_time64");
105+
set_cfg("linux_time_bits64");
106+
} else {
107+
set_cfg("musl_not_time64");
108+
}
109+
} else if target_env == "musl" || target_env == "ohos" {
110+
set_cfg("musl_not_time64");
97111
}
98112
let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
99113
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");

libc-test/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3683,14 +3683,22 @@ fn test_linux(target: &str) {
36833683
let loongarch64 = target.contains("loongarch64");
36843684
let wasm32 = target.contains("wasm32");
36853685
let uclibc = target.contains("uclibc");
3686+
let mips64 = target.contains("mips64");
3687+
let mips32 = target.contains("mips") && !mips64;
36863688

36873689
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
3690+
let musl_time64 = env::var("RUST_LIBC_UNSTABLE_MUSL_TIME64").is_ok();
36883691
let old_musl = musl && !musl_v1_2_3;
36893692

36903693
let mut cfg = ctest_cfg();
3691-
if musl_v1_2_3 {
3694+
if (musl_v1_2_3 || loongarch64) && musl {
36923695
cfg.cfg("musl_v1_2_3", None);
3696+
if musl_time64 && (arm || ppc || x86_32 || mips32) {
3697+
cfg.cfg("musl_time64", None);
3698+
cfg.cfg("linux_time_bits64", None);
3699+
}
36933700
}
3701+
36943702
cfg.define("_GNU_SOURCE", None);
36953703
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are
36963704
// deprecated since glibc >= 2.29. This allows Rust binaries to link against

0 commit comments

Comments
 (0)