Skip to content

Commit f9275e1

Browse files
committed
Skip linking if it is not required
This allows to use `--emit=metadata,obj` and other metadata + non-link combinations. Fixes #81117. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent fc9944f commit f9275e1

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
7474
}
7575
});
7676

77-
if outputs.outputs.should_codegen() {
77+
if outputs.outputs.should_link() {
7878
let tmpdir = TempFileBuilder::new()
7979
.prefix("rustc")
8080
.tempdir()
@@ -123,9 +123,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
123123
}
124124
};
125125

126-
if sess.opts.output_types.should_codegen()
127-
&& !preserve_objects_for_their_debuginfo(sess)
128-
{
126+
if sess.opts.output_types.should_link() && !preserve_objects_for_their_debuginfo(sess) {
129127
for module in &codegen_results.modules {
130128
remove_temps_from_module(module);
131129
}

compiler/rustc_session/src/config.rs

+14
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,20 @@ impl OutputTypes {
403403
OutputType::Metadata | OutputType::DepInfo => false,
404404
})
405405
}
406+
407+
// Returns `true` if any of the output types require linking.
408+
pub fn should_link(&self) -> bool {
409+
self.0.keys().any(|k| match *k {
410+
OutputType::Bitcode
411+
| OutputType::Assembly
412+
| OutputType::LlvmAssembly
413+
| OutputType::Mir
414+
| OutputType::Metadata
415+
| OutputType::Object
416+
| OutputType::DepInfo => false,
417+
OutputType::Exe => true,
418+
})
419+
}
406420
}
407421

408422
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.

src/test/ui/emit-metadata-obj.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags:--emit=metadata,obj
2+
// build-pass
3+
4+
// A test for the emission of metadata + obj and other metadata + non-link
5+
// combinations. See issue #81117.
6+
7+
fn main() {}

0 commit comments

Comments
 (0)