Skip to content

Commit 3c0daaa

Browse files
committed
feat(index): Add unstable pubtime field
1 parent 0bbd817 commit 3c0daaa

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

crates/cargo-test-support/src/publish.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub(crate) fn create_index_line(
228228
yanked: bool,
229229
links: Option<String>,
230230
rust_version: Option<&str>,
231+
pubtime: Option<&str>,
231232
v: Option<u32>,
232233
) -> String {
233234
// This emulates what crates.io does to retain backwards compatibility.
@@ -251,6 +252,9 @@ pub(crate) fn create_index_line(
251252
if let Some(rust_version) = rust_version {
252253
json["rust_version"] = serde_json::json!(rust_version);
253254
}
255+
if let Some(pubtime) = pubtime {
256+
json["pubtime"] = serde_json::json!(pubtime);
257+
}
254258

255259
json.to_string()
256260
}

crates/cargo-test-support/src/registry.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ pub struct Package {
578578
links: Option<String>,
579579
rust_version: Option<String>,
580580
cargo_features: Vec<String>,
581+
pubtime: Option<String>,
581582
v: Option<u32>,
582583
}
583584

@@ -1243,6 +1244,7 @@ fn save_new_crate(
12431244
new_crate.links,
12441245
new_crate.rust_version.as_deref(),
12451246
None,
1247+
None,
12461248
);
12471249

12481250
write_to_index(registry_path, &new_crate.name, line, false);
@@ -1273,6 +1275,7 @@ impl Package {
12731275
links: None,
12741276
rust_version: None,
12751277
cargo_features: Vec::new(),
1278+
pubtime: None,
12761279
v: None,
12771280
}
12781281
}
@@ -1460,6 +1463,12 @@ impl Package {
14601463
self
14611464
}
14621465

1466+
/// The publish time for the package in ISO8601 with UTC timezone (e.g. 2025-11-12T19:30:12Z)
1467+
pub fn pubtime(&mut self, time: &str) -> &mut Package {
1468+
self.pubtime = Some(time.to_owned());
1469+
self
1470+
}
1471+
14631472
/// Sets the index schema version for this package.
14641473
///
14651474
/// See `cargo::sources::registry::IndexPackage` for more information.
@@ -1536,6 +1545,7 @@ impl Package {
15361545
self.yanked,
15371546
self.links.clone(),
15381547
self.rust_version.as_deref(),
1548+
self.pubtime.as_deref(),
15391549
self.v,
15401550
)
15411551
};

crates/cargo-util-schemas/index.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
"null"
6969
]
7070
},
71+
"pubtime": {
72+
"description": "The publish time for the package. Unstable.\n\nIn ISO8601 with UTC timezone (e.g. 2025-11-12T19:30:12Z)",
73+
"type": [
74+
"string",
75+
"null"
76+
]
77+
},
7178
"v": {
7279
"description": "The schema version for this entry.\n\nIf this is None, it defaults to version `1`. Entries with unknown\nversions are ignored.\n\nVersion `2` schema adds the `features2` field.\n\nVersion `3` schema adds `artifact`, `bindep_targes`, and `lib` for\nartifact dependencies support.\n\nThis provides a method to safely introduce changes to index entries\nand allow older versions of cargo to ignore newer entries it doesn't\nunderstand. This is honored as of 1.51, so unfortunately older\nversions will ignore it, and potentially misinterpret version 2 and\nnewer entries.\n\nThe intent is that versions older than 1.51 will work with a\npre-existing `Cargo.lock`, but they may not correctly process `cargo\nupdate` or build a lock from scratch. In that case, cargo may\nincorrectly select a new package that uses a new index schema. A\nworkaround is to downgrade any packages that are incompatible with the\n`--precise` flag of `cargo update`.",
7380
"type": [

crates/cargo-util-schemas/src/index.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub struct IndexPackage<'a> {
4646
/// can be `None` if published before then or if not set in the manifest.
4747
#[cfg_attr(feature = "unstable-schema", schemars(with = "Option<String>"))]
4848
pub rust_version: Option<RustVersion>,
49+
/// The publish time for the package. Unstable.
50+
///
51+
/// In ISO8601 with UTC timezone (e.g. 2025-11-12T19:30:12Z)
52+
pub pubtime: Option<String>,
4953
/// The schema version for this entry.
5054
///
5155
/// If this is None, it defaults to version `1`. Entries with unknown

src/cargo/ops/cargo_package/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ impl<'a> TmpRegistry<'a> {
12291229
yanked: None,
12301230
links: new_crate.links.map(|x| x.into()),
12311231
rust_version: None,
1232+
pubtime: None,
12321233
v: Some(2),
12331234
})?;
12341235

src/cargo/sources/registry/index/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ impl IndexSummary {
674674
cksum: Default::default(),
675675
yanked: Default::default(),
676676
links: Default::default(),
677+
pubtime: Default::default(),
677678
};
678679
let summary = index_package_to_summary(&index, source_id)?;
679680
(index, summary, false)

0 commit comments

Comments
 (0)