Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow registries to omit empty/default fields in JSON #14838

Merged
merged 1 commit into from
Nov 19, 2024
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
8 changes: 8 additions & 0 deletions src/cargo/sources/registry/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub struct IndexPackage<'a> {
#[serde(borrow)]
pub deps: Vec<RegistryDependency<'a>>,
/// Set of features defined for the package, i.e., `[features]` table.
#[serde(default)]
pub features: BTreeMap<InternedString, Vec<InternedString>>,
/// This field contains features with new, extended syntax. Specifically,
/// namespaced features (`dep:`) and weak dependencies (`pkg?/feat`).
Expand Down Expand Up @@ -268,10 +269,13 @@ pub struct RegistryDependency<'a> {
#[serde(borrow)]
pub req: Cow<'a, str>,
/// Set of features enabled for this dependency.
#[serde(default)]
pub features: Vec<InternedString>,
/// Whether or not this is an optional dependency.
#[serde(default)]
pub optional: bool,
/// Whether or not default features are enabled.
#[serde(default = "default_true")]
pub default_features: bool,
/// The target platform for this dependency.
pub target: Option<Cow<'a, str>>,
Expand All @@ -292,6 +296,10 @@ pub struct RegistryDependency<'a> {
pub lib: bool,
}

fn default_true() -> bool {
true
}

impl<'gctx> RegistryIndex<'gctx> {
/// Creates an empty registry index at `path`.
pub fn new(
Expand Down
14 changes: 6 additions & 8 deletions src/doc/src/reference/registry-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,24 @@ explaining the format of the entry.
"req": "^0.6",
// Array of features (as strings) enabled for this dependency.
"features": ["i128_support"],
kornelski marked this conversation as resolved.
Show resolved Hide resolved
// Boolean of whether or not this is an optional dependency.
// Boolean of whether or not this is an optional dependency. Defaults to `false` if not specified.
kornelski marked this conversation as resolved.
Show resolved Hide resolved
"optional": false,
// Boolean of whether or not default features are enabled.
// Boolean of whether or not default features are enabled. Defaults to `true` if not specified.
kornelski marked this conversation as resolved.
Show resolved Hide resolved
"default_features": true,
// The target platform for the dependency.
// null if not a target dependency.
// If not specified or `null`, it is not a target dependency.
// Otherwise, a string such as "cfg(windows)".
"target": null,
// The dependency kind.
// "dev", "build", or "normal".
// Note: this is a required field, but a small number of entries
// exist in the crates.io index with either a missing or null
// `kind` field due to implementation bugs.
// If not specified or `null`, it defaults to "normal".
"kind": "normal",
// The URL of the index of the registry where this dependency is
// from as a string. If not specified or null, it is assumed the
// from as a string. If not specified or `null`, it is assumed the
// dependency is in the current registry.
"registry": null,
// If the dependency is renamed, this is a string of the actual
// package name. If not specified or null, this dependency is not
// package name. If not specified or `null`, this dependency is not
// renamed.
"package": null,
}
Expand Down