Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ enum Cfg {
/// transition to 64-bit `time_t` and thus need `__*_time64` redirects. Implies `musl_v1_2`
/// and 32-bit arch.
MuslRedirTime64,
/// Corresponds to the `UCLIBC_USE_TIME64` config / `__UCLIBC_USE_TIME64__` define. Indicates
/// that `*time64` syscalls should be used. Implies 32-bit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should mention here that it also applies to 64-bit MIPS
with the 32-bits ABI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That platform is definitely a bridge to cross if we ever get to it, but it wouldn't have hurt. Especially considering the x32 platform is poorly supported, and GCC and LLVM may be removing their aarch64 ilp32 support.

Uclibc32Time64,
}

const ALLOWED_CFGS: &[Cfg] = &[
Expand All @@ -76,6 +79,7 @@ const ALLOWED_CFGS: &[Cfg] = &[
Cfg::MuslV1_2,
Cfg::Musl32Time64,
Cfg::MuslRedirTime64,
Cfg::Uclibc32Time64,
];

impl fmt::Display for Cfg {
Expand All @@ -100,6 +104,7 @@ impl fmt::Display for Cfg {
Cfg::MuslV1_2 => "musl_v1_2",
Cfg::Musl32Time64 => "musl32_time64",
Cfg::MuslRedirTime64 => "musl_redir_time64",
Cfg::Uclibc32Time64 => "uclibc32_time64",
})
}
}
Expand Down Expand Up @@ -262,12 +267,6 @@ fn main() {
}
}

let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64");
let uclibc_time64 = target_env == "uclibc" && uclibc_time64_env;
if uclibc_time64 {
cfgs.push(Cfg::LinuxTimeBits64);
}

let mut gnu_tb_env = env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS");

// FIXME: remove these fallbacks in a few releases
Expand Down Expand Up @@ -314,6 +313,17 @@ fn main() {
cfgs.push(Cfg::GnuTimeBits64);
}

let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64");
let uclibc = target_env == "uclibc";
let uclibc32_time64 = uclibc && target_ptr_width == "32" && uclibc_time64_env;

if uclibc32_time64 {
if target_os == "linux" {
cfgs.push(Cfg::LinuxTimeBits64);
}
cfgs.push(Cfg::Uclibc32Time64);
}

// On CI: deny all warnings
if libc_ci {
cfgs.push(Cfg::LibcDenyWarnings);
Expand Down Expand Up @@ -492,6 +502,16 @@ fn validate_cfg(list: &[Cfg], target_env: &str, target_os: &str, target_ptr_widt
"{cfg:?} set on non-musl1.2 platform"
)
}
Cfg::Uclibc32Time64 => {
assert_eq!(target_env, "uclibc", "{cfg:?} set on non-gnu platform");
assert_eq!(target_ptr_width, "32", "{cfg:?} set on non-32-bit platform");
if target_os == "linux" {
assert!(
list.contains(&Cfg::LinuxTimeBits64),
"missing 64-bit time_t Linux config"
)
}
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions ci/verify-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
# Check with breaking changes from musl, including 64-bit time_t on 32-bit
run(cmd, rustflags=f"{rustflags} --cfg=libc_unstable_musl_v1_2")

if "uclibc" in target_env:
# Equivalent of UCLIBC_USE_TIME64 on 32-bit targets, ignored on 64-bit
run(cmd, rustflags=f"{rustflags} --cfg=libc_unstable_uclibc_time64")

# Test again without default features, i.e. without `std`
run([*cmd, "--no-default-features"], rustflags=rustflags)
run([*cmd, "--no-default-features", "--features=extra_traits"], rustflags=rustflags)
Expand Down
8 changes: 6 additions & 2 deletions libc-test/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3995,10 +3995,14 @@ fn test_linux(t: &Target) {
}
}

let uclibc_use_time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64");
if uclibc && uclibc_use_time64 {
let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64");
let uclibc32_time64 = uclibc && p32 && uclibc_time64_env;

if uclibc32_time64 {
cfg.cfg("linux_time_bits64", None);
cfg.cfg("uclibc32_time64", None);
}

cfg.define("_GNU_SOURCE", None)
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are
// deprecated since glibc >= 2.29. This allows Rust binaries to link against
Expand Down
6 changes: 3 additions & 3 deletions src/unix/linux_like/linux/uclibc/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ s! {
pub shm_perm: crate::ipc_perm,
pub shm_segsz: size_t,
pub shm_atime: crate::time_t,
#[cfg(not(linux_time_bits64))]
#[cfg(not(uclibc32_time64))]
__unused1: Padding<c_ulong>,
pub shm_dtime: crate::time_t,
#[cfg(not(linux_time_bits64))]
#[cfg(not(uclibc32_time64))]
__unused2: Padding<c_ulong>,
pub shm_ctime: crate::time_t,
#[cfg(not(linux_time_bits64))]
#[cfg(not(uclibc32_time64))]
__unused3: Padding<c_ulong>,
pub shm_cpid: crate::pid_t,
pub shm_lpid: crate::pid_t,
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/linux/uclibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub type __priority_which_t = c_uint;

cfg_if! {
// Set `--cfg=libc_unstable_uclibc_time64` in RUSTFLAGS if your uClibc has 64-bit `time_t`.
if #[cfg(linux_time_bits64)] {
if #[cfg(uclibc32_time64)] {
pub type time_t = i64;
pub type suseconds_t = i64;
} else {
Expand Down
Loading