Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ fn list_metadata(sess: &Session, metadata_loader: &dyn MetadataLoader) {
}
}

fn print_crate_info(
pub fn print_crate_info(
codegen_backend: &dyn CodegenBackend,
sess: &Session,
parse_attrs: bool,
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tracing::debug;

pub use crate::config::cfg::{Cfg, CheckCfg, ExpectedValues};
use crate::config::native_libs::parse_native_libs;
pub use crate::config::print_request::{PrintKind, PrintRequest};
pub use crate::config::print_request::{PrintKind, PrintRequest, collect_print_requests};
use crate::errors::FileWriteFail;
pub use crate::options::*;
use crate::search_paths::SearchPath;
Expand Down Expand Up @@ -1364,16 +1364,15 @@ impl Sysroot {
}
}

/// Get the host triple out of the build environment. This ensures that our
/// idea of the host triple is the same as for the set of libraries we've
/// actually built. We can't just take LLVM's host triple because they
/// normalize all ix86 architectures to i386.
pub fn host_tuple() -> &'static str {
// Get the host triple out of the build environment. This ensures that our
// idea of the host triple is the same as for the set of libraries we've
// actually built. We can't just take LLVM's host triple because they
// normalize all ix86 architectures to i386.
//
// Instead of grabbing the host triple (for the current host), we grab (at
// compile time) the target triple that this rustc is built with and
// calling that (at runtime) the host triple.
(option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE")
env!("CFG_COMPILER_HOST_TRIPLE")
Comment on lines -1376 to +1375
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was changed from env! to option_env! in the first commit of #13724, but not sure why this change was made or if it's still relevant as CI is green.

(Was looking looking for a #[expect] reason as removing the extra parentheses triggers deny-by-default clippy::option_env_unwrap)

}

fn file_path_mapping(
Expand Down
50 changes: 49 additions & 1 deletion compiler/rustc_session/src/config/print_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,78 @@ pub struct PrintRequest {
#[derive(AllVariants)]
pub enum PrintKind {
// tidy-alphabetical-start
/// All target specs.
AllTargetSpecsJson,

/// Does the backend supports Zstd compression? (perma-unstable)
BackendHasZstd,

/// List of supported calling conventions.
CallingConventions,

/// List of cfg values (1st flavour).
Cfg,

/// List of cfg values (2nd flavour).
CheckCfg,

/// List of available code models for the current backend.
CodeModels,

/// Name of the crate being compiled.
CrateName,

CrateRootLintLevels,

/// The current selected deployment target (Apple platforms).
DeploymentTarget,

/// THe names of the files created by the `link` `--emit` kind.
FileNames,

/// Target-tuple of the host compiler.
HostTuple,

/// Linker invocations.
LinkArgs,

/// When compiling a `staticlib` crate, print the linker flags used.
NativeStaticLibs,

/// List of available relocation models for the current backend.
RelocationModels,

/// List of available split debuginfos for the current target.
SplitDebuginfo,

/// List of available stack protector strategies for the current backend.
StackProtectorStrategies,

/// List of available crate types for the current target.
SupportedCrateTypes,

/// Path to the sysroot.
Sysroot,

/// List of available CPU values for the current target.
TargetCPUs,

/// List of available target features for the current target.
TargetFeatures,

/// Path to the target libdir.
TargetLibdir,

/// List of supported targets.
TargetList,

/// Current target spec.
TargetSpecJson,

/// Target spec schema.
TargetSpecJsonSchema,

/// List of available TLS models for the current backend.
TlsModels,
// tidy-alphabetical-end
}
Expand Down Expand Up @@ -142,7 +190,7 @@ pub(crate) static PRINT_HELP: LazyLock<String> = LazyLock::new(|| {
)
});

pub(crate) fn collect_print_requests(
pub fn collect_print_requests(
early_dcx: &EarlyDiagCtxt,
cg: &mut CodegenOptions,
unstable_opts: &UnstableOptions,
Expand Down
46 changes: 43 additions & 3 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::DiagCtxtHandle;
use rustc_session::config::{
self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns,
OptionsTargetModifiers, OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options,
nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple,
OptionsTargetModifiers, OutFileName, PrintKind, PrintRequest, Sysroot, UnstableOptions,
collect_print_requests, get_cmd_lint_options, nightly_options, parse_crate_types_from_list,
parse_externs, parse_target_triple,
};
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
Expand Down Expand Up @@ -119,6 +120,8 @@ pub(crate) struct Options {
pub(crate) describe_lints: bool,
/// What level to cap lints at.
pub(crate) lint_cap: Option<Level>,
/// Print requests to hand to the compiler.
pub(crate) prints: Vec<PrintRequest>,

// Options specific to running doctests
/// Whether we should run doctests instead of generating docs.
Expand Down Expand Up @@ -210,6 +213,7 @@ impl fmt::Debug for Options {
.field("lint_opts", &self.lint_opts)
.field("describe_lints", &self.describe_lints)
.field("lint_cap", &self.lint_cap)
.field("prints", &self.prints)
.field("should_test", &self.should_test)
.field("test_args", &self.test_args)
.field("test_run_directory", &self.test_run_directory)
Expand Down Expand Up @@ -410,7 +414,7 @@ impl Options {
let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default();

let mut target_modifiers = BTreeMap::<OptionsTargetModifiers, String>::new();
let codegen_options = CodegenOptions::build(early_dcx, matches, &mut target_modifiers);
let mut codegen_options = CodegenOptions::build(early_dcx, matches, &mut target_modifiers);
let unstable_opts = UnstableOptions::build(early_dcx, matches, &mut target_modifiers);

let remap_path_prefix = match parse_remap_path_prefix(matches) {
Expand Down Expand Up @@ -564,6 +568,41 @@ impl Options {
}
};

let mut prints =
collect_print_requests(early_dcx, &mut codegen_options, &unstable_opts, matches);

{
use PrintKind::*;
prints.retain(|req| match req.kind {
// Compiler
TargetList
| AllTargetSpecsJson
| TargetSpecJson
| TargetSpecJsonSchema
| TargetCPUs
| TargetFeatures
| DeploymentTarget
| SupportedCrateTypes

// Codegen
| CallingConventions
| CodeModels
| SplitDebuginfo
| StackProtectorStrategies
| RelocationModels
| TlsModels
| BackendHasZstd

// Linker
| FileNames
| LinkArgs
| NativeStaticLibs
| TargetLibdir => false,

Cfg | CheckCfg | CrateName | CrateRootLintLevels | HostTuple | Sysroot => true,
});
}

let externs = parse_externs(early_dcx, matches, &unstable_opts);
let extern_html_root_urls = match parse_extern_html_roots(matches) {
Ok(ex) => ex,
Expand Down Expand Up @@ -853,6 +892,7 @@ impl Options {
lint_opts,
describe_lints,
lint_cap,
prints,
should_test,
test_args,
show_coverage,
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ pub(crate) fn create_config(
lint_opts,
describe_lints,
lint_cap,
prints,
scrape_examples_options,
remap_path_prefix,
target_modifiers,
Expand Down Expand Up @@ -269,6 +270,7 @@ pub(crate) fn create_config(
diagnostic_width,
edition,
describe_lints,
prints,
crate_name,
test,
remap_path_prefix,
Expand Down
14 changes: 14 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,14 @@ fn opts() -> Vec<RustcOptGroup> {
"Comma separated list of types of output for rustdoc to emit",
"[toolchain-shared-resources,invocation-specific,dep-info]",
),
opt(
Unstable,
Multi,
"",
"print",
"Rustdoc information to print on stdout (or to a file)",
"<INFO>[=<FILE>]",
),
opt(Unstable, FlagMulti, "", "no-run", "Compile doctests without running them", ""),
opt(
Unstable,
Expand Down Expand Up @@ -885,6 +893,12 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
return;
}

if rustc_driver::print_crate_info(&*compiler.codegen_backend, sess, true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: IINM, this won't be run if the input file is *.md or if --test is passed. Not sure what the consequences of that are.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, --print=crate-name doesn't really make sense for *.md inputs I feel like?

== rustc_driver::Compilation::Stop
{
return;
}

let krate = rustc_interface::passes::parse(sess);
rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| {
if sess.dcx().has_errors().is_some() {
Expand Down
2 changes: 2 additions & 0 deletions tests/run-make/rustdoc-default-output/output-default.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Options:
--emit [toolchain-shared-resources,invocation-specific,dep-info]
Comma separated list of types of output for rustdoc to
emit
--print <INFO>[=<FILE>]
Rustdoc information to print on stdout (or to a file)
--no-run Compile doctests without running them
--merge-doctests yes|no|auto
Force all doctests to be compiled as a single binary,
Expand Down
Loading