Skip to content

Commit

Permalink
Replace unmaintained humantime crate with jiff (#15290)
Browse files Browse the repository at this point in the history
<!--
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.
  • Loading branch information
epage authored Mar 10, 2025
2 parents 340d123 + 514057f commit 35cf085
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
38 changes: 28 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ hex = "0.4.3"
hmac = "0.12.1"
home = "0.5.11"
http-auth = { version = "0.1.10", default-features = false }
humantime = "2.1.0"
ignore = "0.4.23"
im-rc = "15.1.0"
indexmap = "2.7.1"
itertools = "0.14.0"
jiff = { version = "0.2.3", default-features = false, features = [ "std" ] }
jobserver = "0.1.32"
lazycell = "1.3.0"
libc = "0.2.169"
Expand Down Expand Up @@ -176,11 +176,11 @@ hex.workspace = true
hmac.workspace = true
home.workspace = true
http-auth.workspace = true
humantime.workspace = true
ignore.workspace = true
im-rc.workspace = true
indexmap.workspace = true
itertools.workspace = true
jiff.workspace = true
jobserver.workspace = true
lazycell.workspace = true
libgit2-sys.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn setup_logger() -> Option<ChromeFlushGuard> {
.with(fmt_layer)
.with(profile_layer);
registry.init();
tracing::trace!(start = humantime::format_rfc3339(std::time::SystemTime::now()).to_string());
tracing::trace!(start = jiff::Timestamp::now().to_string());
profile_guard
}

Expand Down
7 changes: 2 additions & 5 deletions src/cargo/core/compiler/fingerprint/dirty_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,9 @@ impl fmt::Display for FileTimeDiff {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s_diff = self.new_time.seconds() - self.old_time.seconds();
if s_diff >= 1 {
fmt::Display::fmt(
&humantime::Duration::from(std::time::Duration::from_secs(s_diff as u64)),
f,
)
write!(f, "{:#}", jiff::SignedDuration::from_secs(s_diff))
} else {
// format nanoseconds as it is, humantime would display ms, us and ns
// format nanoseconds as it is, jiff would display ms, us and ns
let ns_diff = self.new_time.nanoseconds() - self.old_time.nanoseconds();
write!(f, "{ns_diff}ns")
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cargo_util::paths;
use std::collections::HashMap;
use std::io::{BufWriter, Write};
use std::thread::available_parallelism;
use std::time::{Duration, Instant, SystemTime};
use std::time::{Duration, Instant};

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

0 comments on commit 35cf085

Please sign in to comment.