Skip to content

feat(builtin-deps): Add builtin dependencies manifest syntax - #17498

Merged
weihanglo merged 12 commits into
rust-lang:masterfrom
adamgemmell:dev/builtins/builtin-deps
Sep 23, 2026
Merged

weihanglo merged 12 commits into
rust-lang:masterfrom
adamgemmell:dev/builtins/builtin-deps

Conversation

@adamgemmell

@adamgemmell adamgemmell commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

What does this PR try to resolve?

As part of #16960, this PR adds the required syntax to the manifest to specify builtin dependencies. The main validation present in this PR is that builtin = true being present anywhere requires the builtin-dependencies feature in order to avoid accidentally introducing any new stable behaviour in later PRs. Invalid forms of builtin dependencies are rejected in a later PR. For now builtin dependencies panic with a todo!() as there is no SourceKind variant to represent them.

This PR is part of a chain:

How to test and review this PR?

The PR first introduces the manifest syntax, then builds on that by adding various tests that builtin = true requires an unstable feature. Cargo test passes on every commit.

🤖 LLM disclosure: I used Codex to help me understand the codebase and asked it to review my branch before sharing it upstream. I also used it in limited (pre-arranged) ways to generate code, including resolving merge conflicts and updating test assertions. All code was originally written by hand.

r? @weihanglo

@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-unstable Area: nightly unstable support A-workspaces Area: workspaces S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 21, 2026
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
pub struct TomlDetailedDependency<P: Clone = String> {
pub version: Option<String>,
pub builtin: Option<bool>,

@epage epage Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did the rfc allow builtin = false? We don't allow it for workspace = true.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't specify, I treated builtin = false the same as no builtin key (see the following PR for a bit more detail here). Happy to fix it to follow the workspace convention

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

see the following PR for a bit more detail here

do you mean the implementation, test, or further exposition? If exposition, I missed it.

@weihanglo or @Muscraft any thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean for some demonstration about what's allowed and what isn't. For example I added a test that builtin = false can be combined with other sources, but didn't gate builtin = false on the feature gate since it was technically always allowed in manifests with a warning. #17499

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unless there is a meaning or future expansion for builtin = false, it seems more consistent to follow what workspace does.

Also, currently builtin = false is accepted on stable which is not fine.

@adamgemmell adamgemmell Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can add "const": true to the json schema to disallow builtin = false.

The null in the json schema seems weird to me. I think that allows explicitly setting each key to null (which TOML doesn't even support). Unless I'm missing something, the json schema docs say that all properties are optional by default, unless listed under "required" (for example, workspace is required for a TomlInheritedDependency)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is fair. Does schemars support const: true?

Anyway, the JSON schema is unstable. We can track it and deal with it later. I am going to merge this. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, the validation will be added in 127ca62 (#17499)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Somewhat, you need to tell it to add the attribute with schemars(extend("const" = true))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added to that PR: 0ad30c2

Comment thread src/workspace/parser/mod.rs Outdated
if orig.version.is_none()
&& orig.path.is_none()
&& orig.git.is_none()
&& orig.builtin != Some(true)

@epage epage Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should have a stabilization task on the tracking issue for updating the error text

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a note on the tracking issue: #16960 (comment)

pull Bot pushed a commit to Little-Star888/cargo that referenced this pull request Sep 21, 2026
…-lang#17497)

### What does this PR try to resolve?

As part of rust-lang#16960, this PR adds
a new unstable feature which will be used to gate the `builtin = true`
syntax on builtin dependencies.

This PR is part of a chain:
- rust-lang#17497
- rust-lang#17498
- rust-lang#17499
- rust-lang#17500

### How to test and review this PR?

This PR adds a unit test to demonstrate that the allowed feature gate
works. It also adds documentation for the feature gate. `cargo test`
passes on all commits.

r? @Muscraft

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally looks great for handling the syntax part. Thanks! I wish GitHub's UI supports cross-repo stack PR UI though.

Also, could we have a checklist tracking all the todos, for example, we should track cargo add and cargo rm support for builtin.

View changes since this review

Comment thread src/workspace/parser/mod.rs Outdated
orig.builtin,
) {
(Some(_git), Some(_path), _, _) => {
(_, _, _, _, Some(true)) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This match has grown to a state that is not easy to understand. I wonder if builtin is exclusive enough that we should just check if orig.builtin first before any other fields. I am fine with a slightly worse diagnostic at first.

(haven't checked other PR though so not sure this suggestion makes sense)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Opened #17502 to refactor this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've followed your suggestion about handling builtins first and not touching the match statement.

#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
pub struct TomlDetailedDependency<P: Clone = String> {
pub version: Option<String>,
pub builtin: Option<bool>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unless there is a meaning or future expansion for builtin = false, it seems more consistent to follow what workspace does.

Also, currently builtin = false is accepted on stable which is not fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we have test for this case? This should be banned I feel like.

core = { workspace = true, builtin = true }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is more appropriate for #17499 , see also #17498 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added behaviour to reject this in the following PR: 1d3482d

@adamgemmell
adamgemmell force-pushed the dev/builtins/builtin-deps branch from 91ca7cb to d76cabd Compare September 23, 2026 12:47
@rustbot

rustbot commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@adamgemmell
adamgemmell force-pushed the dev/builtins/builtin-deps branch from d76cabd to 04e9c83 Compare September 23, 2026 12:58
@adamgemmell
adamgemmell force-pushed the dev/builtins/builtin-deps branch from 04e9c83 to 9b682d7 Compare September 23, 2026 13:00
@adamgemmell

Copy link
Copy Markdown
Contributor Author

Also, could we have a checklist tracking all the todos, for example, we should track cargo add and cargo rm support for builtin.

I'm tracking this in the work plan hackmd for now, does that work for you?

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@weihanglo
weihanglo added this pull request to the merge queue Sep 23, 2026
Merged via the queue into rust-lang:master with commit 2134e98 Sep 23, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 23, 2026
adamgemmell pushed a commit to adamgemmell/cargo that referenced this pull request Sep 23, 2026
…g#17499)

### What does this PR try to resolve?

As part of rust-lang#16960 this PR adds
validation checks to reject invalid forms of the manifest including
builtin dependencies, such as when they are present in the
`build-dependencies` section or combined with other sources. The
[RFC](https://rust-lang.github.io/rfcs/3875-build-std-explicit-dependencies.html#)
specifies what forms of builtin dependencies are valid.

This PR is part of a chain:
- rust-lang#17497
- rust-lang#17502
- rust-lang#17498
- rust-lang#17499
- rust-lang#17500

### How to test and review this PR?

The PR consists of commits which add a test demonstrating some undesired
behaviour and then fixes that in the following commit. Cargo test passes
on every commit.

🤖 LLM disclosure: I used Codex to help me understand the codebase and
asked it to review my branch before sharing it upstream. I also used it
in limited (pre-arranged) ways to generate code, including resolving
merge conflicts and updating test assertions. All code was originally
written by hand.

r? @weihanglo
pull Bot pushed a commit to linyihai/cargo that referenced this pull request Sep 23, 2026
…7500)

### What does this PR try to resolve?

As part of rust-lang#16960 this PR adds
a series of tests that already pass, confirming existing behaviour and
preventing any future regressions.

This PR is part of a chain:
- rust-lang#17497
- rust-lang#17502
- rust-lang#17498
- rust-lang#17499
- rust-lang#17500

### How to test and review this PR?

Review all at once or commit-by-commit, there's no overlap between
commits. Cargo test passes on every commit.

🤖 LLM disclosure: I used Codex to help me understand the codebase and
asked it to review my branch before sharing it upstream. I also used it
in limited (pre-arranged) ways to generate code, including resolving
merge conflicts and updating test assertions. All code was originally
written by hand.

r? @weihanglo
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Sep 25, 2026
Update cargo submodule

5 commits in 98a09e7e7d62850f14e5b6132101fc1edd19a16f..3d7cf6e937d6127d0f49881bf689c560b36d35c4
2026-09-21 19:03:16 +0000 to 2026-09-25 01:47:29 +0000
- fix(package): preserve feature metadata in normalized manifests (rust-lang/cargo#17509)
- fix(diag): Don't report unused normal deps when static libs are skipped  (rust-lang/cargo#17515)
- test(builtin-deps): Additional manifest regression tests (rust-lang/cargo#17500)
- fix(builtin-deps): Builtin dependencies manifest validation (rust-lang/cargo#17499)
- feat(builtin-deps): Add builtin dependencies manifest syntax (rust-lang/cargo#17498)

r? ghost
@rustbot rustbot added this to the 1.100.0 milestone Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-unstable Area: nightly unstable support A-workspaces Area: workspaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants