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

Expose std support via --print #3693

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamgemmell
Copy link

@adamgemmell adamgemmell commented Sep 12, 2024

As discussed on Zulip, this RFC proposes adding a new argument for rustc --print that acts as the single source of truth for whether a target supports std.

Rendered

@ehuss ehuss added the T-compiler Relevant to the compiler team, which will review and decide on the RFC. label Sep 12, 2024
@ehuss
Copy link
Contributor

ehuss commented Sep 12, 2024

I don't know what process the compiler team wants to use, but typically in the past they have been using the Major Change Proposal process for new flags and such like this (instead of an RFC).

@davidtwco
Copy link
Member

I don't know what process the compiler team wants to use, but typically in the past they have been using the Major Change Proposal process for new flags and such like this (instead of an RFC).

I think the line is a bit blurry, our documentation says:

It can also be used for small user-facing changes like adding new compiler flags, though in that case we also require an rfcbot fcp to get full approval from the team.

Is this a small user-facing change? Probably? Given that an RFC has been written and it'll be subject to an FCP anyway, I think we might as well keep it as an RFC.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

I think this is a sensible addition to --print1. I don't think we need to worry about adding options to that flag.

Footnotes

  1. for the sake of transparency: @adamgemmell and I work for the same employer and I've reviewed this internally already.

@petrochenkov
Copy link
Contributor

What does "std support" means exactly? You can, for example, make you own crate and make it the std library.

Having an std library shipped is not a property of the compiler, it's a property of the distributed toolchain, similarly to having the LLD linker shipped, for example.
How is compiler going to implement this --print option

  • Report some hardcoded value set during at toolchain's build time?
  • Actually start the crate loader and search for the crate named std?

The distribution itself can potentially ship a json file describing its components (rustup already does something like that?), then rustc --print can point to the location of that json file.

@adamgemmell
Copy link
Author

adamgemmell commented Sep 13, 2024

From my perspective rustc already treats core/std/others as special when it comes to the sysroot and attributes like #![no_std] or #![no_core]. In addition, these crates are versioned with the compiler and you can't expect to mix and match compiler and std versions, even for different nightlies for the same release version. Hence I think the term std is already unambigious except for the case where users write their own standard library crates. I can define std more strictly in the RFC to reflect this.

The RFC goes into implementation details - it's going to use an existing field in the Target spec. The output can be changed by using a custom JSON target but if a user's custom std doesn't support a target and the user wants to use a built-in target then I think I agree with your concerns. I'm not sure if people do that or what guarantees the compiler makes for people who write their own std crates.

@davidtwco
Copy link
Member

Having an std library shipped is not a property of the compiler, it's a property of the distributed toolchain, similarly to having the LLD linker shipped, for example.

To add to what @adamgemmell said, this flag isn't that related to whether a std is shipped for a target. With something like -Zbuild-std, you can build a std that isn't shipped, and on some targets that just won't build, or maybe it will but will panic unexpectedly - in that circumstance, we'd like to be able to know "this std isn't going to work" so that we can give the user a helpful message to that effect rather than a potentially confusing build error that they can't easily action.

@adamgemmell
Copy link
Author

if a user's custom std doesn't support a target and the user wants to use a built-in target

Looking back at this I'm not sure it's a concern. Whether a target can support std is still a property of the target (i.e. whether it has a suitable OS) and as the RFC says the flag doesn't attempt to differentiate targets with a "broken" std.

@wesleywiser
Copy link
Member

I think this is a reasonable addition to the --print command. What do you all think?

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Oct 22, 2024

Team member @wesleywiser has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels Oct 22, 2024
@nagisa
Copy link
Member

nagisa commented Oct 22, 2024

I want to second @petrochenkov's questions. In my mind a lot of the motivation reads as a desire to add a mechanism to "ask" before doing. It then again motivates that this is to avoid confusion by the users of -Zbuild-std. It seems to me that this particular problem could be addressed from a direction of "just doing" and then figuring out how to provide personalized diagnostics if the desired action does not succeed. It could be as simple as

// in std/lib.rs
#[cfg(not(supported_platform))]
compile_error!("libstd is not supported for $platform");

or whatever, with huge benefit of such approach being that the support for libstd remains entirely within confines of libstd without affecting the implementation of the compiler in an orthogonal way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. T-compiler Relevant to the compiler team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants