Emit warning while outputs is not exe and prints linkage info
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
@@ -68,6 +68,23 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_link_info_print_request(sess: &Session, crate_type: CrateType) {
|
||||
let print_native_static_libs =
|
||||
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
|
||||
if print_native_static_libs {
|
||||
if crate_type != CrateType::Staticlib {
|
||||
sess.dcx()
|
||||
.warn(format!("cannot output linkage information without staticlib crate-type"));
|
||||
sess.dcx()
|
||||
.note(format!("consider `--crate-type staticlib` to print linkage information"));
|
||||
} else if !sess.opts.output_types.should_link() {
|
||||
sess.dcx().warn(format!(
|
||||
"skipping link step due to conflict: cannot output linkage information without emitting link"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs the linkage portion of the compilation phase. This will generate all
|
||||
/// of the requested outputs for this compilation session.
|
||||
pub fn link_binary(
|
||||
@@ -178,6 +195,8 @@ pub fn link_binary(
|
||||
tempfiles_for_stdout_output.push(out_filename);
|
||||
}
|
||||
}
|
||||
|
||||
check_link_info_print_request(sess, crate_type);
|
||||
}
|
||||
|
||||
// Remove the temporary object file and metadata if we aren't saving temps.
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
//@ compile-flags: --print native-static-libs
|
||||
//@ check-pass
|
||||
//~? WARN cannot output linkage information without staticlib crate-type
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
warning: cannot output linkage information without staticlib crate-type
|
||||
|
||||
note: consider `--crate-type staticlib` to print linkage information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
//@ compile-flags: --print native-static-libs --crate-type staticlib --emit metadata
|
||||
//@ check-pass
|
||||
//~? WARN skipping link step due to conflict: cannot output linkage information without emitting link
|
||||
@@ -0,0 +1,4 @@
|
||||
warning: skipping link step due to conflict: cannot output linkage information without emitting link
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
@@ -110,3 +110,4 @@ fn main() {}
|
||||
//[check_cfg]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `check-cfg` print option
|
||||
//[supported_crate_types]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `supported-crate-types` print option
|
||||
//[target_spec_json]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `target-spec-json` print option
|
||||
//[native_static_libs]~? WARNING cannot output linkage information without staticlib crate-type
|
||||
|
||||
Reference in New Issue
Block a user