-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Tracking Issue for cargo rustc --print=VAL
#9357
Comments
Thank you for creating this issue to track stabilization. I just wanted to briefly comment about a couple of the unresolved issues (not sure if I should be creating separate issues for each of these):
I have created the cargo-rustc-cfg crate so that others do not need to create a parser each time the output of the Please note, the release version (v0.2.0) was created and released prior to the existence of the
Could you expand on the strangeness of the behavior? Output for each specified |
Just that the blank line solution seems potentially brittle. It assumes the data will never have blank lines. Also, it may be difficult to correlate the output with the actual targets (let's say the targets are driven by a config file). Not big issues, and multiple targets is a very advanced use case, so it is unlikely to be used often. |
Thank you for explanation and see the issue with using the blank lines to delimit the output for multiple targets. There appears to be two issues at play: (1) delimiting the output and (2) associating output with targets. A As for (2) associating output with targets, it might be possible to enforce the order specified at the CLI to the order that is printed. Currently, I believe there is no guarantees on the output order nor order for the incoming multiple However, changing the output to a more structured format, such as JSON, resolves both issues with minimal changes to the CLI and implementation. The Do you foresee rolling this into |
FWIW if this was stable it would let cargo subcommands run This would allow cargo subcommands to properly introspect the current toolchain and start asking questions like "hey is this non-host target actually installed, or should I error/ask-rustup-to-install-it-first". ...which is a thing cargo-dist tries to do, but doesn't do Properly Enough. ofc that usecase could be addressed in a myriad of ways, but this is a good candidate solution that's generally useful. Alternatives would include:
|
I'm loosely aware the "is a target installed" is a... More Complicated question then I'm implying, and am very happy to be told I should Actually be asking a more precise question of my toolchain, so if you want to xy-problem me even harder what I really want is to make it easier for rust developers to be able to say "hey current rust toolchain, make sure you've done everything you can to make it possible to build arm64 macos from intel macos (or linux-musl-static from linux-gnu), and also please let me know if the build Obviously Won't Work". "Tell rustup to |
Summary
Original issue: #8923
Implementation: #9002
cargo rustc --print=VAL
forwards the--print
flag torustc
in order to extract information fromrustc
. This runsrustc
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.)
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.--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.--target
flags is a little strange.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.
The text was updated successfully, but these errors were encountered: