Skip to content

Commit 633929d

Browse files
committed
refactor(schemas): Pull out cargo-util-schemas crate
Fixes #12801
1 parent 1b6d864 commit 633929d

38 files changed

+100
-54
lines changed

Cargo.lock

+16-2
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
@@ -30,6 +30,7 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.4" }
3030
cargo-test-macro = { path = "crates/cargo-test-macro" }
3131
cargo-test-support = { path = "crates/cargo-test-support" }
3232
cargo-util = { version = "0.2.6", path = "crates/cargo-util" }
33+
cargo-util-schemas = { version = "0.1.0", path = "crates/cargo-util-schemas" }
3334
cargo_metadata = "0.18.1"
3435
clap = "4.4.10"
3536
color-print = "0.3.5"
@@ -144,6 +145,7 @@ base64.workspace = true
144145
bytesize.workspace = true
145146
cargo-credential.workspace = true
146147
cargo-platform.workspace = true
148+
cargo-util-schemas.workspace = true
147149
cargo-util.workspace = true
148150
clap = { workspace = true, features = ["wrap_help"] }
149151
color-print.workspace = true
@@ -183,7 +185,6 @@ rustfix.workspace = true
183185
semver.workspace = true
184186
serde = { workspace = true, features = ["derive"] }
185187
serde-untagged.workspace = true
186-
serde-value.workspace = true
187188
serde_ignored.workspace = true
188189
serde_json = { workspace = true, features = ["raw_value"] }
189190
sha1.workspace = true
@@ -199,7 +200,6 @@ tracing.workspace = true
199200
tracing-subscriber.workspace = true
200201
unicase.workspace = true
201202
unicode-width.workspace = true
202-
unicode-xid.workspace = true
203203
url.workspace = true
204204
walkdir.workspace = true
205205

crates/cargo-util-schemas/Cargo.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "cargo-util-schemas"
3+
version = "0.1.0"
4+
rust-version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
homepage = "https://github.com/rust-lang/cargo"
8+
repository = "https://github.com/rust-lang/cargo"
9+
description = "Deserialization schemas for Cargo"
10+
11+
[dependencies]
12+
anyhow.workspace = true
13+
semver.workspace = true
14+
serde = { workspace = true, features = ["derive"] }
15+
serde-untagged.workspace = true
16+
serde-value.workspace = true
17+
toml.workspace = true
18+
unicode-xid.workspace = true
19+
url.workspace = true
20+
21+
[lints]
22+
workspace = true
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE-APACHE

crates/cargo-util-schemas/LICENSE-MIT

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE-MIT
File renamed without changes.

src/cargo/util_schemas/core/package_id_spec.rs crates/cargo-util-schemas/src/core/package_id_spec.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use semver::Version;
66
use serde::{de, ser};
77
use url::Url;
88

9-
use crate::util_schemas::core::GitReference;
10-
use crate::util_schemas::core::PartialVersion;
11-
use crate::util_schemas::core::SourceKind;
12-
use crate::util_schemas::manifest::PackageName;
9+
use crate::core::GitReference;
10+
use crate::core::PartialVersion;
11+
use crate::core::SourceKind;
12+
use crate::manifest::PackageName;
1313

1414
/// Some or all of the data required to identify a package:
1515
///
@@ -59,7 +59,7 @@ impl PackageIdSpec {
5959
/// Some examples of valid strings
6060
///
6161
/// ```
62-
/// use cargo::core::PackageIdSpec;
62+
/// use cargo_util_schemas::core::PackageIdSpec;
6363
///
6464
/// let specs = vec![
6565
/// "https://crates.io/foo",
@@ -280,7 +280,7 @@ impl<'de> de::Deserialize<'de> for PackageIdSpec {
280280
#[cfg(test)]
281281
mod tests {
282282
use super::PackageIdSpec;
283-
use crate::util_schemas::core::{GitReference, SourceKind};
283+
use crate::core::{GitReference, SourceKind};
284284
use url::Url;
285285

286286
#[test]
File renamed without changes.

src/cargo/util_schemas/manifest.rs crates/cargo-util-schemas/src/manifest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use serde::ser;
1616
use serde::{Deserialize, Serialize};
1717
use serde_untagged::UntaggedEnumVisitor;
1818

19-
use crate::util_schemas::core::PackageIdSpec;
20-
use crate::util_schemas::core::PartialVersion;
21-
use crate::util_schemas::restricted_names;
19+
use crate::core::PackageIdSpec;
20+
use crate::core::PartialVersion;
21+
use crate::restricted_names;
2222

2323
/// This type is used to deserialize `Cargo.toml` files.
2424
#[derive(Debug, Deserialize, Serialize)]

crates/resolver-tests/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77

88
[dependencies]
99
cargo.workspace = true
10+
cargo-util-schemas.workspace = true
1011
cargo-util.workspace = true
1112
proptest.workspace = true
1213
varisat.workspace = true

crates/resolver-tests/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cargo::core::{GitReference, SourceId};
1919
use cargo::sources::source::QueryKind;
2020
use cargo::sources::IndexSummary;
2121
use cargo::util::{CargoResult, Config, IntoUrl};
22-
use cargo::util_schemas::manifest::RustVersion;
22+
use cargo_util_schemas::manifest::RustVersion;
2323

2424
use proptest::collection::{btree_map, vec};
2525
use proptest::prelude::*;

crates/xtask-bump-check/src/xtask.rs

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoRes
168168
let mut cmd = ProcessBuilder::new("cargo");
169169
cmd.arg("semver-checks")
170170
.arg("check-release")
171+
.args(&["--exclude", "cargo-util-schemas"]) // FIXME: Remove once 1.76 is stable
171172
.arg("--workspace");
172173
config.shell().status("Running", &cmd)?;
173174
cmd.exec()?;
@@ -177,6 +178,7 @@ fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoRes
177178
cmd.arg("semver-checks")
178179
.arg("--workspace")
179180
.args(&["--exclude", "rustfix"]) // FIXME: Remove once 1.76 is stable
181+
.args(&["--exclude", "cargo-util-schemas"]) // FIXME: Remove once 1.76 is stable
180182
.arg("--baseline-rev")
181183
.arg(referenced_commit.id().to_string());
182184
for krate in crates_not_check_against_channels {

publish.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'crates/cargo-platform',
2626
'crates/cargo-util',
2727
'crates/crates-io',
28+
'crates/cargo-util-schemas',
2829
'.',
2930
]
3031

src/bin/cargo/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use cargo::util::network::http::http_handle;
44
use cargo::util::network::http::needs_custom_http_transport;
55
use cargo::util::CliError;
66
use cargo::util::{self, closest_msg, command_prelude, CargoResult, CliResult, Config};
7-
use cargo::util_schemas::manifest::StringOrVec;
87
use cargo_util::{ProcessBuilder, ProcessError};
8+
use cargo_util_schemas::manifest::StringOrVec;
99
use std::collections::BTreeMap;
1010
use std::env;
1111
use std::ffi::OsStr;

src/cargo/core/compiler/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ use crate::util::errors::{CargoResult, VerboseError};
9494
use crate::util::interning::InternedString;
9595
use crate::util::machine_message::{self, Message};
9696
use crate::util::{add_path_args, internal, iter_join_onto, profile};
97-
use crate::util_schemas::manifest::TomlDebugInfo;
98-
use crate::util_schemas::manifest::TomlTrimPaths;
9997
use cargo_util::{paths, ProcessBuilder, ProcessError};
98+
use cargo_util_schemas::manifest::TomlDebugInfo;
99+
use cargo_util_schemas::manifest::TomlTrimPaths;
100100
use rustfix::diagnostics::Applicability;
101101

102102
const RUSTDOC_CRATE_VERSION_FLAG: &str = "--crate-version";

src/cargo/core/manifest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::rc::Rc;
66
use std::sync::Arc;
77

88
use anyhow::Context as _;
9+
use cargo_util_schemas::manifest::RustVersion;
10+
use cargo_util_schemas::manifest::{TomlManifest, TomlProfiles};
911
use semver::Version;
1012
use serde::ser;
1113
use serde::Serialize;
@@ -19,8 +21,6 @@ use crate::core::{Edition, Feature, Features, WorkspaceConfig};
1921
use crate::util::errors::*;
2022
use crate::util::interning::InternedString;
2123
use crate::util::{short_hash, Config, Filesystem};
22-
use crate::util_schemas::manifest::RustVersion;
23-
use crate::util_schemas::manifest::{TomlManifest, TomlProfiles};
2424

2525
pub enum EitherManifest {
2626
Real(Manifest),

src/cargo/core/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use self::workspace::{
1414
find_workspace_root, resolve_relative_path, MaybePackage, Workspace, WorkspaceConfig,
1515
WorkspaceRootConfig,
1616
};
17-
pub use crate::util_schemas::core::{GitReference, PackageIdSpec, SourceKind};
17+
pub use cargo_util_schemas::core::{GitReference, PackageIdSpec, SourceKind};
1818

1919
pub mod compiler;
2020
pub mod dependency;

src/cargo/core/package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::time::{Duration, Instant};
1010

1111
use anyhow::Context;
1212
use bytesize::ByteSize;
13+
use cargo_util_schemas::manifest::RustVersion;
1314
use curl::easy::Easy;
1415
use curl::multi::{EasyHandle, Multi};
1516
use lazycell::LazyCell;
@@ -33,7 +34,6 @@ use crate::util::network::retry::{Retry, RetryResult};
3334
use crate::util::network::sleep::SleepTracker;
3435
use crate::util::toml::prepare_for_publish;
3536
use crate::util::{self, internal, Config, Progress, ProgressStyle};
36-
use crate::util_schemas::manifest::RustVersion;
3737

3838
pub const MANIFEST_PREAMBLE: &str = "\
3939
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

src/cargo/core/profiles.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ use crate::core::{
3131
use crate::util::interning::InternedString;
3232
use crate::util::toml::validate_profile;
3333
use crate::util::{closest_msg, config, CargoResult, Config};
34-
use crate::util_schemas::manifest::TomlTrimPaths;
35-
use crate::util_schemas::manifest::TomlTrimPathsValue;
36-
use crate::util_schemas::manifest::{
34+
use anyhow::{bail, Context as _};
35+
use cargo_util_schemas::manifest::TomlTrimPaths;
36+
use cargo_util_schemas::manifest::TomlTrimPathsValue;
37+
use cargo_util_schemas::manifest::{
3738
ProfilePackageSpec, StringOrBool, TomlDebugInfo, TomlProfile, TomlProfiles,
3839
};
39-
use anyhow::{bail, Context as _};
4040
use std::collections::{BTreeMap, HashMap, HashSet};
4141
use std::hash::Hash;
4242
use std::{cmp, fmt, hash};

src/cargo/core/resolver/version_prefs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
use std::cmp::Ordering;
55
use std::collections::{HashMap, HashSet};
66

7+
use cargo_util_schemas::manifest::RustVersion;
8+
79
use crate::core::{Dependency, PackageId, Summary};
810
use crate::util::interning::InternedString;
9-
use crate::util_schemas::manifest::RustVersion;
1011

1112
/// A collection of preferences for particular package versions.
1213
///

src/cargo/core/summary.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::core::{Dependency, PackageId, SourceId};
22
use crate::util::interning::InternedString;
33
use crate::util::CargoResult;
4-
use crate::util_schemas::manifest::FeatureName;
5-
use crate::util_schemas::manifest::RustVersion;
64
use anyhow::bail;
5+
use cargo_util_schemas::manifest::FeatureName;
6+
use cargo_util_schemas::manifest::RustVersion;
77
use semver::Version;
88
use std::collections::{BTreeMap, HashMap, HashSet};
99
use std::fmt;

src/cargo/core/workspace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ use crate::util::errors::{CargoResult, ManifestError};
2626
use crate::util::interning::InternedString;
2727
use crate::util::toml::{read_manifest, InheritableFields};
2828
use crate::util::{config::ConfigRelativePath, Config, Filesystem, IntoUrl};
29-
use crate::util_schemas::manifest::RustVersion;
30-
use crate::util_schemas::manifest::{TomlDependency, TomlProfiles};
3129
use cargo_util::paths;
3230
use cargo_util::paths::normalize_path;
31+
use cargo_util_schemas::manifest::RustVersion;
32+
use cargo_util_schemas::manifest::{TomlDependency, TomlProfiles};
3333
use pathdiff::diff_paths;
3434

3535
/// The core abstraction in Cargo for working with a workspace of crates.

src/cargo/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
//! - [`cargo-util`](https://crates.io/crates/cargo-util)
6363
//! ([nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/cargo_util)):
6464
//! This contains general utility code that is shared between cargo and the testsuite
65+
//! - [`cargo-util-schemas`](https://crates.io/crates/cargo-util-schemas)
66+
//! ([nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/cargo_util-schemas)):
67+
//! This contains the serde schemas for cargo
6568
//! - [`crates-io`](https://crates.io/crates/crates-io)
6669
//! ([nightly docs](https://doc.rust-lang.org/nightly/nightly-rustc/crates_io)):
6770
//! This contains code for accessing the crates.io API.
@@ -98,7 +101,7 @@
98101
//! Files that interact with cargo include
99102
//!
100103
//! - Package
101-
//! - `Cargo.toml`: User-written project manifest, loaded with [`util_schemas::manifest::TomlManifest`] and then
104+
//! - `Cargo.toml`: User-written project manifest, loaded with [`util::toml::read_manifest`] and then
102105
//! translated to [`core::manifest::Manifest`] which maybe stored in a [`core::Package`].
103106
//! - This is editable with [`util::toml_mut::manifest::LocalManifest`]
104107
//! - `Cargo.lock`: Generally loaded with [`ops::resolve_ws`] or a variant of it into a [`core::resolver::Resolve`]
@@ -152,7 +155,6 @@ pub mod core;
152155
pub mod ops;
153156
pub mod sources;
154157
pub mod util;
155-
pub mod util_schemas;
156158
mod version;
157159

158160
pub fn exit_with_error(err: CliError, shell: &mut Shell) -> ! {

src/cargo/ops/cargo_add/crate_spec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use anyhow::Context as _;
44

55
use super::Dependency;
66
use crate::util::toml_mut::dependency::RegistrySource;
7-
use crate::util_schemas::manifest::PackageName;
87
use crate::CargoResult;
8+
use cargo_util_schemas::manifest::PackageName;
99

1010
/// User-specified crate
1111
///

src/cargo/ops/cargo_add/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::str::FromStr;
1111

1212
use anyhow::Context as _;
1313
use cargo_util::paths;
14+
use cargo_util_schemas::manifest::RustVersion;
1415
use indexmap::IndexSet;
1516
use itertools::Itertools;
1617
use toml_edit::Item as TomlItem;
@@ -35,7 +36,6 @@ use crate::util::toml_mut::dependency::WorkspaceSource;
3536
use crate::util::toml_mut::is_sorted;
3637
use crate::util::toml_mut::manifest::DepTable;
3738
use crate::util::toml_mut::manifest::LocalManifest;
38-
use crate::util_schemas::manifest::RustVersion;
3939
use crate::CargoResult;
4040
use crate::Config;
4141
use crate_spec::CrateSpec;

src/cargo/ops/cargo_new.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::util::important_paths::find_root_manifest_for_wd;
44
use crate::util::toml_mut::is_sorted;
55
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
66
use crate::util::{restricted_names, Config};
7-
use crate::util_schemas::manifest::PackageName;
87
use anyhow::{anyhow, Context};
98
use cargo_util::paths::{self, write_atomic};
9+
use cargo_util_schemas::manifest::PackageName;
1010
use serde::de;
1111
use serde::Deserialize;
1212
use std::collections::BTreeMap;

src/cargo/ops/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ use crate::sources::PathSource;
7272
use crate::util::cache_lock::CacheLockMode;
7373
use crate::util::errors::CargoResult;
7474
use crate::util::{profile, CanonicalUrl};
75-
use crate::util_schemas::manifest::RustVersion;
7675
use anyhow::Context as _;
76+
use cargo_util_schemas::manifest::RustVersion;
7777
use std::collections::{HashMap, HashSet};
7878
use tracing::{debug, trace};
7979

0 commit comments

Comments
 (0)