From a9620eca030230a3def9025e26fde2aeee6cac40 Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Fri, 14 Aug 2026 08:35:51 +0200 Subject: [PATCH 1/4] crate: expose `cfg` for general time64 Add `cfg` enabling `time64` functionality across all supported targets. This ensures users have a simple entry point to the crate functionality gated behind one of `linux_time_bits64`, `uclibc_time64` and `gnu_time_bits64`. The new `cfg` goes by the name `libc_unstable_time64`. --- build.rs | 9 ++++++--- libc-test/build/main.rs | 15 ++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index faa5a33fb293..5a53cc4f46a8 100644 --- a/build.rs +++ b/build.rs @@ -251,9 +251,12 @@ fn main() { || target_env == "ohos" || target_abi == "pauthtest"; + // Single entry-point to enable `time64` on supported platforms. + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + // OpenHarmony uses a fork of the musl libc let musl = target_env == "musl" || target_env == "ohos"; - let musl_v1_2 = musl && (musl_v1_2_env || only_v1_2_on_musl); + let musl_v1_2 = musl && (musl_v1_2_env || only_v1_2_on_musl || time64); if musl_v1_2 { cfgs.push(Cfg::MuslV1_2); @@ -301,7 +304,7 @@ fn main() { || target_arch == "x86_64" || !matches!(target_os.as_str(), "linux" | "windows" | "hurd"); let gnu = target_env == "gnu"; - let gnu32_time64 = gnu && target_ptr_width == "32" && gnu32_timebits == "64"; + let gnu32_time64 = gnu && target_ptr_width == "32" && (gnu32_timebits == "64" || time64); if gnu32_time64 && !gnu32_already_time64 { // These configs all set up nonstandard options. They are not needed on platforms like @@ -315,7 +318,7 @@ fn main() { 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; + let uclibc32_time64 = uclibc && target_ptr_width == "32" && (uclibc_time64_env || time64); if uclibc32_time64 { if target_os == "linux" { diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index 1d4dca435c87..6b66a62ea439 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -746,7 +746,8 @@ fn test_windows(t: &Target) { } cfg.define("_WIN32_WINNT", Some("0x8000")); - let win_gnu_x86_time64 = match env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS") { + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + let mut win_gnu_x86_time64 = match env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS") { Ok(v) if v == "64" => true, Ok(v) if v == "32" => false, Ok(_) => { @@ -754,6 +755,7 @@ fn test_windows(t: &Target) { } Err(_) => false, }; + win_gnu_x86_time64 |= time64; // Needed for the Windows `time_t` test. println!("cargo::rustc-check-cfg=cfg(gnu_time_bits64)"); @@ -3877,6 +3879,7 @@ fn config_gnu_bits(t: &Target, cfg: &mut ctest::TestGenerator) { if t.gnu() && t.linux() && !t.x32() && !t.riscv32() && t.pointer_width == P32 { let defaultbits = "32"; let mut tb_env = env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"); + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); // FIXME: remove these fallbacks in a few releases if let Ok(old_tb_env) = env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") { @@ -3905,7 +3908,7 @@ fn config_gnu_bits(t: &Target, cfg: &mut ctest::TestGenerator) { } }; - if timebits == "64" { + if timebits == "64" || time64 { cfg.define("_TIME_BITS", Some("64")); cfg.define("_FILE_OFFSET_BITS", Some("64")); cfg.cfg("linux_time_bits64", None); @@ -3970,13 +3973,15 @@ fn test_linux(t: &Target) { None => panic!("failed to detect kernel version for Linux target {t:?}",), }; + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + let mut musl_v1_2 = env_flag("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2"); if musl_v1_2 { assert!(musl); } // Some platforms only exist with recent musl. Keep in sync with libc's build.rs. - if musl && (loongarch64 || hexagon || pauthtest/* || ohos */) { + if musl && (loongarch64 || hexagon || pauthtest/* || ohos */ || time64) { musl_v1_2 = true; } @@ -3984,7 +3989,7 @@ fn test_linux(t: &Target) { let mut cfg = ctest_cfg(); - if musl_v1_2 { + if musl && musl_v1_2 { cfg.cfg("musl_v1_2", None); if p32 { cfg.cfg("musl32_time64", None); @@ -3996,7 +4001,7 @@ fn test_linux(t: &Target) { } let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); - let uclibc32_time64 = uclibc && p32 && uclibc_time64_env; + let uclibc32_time64 = uclibc && p32 && (uclibc_time64_env || time64); if uclibc32_time64 { cfg.cfg("linux_time_bits64", None); From 5e2ab2c3d3a8d04dfa9404288c19e2c4c59326bb Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Sat, 29 Aug 2026 09:18:08 +0200 Subject: [PATCH 2/4] ci: make prevalent use of time64 `cfg` Switch as many uses of other target-specific `cfg`s with the `time64` `cfg` introduced in the prior patch. --- ci/run-docker.sh | 2 +- ci/run.sh | 2 +- ci/verify-build.py | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ci/run-docker.sh b/ci/run-docker.sh index 494f3c118501..fa97a17a0dc9 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -51,7 +51,7 @@ run() { if [ -n "${TEST_UCLIBC_TIME64:-}" ]; then build_args+=("--build-arg=TEST_UCLIBC_TIME64=1") - RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_uclibc_time64" + RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_time64" fi if [[ "$run_target" = *-linux-uclibc* ]]; then if [ "${UCLIBC_TOOLCHAIN_URL:-}" ]; then diff --git a/ci/run.sh b/ci/run.sh index b254ea8b169b..dfcc9bd5262e 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -60,5 +60,5 @@ $cmd --features extra_traits -- $test_flags if [ "$env" = "gnu" ] && [ "$bits" = "32" ]; then # shellcheck disable=SC2086 - RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_gnu_time_bits=\"64\"" $cmd -- $test_flags + RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_time64" $cmd -- $test_flags fi diff --git a/ci/verify-build.py b/ci/verify-build.py index 065643d42a37..d49f69ae05b4 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -412,13 +412,14 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult: run(cmd, rustflags=rustflags) run([*cmd, "--features=extra_traits"], rustflags=rustflags) - if "gnu" in target_env and target_bits == "32": - # Equivalent of _TIME_BITS=64 - run(cmd, rustflags=f'{rustflags} --cfg=libc_unstable_gnu_time_bits="64"') - - if "musl" in target_env: - # 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 ( + ("gnu" in target_env and target_bits == "32") + or "musl" in target_env + or "uclibc" in target_env + ): + # Global toggle for `_TIME_BITS=64` on glibc, musl breaking changes and + # uClibc buil-time options concerning 64-bit `time_t`. + run(cmd, rustflags=f"{rustflags} --cfg=libc_unstable_time64") if "uclibc" in target_env: # Equivalent of UCLIBC_USE_TIME64 on 32-bit targets, ignored on 64-bit From 917d0133411cfd60582162133f108f986b1f7b58 Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:49:01 +0200 Subject: [PATCH 3/4] ci: format yaml - Change indentation of two YAML arrays to consistently appear as nested within the key that corresponds with the array. - Change one inconsistent use of single quotes with double quotes for YAML strings. --- .github/workflows/ci.yaml | 46 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 733768e20230..3d129c7d5c64 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -71,7 +71,7 @@ jobs: - toolchain: nightly half: 2 - toolchain: beta - only: '(aarch64|x86_64)' # just a spot check for beta + only: "(aarch64|x86_64)" # just a spot check for beta - toolchain: stable - toolchain: 1.65.0 # msrv runs-on: ubuntu-26.04 @@ -392,34 +392,34 @@ jobs: env: RUSTFLAGS: "" # No need to check warnings on old MSRV, clear `-Dwarnings` steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - run: | - msrv="$( - cargo metadata --format-version 1 | - jq -r --arg CRATE_NAME ctest '.packages | map(select((.name == $CRATE_NAME) and (.id | startswith("path+file")))) | first | .rust_version' - )" - echo "MSRV: $msrv" - echo "MSRV=$msrv" >> "$GITHUB_ENV" - - name: Install Rust - run: rustup update "$MSRV" --no-self-update && rustup default "$MSRV" - - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 - - run: cargo build -p ctest + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - run: | + msrv="$( + cargo metadata --format-version 1 | + jq -r --arg CRATE_NAME ctest '.packages | map(select((.name == $CRATE_NAME) and (.id | startswith("path+file")))) | first | .rust_version' + )" + echo "MSRV: $msrv" + echo "MSRV=$msrv" >> "$GITHUB_ENV" + - name: Install Rust + run: rustup update "$MSRV" --no-self-update && rustup default "$MSRV" + - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + - run: cargo build -p ctest docs: name: Ensure docs build runs-on: ubuntu-26.04 timeout-minutes: 10 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Install Rust - # FIXME(rust-lang/rust#160439): unpin once the issue is fixed - run: rustup update nightly-2026-08-02 --no-self-update && rustup default nightly-2026-08-02 - - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 - - run: cargo doc --workspace --no-deps + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Install Rust + # FIXME(rust-lang/rust#160439): unpin once the issue is fixed + run: rustup update nightly-2026-08-02 --no-self-update && rustup default nightly-2026-08-02 + - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + - run: cargo doc --workspace --no-deps zizmor: name: Zizmor (Static analysis for GitHub Actions) From 050b9e51c91c9b0f9002cc2f4ebb8983c9e8522a Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Thu, 10 Sep 2026 14:10:39 +0200 Subject: [PATCH 4/4] ci: use `TEST_MUSL_V1_2` in powerpc runs Replace use of `RUST_LIBC_UNSTABLE_MUSL_V1_2` with `TEST_MUSL_V1_2` in the PowerPC CI runs. The former is deprecated; The latter is used in CI scripts to set the right unstable `cfg` for functionality gated behind musl's v1.2. --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3d129c7d5c64..501874845fd4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -220,7 +220,7 @@ jobs: - target: powerpc64-unknown-linux-gnu - target: powerpc64-unknown-linux-musl - target: powerpc64-unknown-linux-musl - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2: 1 } + env: { TEST_MUSL_V1_2: 1 } artifact-tag: new-musl - target: powerpc64le-unknown-linux-gnu - target: powerpc64le-unknown-linux-musl