rust-lang / rfcs

RFCs for changes to Rust
https://rust-lang.github.io/rfcs/
Apache License 2.0
5.96k stars 1.57k forks source link

Expose std support via --print #3693

Open adamgemmell opened 2 months ago

adamgemmell commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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.

petrochenkov commented 2 months ago

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

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 commented 2 months ago

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 commented 2 months ago

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 commented 1 month ago

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 commented 1 month ago

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

@rfcbot fcp merge

rfcbot commented 1 month ago

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.

nagisa commented 1 month ago

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.