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

refactor(toml): Pull out the schema #12911

Merged
merged 2 commits into from
Nov 6, 2023
Merged

Conversation

epage
Copy link
Contributor

@epage epage commented Nov 2, 2023

What does this PR try to resolve?

On its own, this PR is a net negative for readability / complexity. It moves all of the serde types related to manifest from toml/mod.rs to toml/schema.rs, leaving a lot of the functions and some trait implementations back in toml/mod.rs (some basic functions that made sense for the type on their own were also moved).

So why do this? This is an ooch towards having the schema broken out into a separate package (#12801). To do this, we need to

  • Identify what all types need to be put in the package. This refactor highlights the dependence on RustVersion and PackageIdSpec
  • Highlights what functionality we need to find a new home for

Follow up PRs would

  • Find better homes for the logic in toml/mod.rs, moving us away from having impl schema::Type blocks.
  • Pull out a src/cargo/util_semver package to own PartialVersion (at least) as prep for making a cargo-util-semver package (refactor(util): Pull out mod util_semver #12940)
  • Move RustVersion to manifest-toml/schema.rs, deciding what functionality needs to move with the type
  • Move or copy PackageIdSpec into manfest-toml/schema.rs, deciding what functionality remain in core/ and what moves over
  • Move toml/schema.rs to src/cargo/util_schema
  • Actually make cargo-util-semver and cargo-util-manifest-schema packages

So why do this now? This is a big change! By being incremental

  • Reduce churn for me and others
  • Be easier to review
  • Collect feedback as we go on the whole plan to avoid more painful changes later

We can back this out if needed but the further we go, the more painful it will be.

How should we test and review this PR?

Additional information

Remaining steps
- Decouple `toml/mod.rs` functionality from `toml/schema.rs`
- Pull out `core/` types referenced by `toml/schema.rs`
@rustbot
Copy link
Collaborator

rustbot commented Nov 2, 2023

r? @ehuss

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-cli Area: Command-line interface, option parsing, etc. A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-workspaces Area: workspaces Command-package S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 2, 2023
@rustbot rustbot added the A-unstable Area: nightly unstable support label Nov 2, 2023
@ehuss
Copy link
Contributor

ehuss commented Nov 3, 2023

Just to confirm, this just moves things, there aren't any other changes of substance?

If so, it sounds good to me. However, I'd like to defer to @weihanglo to see what they would like.

r? @weihanglo

@rustbot rustbot assigned weihanglo and unassigned ehuss Nov 3, 2023
@epage
Copy link
Contributor Author

epage commented Nov 3, 2023

Correct. The most visible changes are for cargo-as-a-library users

  • Types moved
  • More types are pub
  • Fields are pub

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module name doesn't catch my eye. toml::schema looks pretty genernal that we might also want config.toml to be inside. I don't think that's the better direction, but is it in the plan in your mind?

@epage
Copy link
Contributor Author

epage commented Nov 6, 2023

Thats been a problem for util::toml for a while :)

This doesn't try to solve it. I laid out my plan within the PR description. Currently, I have the package name as cargo-util-schema but tht does remind me that I meant it to be cargo-util-manifest-schema

EDIT: PR description is updated

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I left two comments about the visibility of seemingly internal only fields, I am going to merge this to unblock stuff.


/// Provide a helpful error message for a common user error.
#[serde(rename = "cargo-features", skip_serializing)]
pub _invalid_cargo_features: Option<InvalidCargoFeatures>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case of making this public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on if we want this to be #[non_exhaustive] or directly constructable. For now, I was going with directly constructable.

/// This is here to provide a way to see the "unused manifest keys" when deserializing
#[serde(skip_serializing)]
#[serde(flatten)]
pub unused_keys: BTreeMap<String, toml::Value>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like for emitting a better warning only. Do we want to pub this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Callers might want to collect unused keys
  • See above about #[non_exhaustive]

@weihanglo
Copy link
Member

Correct. The most visible changes are for cargo-as-a-library users

* Types moved

* More types are pub

* Fields are pub

Worth noting that, making fields and types pub doesn't mean they are stable. There is still no strong stability guarantee for Cargo as a library, but this PR is a path forward that goal.

@bors r+

@bors
Copy link
Contributor

bors commented Nov 6, 2023

📌 Commit 9a1bbc9 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2023
@bors
Copy link
Contributor

bors commented Nov 6, 2023

⌛ Testing commit 9a1bbc9 with merge 1efd40e...

bors added a commit that referenced this pull request Nov 6, 2023
refactor(toml): Pull out the schema

### What does this PR try to resolve?

On its own, this PR is a net negative for readability / complexity.  It moves all of the serde types related to manifest from `toml/mod.rs` to `toml/schema.rs`, leaving a lot of the functions and some trait implementations back in `toml/mod.rs` (some basic functions that made sense for the type on their own were also moved).

So why do this?  This is an ooch towards having the schema broken out into a separate package (#12801).  To do this, we need to
- Identify what all types need to be put in the package.  This refactor highlights the dependence on `RustVersion` and `PackageIdSpec`
- Highlights what functionality we need to find a new home for

Follow up PRs would
- Find better homes for the logic in `toml/mod.rs`, moving us away from having `impl schema::Type` blocks.
- Pull out a `src/cargo/util_semver` package to own `PartialVersion` (at least) as prep for making a `cargo-util-semver` package
- Move `RustVersion` to `manifest-toml/schema.rs`, deciding what functionality needs to move with the type
- Move or copy `PackageIdSpec` into `manfest-toml/schema.rs`, deciding what functionality remain in `core/` and what moves over
- Move `toml/schema.rs` to `src/cargo/util_schema`
- Actually make `cargo-util-semver` and `cargo-util-manifest-schema` packages

So why do this now? This is a big change!  By being incremental
- Reduce churn for me and others
- Be easier to review
- Collect feedback as we go on the whole plan to avoid more painful changes later

We *can* back this out if needed but the further we go, the more painful it will be.

### How should we test and review this PR?

### Additional information
@bors
Copy link
Contributor

bors commented Nov 6, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 6, 2023
@epage
Copy link
Contributor Author

epage commented Nov 6, 2023

Blocked on #12921

@weihanglo
Copy link
Member

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2023
@bors
Copy link
Contributor

bors commented Nov 6, 2023

⌛ Testing commit 9a1bbc9 with merge 4300dd7...

@bors
Copy link
Contributor

bors commented Nov 6, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 4300dd7 to master...

@bors bors merged commit 4300dd7 into rust-lang:master Nov 6, 2023
20 checks passed
@epage epage deleted the manifest-schema branch November 6, 2023 21:06
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 8, 2023
Update cargo

7 commits in 65e297d1ec0dee1a74800efe600b8dc163bcf5db..7046d992f9f32ba209a8079f662ebccf9da8de25
2023-11-03 20:56:31 +0000 to 2023-11-08 03:24:57 +0000
- fix: Report more detailed semver errors (rust-lang/cargo#12924)
- Fix some broken links in the man pages (rust-lang/cargo#12929)
- Add better error message when it can not find the search section (rust-lang/cargo#12865)
- Bug 12920 (rust-lang/cargo#12923)
- Update link in environment-variables.md (rust-lang/cargo#12922)
- refactor(toml): Pull out the schema (rust-lang/cargo#12911)
- tests: Remove plugin tests (rust-lang/cargo#12921)

r? ghost
bors added a commit that referenced this pull request Nov 9, 2023
refactor(toml): Simplify code to make schema split easier

### What does this PR try to resolve?

This is a follow up to #12911 and is prep for #12801.

### How should we test and review this PR?

### Additional information
@ehuss ehuss added this to the 1.75.0 milestone Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-cli Area: Command-line interface, option parsing, etc. A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-unstable Area: nightly unstable support A-workspaces Area: workspaces Command-package S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants