Skip to content

Add --print target-spec-json-schema #144498

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Noratrieb
Copy link
Member

@Noratrieb Noratrieb commented Jul 26, 2025

This schema is helpful for people writing custom target spec JSON. It can provide autocomplete in the editor, and also serves as documentation when there are documentation comments on the structs, as schemars will put them in the schema.

I was motivated to do this because I saw someone write their own version of this schema by hand, so demand for this clearly exists. It's not a lot of effort to implement, so I thought it would make sense.

MCP: rust-lang/compiler-team#905

I think it would also be useful to put this in the sysroot in etc so people can link it directly in their editors.

I would have loved to add a test that validates the JSON schema against the spec JSON of every builtin target, but I don't want to do it as the JSON schema validation crates have incredible amounts of dependencies because JSON schema supports a ton of random features. I don't want to add that, even as a dev dependency.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 26, 2025
@rust-log-analyzer

This comment has been minimized.

With this macro we only need to enumerate every variant once. This saves
a lot of duplication already between the definition, the `FromStr` impl
and the `ToJson` impl.

It also enables us to do further things with it like JSON schema
generation.
@Noratrieb Noratrieb force-pushed the rustc-json-schema branch from 547cba8 to d6acb28 Compare July 26, 2025 22:15
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 26, 2025
@rust-log-analyzer

This comment has been minimized.

@Noratrieb Noratrieb force-pushed the rustc-json-schema branch from d6acb28 to 8f1abd3 Compare July 27, 2025 11:33
@rust-log-analyzer

This comment has been minimized.

@Noratrieb Noratrieb force-pushed the rustc-json-schema branch from 8f1abd3 to a07cfd1 Compare July 27, 2025 12:18
@rust-log-analyzer

This comment has been minimized.

This schema is helpful for people writing custom target spec JSON. It
can provide autocomplete in the editor, and also serves as documentation
when there are documentation comments on the structs, as `schemars` will
put them in the schema.
@Noratrieb Noratrieb force-pushed the rustc-json-schema branch from a07cfd1 to d4383c1 Compare July 27, 2025 13:42
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jul 27, 2025
@Noratrieb Noratrieb marked this pull request as ready for review July 27, 2025 17:52
@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging.

cc @davidtwco, @wesleywiser

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

These commits modify compiler targets.
(See the Target Tier Policy.)

This PR modifies run-make tests.

cc @jieyouxu

There are changes to the tidy tool.

cc @jieyouxu

@Noratrieb
Copy link
Member Author

Noratrieb commented Jul 27, 2025

The MCP isn't accepted yet, but that doesn't need to stop anyone from reviewing.
r? jieyouxu maybe you want to review it since it also touches bootstrap?

@rustbot rustbot assigned jieyouxu and unassigned fee1-dead Jul 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2025

jieyouxu is currently at their maximum review capacity.
They may take a while to respond.

@jieyouxu
Copy link
Member

I can probably review it after the MCP passes.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me overall, a few questions

fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
schemars::json_schema! ({
"type": "string",
"enum": ["false", "true", "wasm", "musl", "mingw"]
Copy link
Member

Choose a reason for hiding this comment

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

Question: for some options, it seems like there are no target_spec_enum-like help where the possible variants are sync'd. Not that I think this is a big problem, just some extra potential for desync.

Comment on lines +915 to +917
schemars::json_schema! ({
"type": "string",
})
Copy link
Member

@jieyouxu jieyouxu Jul 29, 2025

Choose a reason for hiding this comment

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

Question: is this because it's annoying if not impossible to express an array of:

  • "Simple strings" like none or default-for-arch, vs
  • "Key-value strings" like llvm-module-flag=xxx or llvm-arg=xxx, right?

@@ -361,6 +362,8 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"rand_xorshift", // dependency for doc-tests in rustc_thread_pool
"rand_xoshiro",
"redox_syscall",
"ref-cast",
Copy link
Member

Choose a reason for hiding this comment

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

Remark: at least this uses rustc version detection, not just nightly detection

https://github.com/dtolnay/ref-cast/blob/1.0.24/build.rs

@jieyouxu
Copy link
Member

None of them are blocking, so feel free to r=me once the MCP is accepted.

@jieyouxu jieyouxu added S-waiting-on-MCP Status: PR has a compiler MCP and is waiting for the compiler MCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs A-tidy Area: The tidy tool S-waiting-on-MCP Status: PR has a compiler MCP and is waiting for the compiler MCP to complete. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants