Rollup merge of #113780 - dtolnay:printkindpath, r=b-naber
Support `--print KIND=PATH` command line syntax As is already done for `--emit KIND=PATH` and `-L KIND=PATH`. In the discussion of #110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o` path to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`. I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](d43cf3a51a/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system. From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse".31eda6f7c3/src/cargo/core/compiler/build_context/target_info.rs (L242)(FYI `@weihanglo` as you dealt with this recently in https://github.com/rust-lang/cargo/pull/11633.) Mentioning reviewers active in #110785: `@fee1-dead` `@jyn514` `@bjorn3`
This commit is contained in:
@@ -12,8 +12,8 @@ use rustc_metadata::fs::{copy_to_stdout, emit_wrapper_file, METADATA_FILENAME};
|
||||
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
||||
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, Strip};
|
||||
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind};
|
||||
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, OutFileName, Strip};
|
||||
use rustc_session::config::{OutputFilenames, OutputType, PrintKind, SplitDwarfKind};
|
||||
use rustc_session::cstore::DllImport;
|
||||
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
|
||||
use rustc_session::search_paths::PathKind;
|
||||
@@ -596,8 +596,10 @@ fn link_staticlib<'a>(
|
||||
|
||||
all_native_libs.extend_from_slice(&codegen_results.crate_info.used_libraries);
|
||||
|
||||
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
|
||||
print_native_static_libs(sess, &all_native_libs, &all_rust_dylibs);
|
||||
for print in &sess.opts.prints {
|
||||
if print.kind == PrintKind::NativeStaticLibs {
|
||||
print_native_static_libs(sess, &print.out, &all_native_libs, &all_rust_dylibs);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -744,8 +746,11 @@ fn link_natively<'a>(
|
||||
cmd.env_remove(k.as_ref());
|
||||
}
|
||||
|
||||
if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
|
||||
println!("{:?}", &cmd);
|
||||
for print in &sess.opts.prints {
|
||||
if print.kind == PrintKind::LinkArgs {
|
||||
let content = format!("{:?}", cmd);
|
||||
print.out.overwrite(&content, sess);
|
||||
}
|
||||
}
|
||||
|
||||
// May have not found libraries in the right formats.
|
||||
@@ -1386,6 +1391,7 @@ enum RlibFlavor {
|
||||
|
||||
fn print_native_static_libs(
|
||||
sess: &Session,
|
||||
out: &OutFileName,
|
||||
all_native_libs: &[NativeLib],
|
||||
all_rust_dylibs: &[&Path],
|
||||
) {
|
||||
@@ -1459,11 +1465,22 @@ fn print_native_static_libs(
|
||||
lib_args.push(format!("-l{}", lib));
|
||||
}
|
||||
}
|
||||
if !lib_args.is_empty() {
|
||||
sess.emit_note(errors::StaticLibraryNativeArtifacts);
|
||||
// Prefix for greppability
|
||||
// Note: This must not be translated as tools are allowed to depend on this exact string.
|
||||
sess.note_without_error(format!("native-static-libs: {}", &lib_args.join(" ")));
|
||||
|
||||
match out {
|
||||
OutFileName::Real(path) => {
|
||||
out.overwrite(&lib_args.join(" "), sess);
|
||||
if !lib_args.is_empty() {
|
||||
sess.emit_note(errors::StaticLibraryNativeArtifactsToFile { path });
|
||||
}
|
||||
}
|
||||
OutFileName::Stdout => {
|
||||
if !lib_args.is_empty() {
|
||||
sess.emit_note(errors::StaticLibraryNativeArtifacts);
|
||||
// Prefix for greppability
|
||||
// Note: This must not be translated as tools are allowed to depend on this exact string.
|
||||
sess.note_without_error(format!("native-static-libs: {}", &lib_args.join(" ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user