Implement supported-crate-types
print request
As an unstable print request.
This commit is contained in:
parent
60a3084f64
commit
0e7dbab1fc
7 changed files with 59 additions and 3 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!(
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
//@[check_cfg] compile-flags: --print=check-cfg
|
||||
//@[check_cfg] error-pattern: the `-Z unstable-options` flag must also be passed
|
||||
|
||||
//@ revisions: supported_crate_types
|
||||
//@[supported_crate_types] compile-flags: --print=supported-crate-types
|
||||
//@[supported_crate_types] error-pattern: the `-Z unstable-options` flag must also be passed
|
||||
|
||||
//@ revisions: target_spec_json
|
||||
//@[target_spec_json] compile-flags: --print=target-spec-json
|
||||
//@[target_spec_json] error-pattern: the `-Z unstable-options` flag must also be passed
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
bin
|
||||
cdylib
|
||||
dylib
|
||||
lib
|
||||
proc-macro
|
||||
rlib
|
||||
staticlib
|
5
tests/ui/print-request/supported-crate-types.musl.stdout
Normal file
5
tests/ui/print-request/supported-crate-types.musl.stdout
Normal file
|
@ -0,0 +1,5 @@
|
|||
bin
|
||||
lib
|
||||
proc-macro
|
||||
rlib
|
||||
staticlib
|
20
tests/ui/print-request/supported-crate-types.rs
Normal file
20
tests/ui/print-request/supported-crate-types.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
//! Basic smoke test for `--print=supported-crate-types`, which should print a newline delimited
|
||||
//! list of crate types supported by the given target. This test cherry-picks a few well-known
|
||||
//! targets as examples.
|
||||
//!
|
||||
//! Tracking issue: <https://github.com/rust-lang/rust/issues/138640>
|
||||
|
||||
// ignore-tidy-linelength
|
||||
|
||||
//@ check-pass
|
||||
|
||||
//@ revisions: wasm musl linux
|
||||
|
||||
//@[wasm] compile-flags: --target=wasm32-unknown-unknown --print=supported-crate-types -Zunstable-options
|
||||
//@[wasm] needs-llvm-components: webassembly
|
||||
|
||||
//@[musl] compile-flags: --target=x86_64-unknown-linux-musl --print=supported-crate-types -Zunstable-options
|
||||
//@[musl] needs-llvm-components: x86
|
||||
|
||||
//@[linux] compile-flags: --target=x86_64-unknown-linux-gnu --print=supported-crate-types -Zunstable-options
|
||||
//@[linux] needs-llvm-components: x86
|
5
tests/ui/print-request/supported-crate-types.wasm.stdout
Normal file
5
tests/ui/print-request/supported-crate-types.wasm.stdout
Normal file
|
@ -0,0 +1,5 @@
|
|||
bin
|
||||
cdylib
|
||||
lib
|
||||
rlib
|
||||
staticlib
|
Loading…
Add table
Add a link
Reference in a new issue