Skip to content

Commit 47960b4

Browse files
xbjfktgross35
authored andcommitted
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 9ca4ae9 commit 47960b4

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
@@ -3690,6 +3690,7 @@ fn test_linux(target: &str) {
36903690
let i686 = target.contains("i686");
36913691
let ppc = target.contains("powerpc");
36923692
let ppc64 = target.contains("powerpc64");
3693+
let ppc32 = ppc && !ppc64;
36933694
let s390x = target.contains("s390x");
36943695
let sparc64 = target.contains("sparc64");
36953696
let x32 = target.contains("x32");
@@ -3702,6 +3703,8 @@ fn test_linux(target: &str) {
37023703
let wasm32 = target.contains("wasm32");
37033704
let uclibc = target.contains("uclibc");
37043705
let mips = target.contains("mips");
3706+
let mips64 = target.contains("mips64");
3707+
let mips32 = mips && !mips64;
37053708

37063709
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
37073710
if musl_v1_2_3 {
@@ -3710,8 +3713,12 @@ fn test_linux(target: &str) {
37103713
let old_musl = musl && !musl_v1_2_3;
37113714

37123715
let mut cfg = ctest_cfg();
3713-
if musl_v1_2_3 {
3716+
if (musl_v1_2_3 || loongarch64) && musl {
37143717
cfg.cfg("musl_v1_2_3", None);
3718+
if arm || ppc32 || x86_32 || mips32 {
3719+
cfg.cfg("musl32_time64", None);
3720+
cfg.cfg("linux_time_bits64", None);
3721+
}
37153722
}
37163723
cfg.define("_GNU_SOURCE", None)
37173724
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are

0 commit comments

Comments
 (0)