Rollup merge of #138641 - jieyouxu:print-supported-crate-types, r=Urgau
Add unstable `--print=supported-crate-types` option MCP: https://github.com/rust-lang/compiler-team/issues/836 Tracking issue: https://github.com/rust-lang/rust/issues/138640 ### Test coverage Two tests: 1. `tests/ui/print-request/stability.rs` to check that `--print=supported-crate-types` is `-Zunstable-options`-gated 2. `tests/ui/print-request/supported-crate-types.rs` is added as a basic smoke test. Observe that the compiler stdout corresponds to the below *Example output* section (e.g. `proc-macro` is unsupported on `wasm32-unknown-unknown` currently). ### Example output <details> <summary>For `x86_64-unknown-linux-gnu`</summary> Notice the presence of `{c,}dylib` and `proc-macro`: ``` bin cdylib dylib lib proc-macro rlib staticlib ``` </details> <details> <summary>For `wasm32-unknown-unknown`</summary> Notice the absence of `dylib` and `proc-macro`: ``` bin cdylib lib rlib staticlib ``` </details> <details> <summary>For `x86_64-unknown-linux-musl`</summary> Notice the absence of `{c,}dylib` but presence of `proc-macro`: ``` bin lib proc-macro rlib staticlib ``` </details> ### Documentation I added an entry in the unstable book's print request section to document this `supported-crate-types` print request. ### Unresolved questions - [ ] (Name bikeshedding) is `supported-crate-types` a good name for the print request? I'm inclined to say it's good enough for an unstable print request, but may be worth revisiting at stabilization time. ### Stability This print request being added is *unstable* in this PR. A separate stabilization PR following the usual compiler flag stabilization procedure should be filed for stabilization after some baking time. ### Review remarks Best reviewed commit-by-commit. r? compiler
This commit is contained in:
commit
21cdebcf4e
15 changed files with 98 additions and 10 deletions
|
@ -20,7 +20,7 @@
|
|||
// tidy-alphabetical-end
|
||||
|
||||
use std::cmp::max;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::ffi::OsString;
|
||||
use std::fmt::Write as _;
|
||||
use std::fs::{self, File};
|
||||
|
@ -61,7 +61,7 @@ use rustc_session::config::{
|
|||
};
|
||||
use rustc_session::getopts::{self, Matches};
|
||||
use rustc_session::lint::{Lint, LintId};
|
||||
use rustc_session::output::collect_crate_types;
|
||||
use rustc_session::output::{CRATE_TYPES, collect_crate_types, invalid_output_for_target};
|
||||
use rustc_session::{EarlyDiagCtxt, Session, config, filesearch};
|
||||
use rustc_span::FileName;
|
||||
use rustc_target::json::ToJson;
|
||||
|
@ -790,6 +790,16 @@ fn print_crate_info(
|
|||
sess.dcx().fatal("only Apple targets currently support deployment version info")
|
||||
}
|
||||
}
|
||||
SupportedCrateTypes => {
|
||||
let supported_crate_types = CRATE_TYPES
|
||||
.iter()
|
||||
.filter(|(_, crate_type)| !invalid_output_for_target(&sess, *crate_type))
|
||||
.map(|(crate_type_sym, _)| *crate_type_sym)
|
||||
.collect::<BTreeSet<_>>();
|
||||
for supported_crate_type in supported_crate_types {
|
||||
println_info!("{}", supported_crate_type.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
req.out.overwrite(&crate_info, sess);
|
||||
|
|
|
@ -58,6 +58,7 @@ pub const PRINT_KINDS: &[(&str, PrintKind)] = &[
|
|||
("relocation-models", PrintKind::RelocationModels),
|
||||
("split-debuginfo", PrintKind::SplitDebuginfo),
|
||||
("stack-protector-strategies", PrintKind::StackProtectorStrategies),
|
||||
("supported-crate-types", PrintKind::SupportedCrateTypes),
|
||||
("sysroot", PrintKind::Sysroot),
|
||||
("target-cpus", PrintKind::TargetCPUs),
|
||||
("target-features", PrintKind::TargetFeatures),
|
||||
|
@ -888,6 +889,7 @@ pub enum PrintKind {
|
|||
RelocationModels,
|
||||
SplitDebuginfo,
|
||||
StackProtectorStrategies,
|
||||
SupportedCrateTypes,
|
||||
Sysroot,
|
||||
TargetCPUs,
|
||||
TargetFeatures,
|
||||
|
@ -2063,7 +2065,10 @@ fn check_print_request_stability(
|
|||
(print_name, print_kind): (&str, PrintKind),
|
||||
) {
|
||||
match print_kind {
|
||||
PrintKind::AllTargetSpecsJson | PrintKind::CheckCfg | PrintKind::TargetSpecJson
|
||||
PrintKind::AllTargetSpecsJson
|
||||
| PrintKind::CheckCfg
|
||||
| PrintKind::SupportedCrateTypes
|
||||
| PrintKind::TargetSpecJson
|
||||
if !unstable_opts.unstable_options =>
|
||||
{
|
||||
early_dcx.early_fatal(format!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue