Skip to content

Commit 5bde4db

Browse files
committed
musl: add musl_time64 feature
This feature is enabled with independently from musl_v1_2_3 to support time64. Defining this feature makes this roughly equivalent to upstream commit bminor/musl@f12bd8e.
1 parent 0f1d040 commit 5bde4db

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

build.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const ALLOWED_CFGS: &[&str] = &[
2828
// Corresponds to `__USE_TIME_BITS64` in UAPI
2929
"linux_time_bits64",
3030
"musl_v1_2_3",
31+
// Corresponds to `_REDIR_TIME64` in musl
32+
"musl32_time64",
3133
"vxworks_lt_25_09",
3234
];
3335

@@ -49,6 +51,9 @@ const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
4951
),
5052
];
5153

54+
/// Musl architectures that set `#define _REDIR_TIME64 1`.
55+
const MUSL_REDIR_TIME64_ARCHES: &[&str] = &["arm", "mips", "powerpc", "x86"];
56+
5257
fn main() {
5358
// Avoid unnecessary re-building.
5459
println!("cargo:rerun-if-changed=build.rs");
@@ -99,12 +104,29 @@ fn main() {
99104
_ => (),
100105
}
101106

102-
let musl_v1_2_3 = env_flag("RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
107+
let mut musl_v1_2_3 = env_flag("RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
103108
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
104-
// loongarch64 and ohos have already updated
105-
if musl_v1_2_3 || target_arch == "loongarch64" || target_env == "ohos" {
106-
// FIXME(musl): enable time64 api as well
109+
110+
// OpenHarmony uses a fork of the musl libc
111+
let musl = target_env == "musl" || target_env == "ohos";
112+
113+
// loongarch64 and ohos only exist with recent musl
114+
if target_arch == "loongarch64" || target_env == "ohos" {
115+
musl_v1_2_3 = true;
116+
}
117+
118+
if musl && musl_v1_2_3 {
107119
set_cfg("musl_v1_2_3");
120+
if MUSL_REDIR_TIME64_ARCHES.contains(&target_arch.as_str()) {
121+
set_cfg("musl32_time64");
122+
set_cfg("linux_time_bits64");
123+
}
124+
}
125+
126+
let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
127+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");
128+
if linux_time_bits64 {
129+
set_cfg("linux_time_bits64");
108130
}
109131
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
110132
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS");

libc-test/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3679,6 +3679,7 @@ fn test_linux(target: &str) {
36793679
let i686 = target.contains("i686");
36803680
let ppc = target.contains("powerpc");
36813681
let ppc64 = target.contains("powerpc64");
3682+
let ppc32 = ppc && !ppc64;
36823683
let s390x = target.contains("s390x");
36833684
let sparc64 = target.contains("sparc64");
36843685
let x32 = target.contains("x32");
@@ -3691,6 +3692,8 @@ fn test_linux(target: &str) {
36913692
let wasm32 = target.contains("wasm32");
36923693
let uclibc = target.contains("uclibc");
36933694
let mips = target.contains("mips");
3695+
let mips64 = target.contains("mips64");
3696+
let mips32 = mips && !mips64;
36943697

36953698
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
36963699
if musl_v1_2_3 {
@@ -3699,8 +3702,12 @@ fn test_linux(target: &str) {
36993702
let old_musl = musl && !musl_v1_2_3;
37003703

37013704
let mut cfg = ctest_cfg();
3702-
if musl_v1_2_3 {
3705+
if (musl_v1_2_3 || loongarch64) && musl {
37033706
cfg.cfg("musl_v1_2_3", None);
3707+
if arm || ppc32 || x86_32 || mips32 {
3708+
cfg.cfg("musl32_time64", None);
3709+
cfg.cfg("linux_time_bits64", None);
3710+
}
37043711
}
37053712
cfg.define("_GNU_SOURCE", None)
37063713
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are

0 commit comments

Comments
 (0)