Description
Summary
Original issue: #8923
Implementation: #9002
cargo rustc --print=VAL
forwards the --print
flag to rustc
in order to extract information from rustc
. This runs rustc
with the corresponding --print
flag, and then immediately exits without compiling. Exposing this as a cargo flag allows cargo to inject the correct target and RUSTFLAGS based on the current configuration.
The primary use case is to run cargo rustc --print=cfg
to get config values for the appropriate target and influenced by any other RUSTFLAGS.
Unresolved issues
(These aren't necessarily blockers, just random thoughts about the current design.)
- I think
cfg
is the only value that is worth printing. It is not clear from a UI perspective if it makes sense to expose the other values, since several will just fail or don't add anything different than runningrustc
directly. Forwarding the print value to rustc is more flexible and probably fine, though it seems like it could cause confusion. - The intended use case of
--print=cfg
means anyone using it needs to implement a parser for the ad-hoc format. The original implementation parsed it and returned JSON, which might be easier to consume? There was some back-and-forth discussion on the PR about this, and possibly using a more general purpose subcommand (likecargo config
) for "expose internal information". It might be worth considering that more. - The behavior with multiple
--target
flags is a little strange. - Profiles are ignored. This has historically caused confusion for people (for things like
debug_assertions
). However, all of cargo ignores profiles for the intended use case (--print=cfg
). It's not clear what this should do.
Future extensions
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status