Skip to content

Commit 20d83e5

Browse files
committed
Show files produced by --emit foo in json artifact notifications
1 parent 8e1527f commit 20d83e5

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

compiler/rustc_codegen_gcc/src/back/write.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub(crate) unsafe fn codegen(
5656
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
5757
context.add_command_line_option("-flto=auto");
5858
context.add_command_line_option("-flto-partition=one");
59+
if config.json_artifact_notifications {
60+
dcx.emit_artifact_notification(&bc_out, "llvm_bc");
61+
}
5962
context
6063
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
6164
}
@@ -70,6 +73,9 @@ pub(crate) unsafe fn codegen(
7073
context.add_command_line_option("-flto=auto");
7174
context.add_command_line_option("-flto-partition=one");
7275
context.add_command_line_option("-ffat-lto-objects");
76+
if config.json_artifact_notifications {
77+
dcx.emit_artifact_notification(&bc_out, "llvm_bc");
78+
}
7379
// TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
7480
context
7581
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
@@ -78,14 +84,20 @@ pub(crate) unsafe fn codegen(
7884

7985
if config.emit_ir {
8086
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
81-
std::fs::write(out, "").expect("write file");
87+
std::fs::write(&out, "").expect("write file");
88+
if config.json_artifact_notifications {
89+
dcx.emit_artifact_notification(&out, "llvm_ir");
90+
}
8291
}
8392

8493
if config.emit_asm {
8594
let _timer =
8695
cgcx.prof.generic_activity_with_arg("GCC_module_codegen_emit_asm", &*module.name);
8796
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
8897
context.compile_to_file(OutputKind::Assembler, path.to_str().expect("path to str"));
98+
if config.json_artifact_notifications {
99+
dcx.emit_artifact_notification(&path, "asm");
100+
}
89101
}
90102

91103
match config.emit_obj {
@@ -113,6 +125,9 @@ pub(crate) unsafe fn codegen(
113125
context.set_debug_info(true);
114126
context.dump_to_file(path, true);
115127
}
128+
if config.json_artifact_notifications {
129+
dcx.emit_artifact_notification(&obj_out, "obj");
130+
}
116131
if should_combine_object_files && fat_lto {
117132
context.add_command_line_option("-flto=auto");
118133
context.add_command_line_option("-flto-partition=one");

compiler/rustc_codegen_llvm/src/back/write.rs

+15
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ pub(crate) unsafe fn codegen(
740740
.generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name);
741741
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
742742
}
743+
if config.json_artifact_notifications && config.emit_bc {
744+
dcx.emit_artifact_notification(&bc_out, "llvm-bc");
745+
}
743746
}
744747

745748
if config.emit_ir {
@@ -781,6 +784,10 @@ pub(crate) unsafe fn codegen(
781784
}
782785

783786
result.into_result().map_err(|()| llvm_err(dcx, LlvmError::WriteIr { path: &out }))?;
787+
788+
if config.json_artifact_notifications {
789+
dcx.emit_artifact_notification(&out, "llvm-ir");
790+
}
784791
}
785792

786793
if config.emit_asm {
@@ -809,6 +816,10 @@ pub(crate) unsafe fn codegen(
809816
&cgcx.prof,
810817
)
811818
})?;
819+
820+
if config.json_artifact_notifications {
821+
dcx.emit_artifact_notification(&path, "asm");
822+
}
812823
}
813824

814825
match config.emit_obj {
@@ -844,6 +855,10 @@ pub(crate) unsafe fn codegen(
844855
&cgcx.prof,
845856
)
846857
})?;
858+
859+
if config.json_artifact_notifications {
860+
dcx.emit_artifact_notification(&obj_out, "obj");
861+
}
847862
}
848863

849864
EmitObj::Bitcode => {

compiler/rustc_codegen_ssa/src/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub struct ModuleConfig {
106106
pub emit_asm: bool,
107107
pub emit_obj: EmitObj,
108108
pub emit_thin_lto: bool,
109+
pub json_artifact_notifications: bool,
109110
pub bc_cmdline: String,
110111

111112
// Miscellaneous flags. These are mostly copied from command-line
@@ -276,6 +277,7 @@ impl ModuleConfig {
276277
inline_threshold: sess.opts.cg.inline_threshold,
277278
emit_lifetime_markers: sess.emit_lifetime_markers(),
278279
llvm_plugins: if_regular!(sess.opts.unstable_opts.llvm_plugins.clone(), vec![]),
280+
json_artifact_notifications: sess.opts.json_artifact_notifications,
279281
}
280282
}
281283

compiler/rustc_mir_transform/src/dump_mir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
2727
}
2828
OutFileName::Real(path) => {
2929
let mut f = io::BufWriter::new(File::create(&path)?);
30+
if tcx.sess.opts.json_artifact_notifications {
31+
tcx.dcx().emit_artifact_notification(&path, "mir");
32+
}
3033
write_mir_pretty(tcx, None, &mut f)?;
3134
}
3235
}

src/doc/rustc/src/json.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ Diagnostics have the following format:
217217
Artifact notifications are emitted when the [`--json=artifacts`
218218
flag][option-json] is used. They indicate that a file artifact has been saved
219219
to disk. More information about emit kinds may be found in the [`--emit`
220-
flag][option-emit] documentation.
220+
flag][option-emit] documentation. Notifications can contain more than one file
221+
for each type, for example when using multiple codegen units.
221222

222223
```javascript
223224
{
@@ -229,6 +230,12 @@ flag][option-emit] documentation.
229230
- "link": The generated crate as specified by the crate-type.
230231
- "dep-info": The `.d` file with dependency information in a Makefile-like syntax.
231232
- "metadata": The Rust `.rmeta` file containing metadata about the crate.
233+
- "asm": The `.s` file with generated assembly
234+
- "llvm-ir": The `.ll` file with generated textual LLVM IR
235+
- "llvm-bc": The `.bc` file with generated LLVM bitcode
236+
- "mir": The `.mir` file with rustc's mid-level intermediate representation.
237+
- "obj": The `.o` file with generated native object code
238+
232239
*/
233240
"emit": "link"
234241
}

0 commit comments

Comments
 (0)