Add --print=supported-crate-types
#836
Labels
final-comment-period
The FCP has started, most (if not all) team members are in agreement
major-change
A proposal to make a major change to rustc
T-compiler
Add this label so rfcbot knows to poll the compiler team
Proposal
Summary
Add an unstable
--print=supported-crate-types
rustc flag which outputs a newline-delimited list of crate types that are supported by a given target:Alternative json format
Alternatively, we could also introduce an unstable
--print-json=supported-crate-types
which outputs a line of JSON that's more friendly for tooling instead of newline-delimited plain text.Primary motivation
compiletest relies on
--print=all-target-specs-json
and--print=cfg
to collect target info for its various{ignore,only,needs}
directives. However, what crate types are supported by a given target is not contained within these two--print
flags, and trying to maintain such supported crate types list separately in compiletest is fragile and easily becomes outdated.Aside: using
--print=supported-crate-types
to add a//@ needs-crate-types: ...
directiveCurrently, test writers have to manually maintain
ignore-$target
s to skip targets.dylib
being unsupported by default on wasm targets.ignore-musl
is very easy to forget to update.See compiletest: add a proper
supports-crate-type: xxx
directive #132309.Example test that would benefit from a dedicated
supports-crate-type
directive versus manually maintaining a list of targetignore-*
s: rust-lang/rust#134906.Third-party tools like
cargo-semver-checks
may also benefit from being able to obtain this information directly.Secondary motivation
cargo currently does target supported crate types detection by trying to build a
$crate_type
for the target, then read the unsupported crate type warning:See rust-lang/cargo#15036, which works around rust-lang/rust#116626.
Note that cargo may or may not benefit from
--print=supported-crate-types
even if this flag is added due to the cost of an extra rustc invocation.Stability guarantees of the flag and its output
Note that this proposal is to add
--print=supported-crate-types
or--print-json=supported-crate-types
as an unstable flag guarded behind-Zunstable-options
. Proposing this for stabilization should go through the usual process. This section tries to describe what kind of stability (or explicit lack thereof) we may consider for the form and output of this flag when and if it comes to stabilizing this--print
/--print-json
option:What would be stable:
rustc --print=supported-crate-types
or--print-json=supported-crate-types
What would be perma-unstable:
Prior discussions
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Proposal.3A.20.60--print.3Dsupported-crate-types.60
Mentors or Reviewers
N/A, I plan to implement this myself, standard compiler reviews apply.
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: