Skip to content

Commit 35cf085

Browse files
authored
Replace unmaintained humantime crate with jiff (#15290)
<!-- Thanks for submitting a pull request 🎉! Here are some tips for you: * If this is your first contribution, read "Cargo Contribution Guide" first: https://doc.crates.io/contrib/ * Run `cargo fmt --all` to format your code changes. * Small commits and pull requests are always preferable and easy to review. * If your idea is large and needs feedback from the community, read how: https://doc.crates.io/contrib/process/#working-on-large-features * Cargo takes care of compatibility. Read our design principles: https://doc.crates.io/contrib/design.html * When changing help text of cargo commands, follow the steps to generate docs: https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages * If your PR is not finished, set it as "draft" PR or add "WIP" in its title. * It's ok to use the CI resources to test your PR, but please don't abuse them. ### What does this PR try to resolve? Explain the motivation behind this change. A clear overview along with an in-depth explanation are helpful. You can use `Fixes #<issue number>` to associate this PR to an existing issue. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information Other information you want to mention in this PR, such as prior arts, future extensions, an unresolved problem, or a TODO list. --> The crate [`humantime`](https://crates.io/crates/humantime) appears to be unmaintained. There's open PR in RustSec's advisory-db about this: rustsec/advisory-db#2249 The crates [`clap`](https://crates.io/crates/clap) and [`env_logger`](https://crates.io/crates/env_logger) have already made the switch from `humantime` to [`jiff`](https://crates.io/crates/jiff): * clap-rs/clap#5944 * rust-cli/env_logger#352 The `jiff` crate is already dependency on `cargo` via `gix` (albeit old 0.1 version, but that's probably fixed in [next gix release](GitoxideLabs/gitoxide@3ae99a4)): ``` jiff v0.1.29 └── gix-date v0.9.3 ├── gix v0.70.0 │ └── cargo v0.88.0 (/Users/oherrala/rust/cargo) ``` This PR shouldn't have any functional change to cargo itself.
2 parents 340d123 + 514057f commit 35cf085

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

Cargo.lock

+28-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ hex = "0.4.3"
5555
hmac = "0.12.1"
5656
home = "0.5.11"
5757
http-auth = { version = "0.1.10", default-features = false }
58-
humantime = "2.1.0"
5958
ignore = "0.4.23"
6059
im-rc = "15.1.0"
6160
indexmap = "2.7.1"
6261
itertools = "0.14.0"
62+
jiff = { version = "0.2.3", default-features = false, features = [ "std" ] }
6363
jobserver = "0.1.32"
6464
lazycell = "1.3.0"
6565
libc = "0.2.169"
@@ -176,11 +176,11 @@ hex.workspace = true
176176
hmac.workspace = true
177177
home.workspace = true
178178
http-auth.workspace = true
179-
humantime.workspace = true
180179
ignore.workspace = true
181180
im-rc.workspace = true
182181
indexmap.workspace = true
183182
itertools.workspace = true
183+
jiff.workspace = true
184184
jobserver.workspace = true
185185
lazycell.workspace = true
186186
libgit2-sys.workspace = true

src/bin/cargo/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn setup_logger() -> Option<ChromeFlushGuard> {
7979
.with(fmt_layer)
8080
.with(profile_layer);
8181
registry.init();
82-
tracing::trace!(start = humantime::format_rfc3339(std::time::SystemTime::now()).to_string());
82+
tracing::trace!(start = jiff::Timestamp::now().to_string());
8383
profile_guard
8484
}
8585

src/cargo/core/compiler/fingerprint/dirty_reason.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@ impl fmt::Display for FileTimeDiff {
102102
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103103
let s_diff = self.new_time.seconds() - self.old_time.seconds();
104104
if s_diff >= 1 {
105-
fmt::Display::fmt(
106-
&humantime::Duration::from(std::time::Duration::from_secs(s_diff as u64)),
107-
f,
108-
)
105+
write!(f, "{:#}", jiff::SignedDuration::from_secs(s_diff))
109106
} else {
110-
// format nanoseconds as it is, humantime would display ms, us and ns
107+
// format nanoseconds as it is, jiff would display ms, us and ns
111108
let ns_diff = self.new_time.nanoseconds() - self.old_time.nanoseconds();
112109
write!(f, "{ns_diff}ns")
113110
}

src/cargo/core/compiler/timings.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cargo_util::paths;
1515
use std::collections::HashMap;
1616
use std::io::{BufWriter, Write};
1717
use std::thread::available_parallelism;
18-
use std::time::{Duration, Instant, SystemTime};
18+
use std::time::{Duration, Instant};
1919

2020
/// Tracking information for the entire build.
2121
///
@@ -117,7 +117,7 @@ impl<'gctx> Timings<'gctx> {
117117
(pkg_desc, targets)
118118
})
119119
.collect();
120-
let start_str = humantime::format_rfc3339_seconds(SystemTime::now()).to_string();
120+
let start_str = jiff::Timestamp::now().to_string();
121121
let profile = bcx.build_config.requested_profile.to_string();
122122
let last_cpu_state = if enabled {
123123
match State::current() {

0 commit comments

Comments
 (0)