Skip to content

Commit 89688c5

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. (backport <rust-lang#4463>) (cherry picked from commit 47960b4)
1 parent 46758b8 commit 89688c5

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

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
@@ -3836,6 +3836,7 @@ fn test_linux(target: &str) {
38363836
let i686 = target.contains("i686");
38373837
let ppc = target.contains("powerpc");
38383838
let ppc64 = target.contains("powerpc64");
3839+
let ppc32 = ppc && !ppc64;
38393840
let s390x = target.contains("s390x");
38403841
let sparc64 = target.contains("sparc64");
38413842
let x32 = target.contains("x32");
@@ -3848,6 +3849,8 @@ fn test_linux(target: &str) {
38483849
let wasm32 = target.contains("wasm32");
38493850
let uclibc = target.contains("uclibc");
38503851
let mips = target.contains("mips");
3852+
let mips64 = target.contains("mips64");
3853+
let mips32 = mips && !mips64;
38513854

38523855
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
38533856
if musl_v1_2_3 {
@@ -3856,8 +3859,12 @@ fn test_linux(target: &str) {
38563859
let old_musl = musl && !musl_v1_2_3;
38573860

38583861
let mut cfg = ctest_cfg();
3859-
if musl_v1_2_3 {
3862+
if (musl_v1_2_3 || loongarch64) && musl {
38603863
cfg.cfg("musl_v1_2_3", None);
3864+
if arm || ppc32 || x86_32 || mips32 {
3865+
cfg.cfg("musl32_time64", None);
3866+
cfg.cfg("linux_time_bits64", None);
3867+
}
38613868
}
38623869
cfg.define("_GNU_SOURCE", None)
38633870
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are

0 commit comments

Comments
 (0)