Skip to content

Commit 46d1647

Browse files
authored
Unrolled build for #138139
Rollup merge of #138139 - xizheyin:issue-137384, r=ChrisDenton Emit warning while outputs is not exe and prints linkage info cc #137384 ```bash $ rustc +stage1 /dev/null --print native-static-libs --crate-type staticlib --emit metadata warning: skipping link step due to conflict: cannot output linkage information without emitting executable note: consider emitting executable to print link information warning: 1 warning emitted ```
2 parents 5f025f3 + f66787a commit 46d1647

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
6868
}
6969
}
7070

71+
fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) {
72+
let print_native_static_libs =
73+
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
74+
let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib);
75+
if print_native_static_libs {
76+
if !has_staticlib {
77+
sess.dcx()
78+
.warn(format!("cannot output linkage information without staticlib crate-type"));
79+
sess.dcx()
80+
.note(format!("consider `--crate-type staticlib` to print linkage information"));
81+
} else if !sess.opts.output_types.should_link() {
82+
sess.dcx()
83+
.warn(format!("cannot output linkage information when --emit link is not passed"));
84+
}
85+
}
86+
}
87+
7188
/// Performs the linkage portion of the compilation phase. This will generate all
7289
/// of the requested outputs for this compilation session.
7390
pub fn link_binary(
@@ -180,6 +197,8 @@ pub fn link_binary(
180197
}
181198
}
182199

200+
check_link_info_print_request(sess, &codegen_results.crate_info.crate_types);
201+
183202
// Remove the temporary object file and metadata if we aren't saving temps.
184203
sess.time("link_binary_remove_temps", || {
185204
// If the user requests that temporaries are saved, don't delete any.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ compile-flags: --print native-static-libs
2+
//@ check-pass
3+
//~? WARN cannot output linkage information without staticlib crate-type
4+
5+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: cannot output linkage information without staticlib crate-type
2+
3+
note: consider `--crate-type staticlib` to print linkage information
4+
5+
warning: 1 warning emitted
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ compile-flags: --print native-static-libs --crate-type staticlib --emit metadata
2+
//@ check-pass
3+
//~? WARN cannot output linkage information when --emit link is not passed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
warning: cannot output linkage information when --emit link is not passed
2+
3+
warning: 1 warning emitted
4+

tests/ui/print-request/stability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ fn main() {}
110110
//[check_cfg]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `check-cfg` print option
111111
//[supported_crate_types]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `supported-crate-types` print option
112112
//[target_spec_json]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `target-spec-json` print option
113+
//[native_static_libs]~? WARNING cannot output linkage information without staticlib crate-type

0 commit comments

Comments
 (0)