Skip to content

Commit

Permalink
Show files produced by --emit foo in json artifact notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
pacak committed Mar 21, 2024
1 parent 8e1527f commit 973a0fb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
17 changes: 16 additions & 1 deletion compiler/rustc_codegen_gcc/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub(crate) unsafe fn codegen(
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
context.add_command_line_option("-flto=auto");
context.add_command_line_option("-flto-partition=one");
if config.json_artifact_notifications {
dcx.emit_artifact_notification(&bc_out, "llvm-bc");
}
context
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
}
Expand All @@ -70,6 +73,9 @@ pub(crate) unsafe fn codegen(
context.add_command_line_option("-flto=auto");
context.add_command_line_option("-flto-partition=one");
context.add_command_line_option("-ffat-lto-objects");
if config.json_artifact_notifications {
dcx.emit_artifact_notification(&bc_out, "llvm-bc");
}
// 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).
context
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
Expand All @@ -78,14 +84,20 @@ pub(crate) unsafe fn codegen(

if config.emit_ir {
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
std::fs::write(out, "").expect("write file");
std::fs::write(&out, "").expect("write file");
if config.json_artifact_notifications {
dcx.emit_artifact_notification(&out, "llvm-ir");
}
}

if config.emit_asm {
let _timer =
cgcx.prof.generic_activity_with_arg("GCC_module_codegen_emit_asm", &*module.name);
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
context.compile_to_file(OutputKind::Assembler, path.to_str().expect("path to str"));
if config.json_artifact_notifications {
dcx.emit_artifact_notification(&path, "asm");
}
}

match config.emit_obj {
Expand Down Expand Up @@ -113,6 +125,9 @@ pub(crate) unsafe fn codegen(
context.set_debug_info(true);
context.dump_to_file(path, true);
}
if config.json_artifact_notifications {
dcx.emit_artifact_notification(&obj_out, "obj");
}
if should_combine_object_files && fat_lto {
context.add_command_line_option("-flto=auto");
context.add_command_line_option("-flto-partition=one");
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ pub(crate) unsafe fn codegen(
.generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name);
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
}
if config.json_artifact_notifications && config.emit_bc {
dcx.emit_artifact_notification(&bc_out, "llvm-bc");
}
}

if config.emit_ir {
Expand Down Expand Up @@ -781,6 +784,10 @@ pub(crate) unsafe fn codegen(
}

result.into_result().map_err(|()| llvm_err(dcx, LlvmError::WriteIr { path: &out }))?;

if config.json_artifact_notifications {
dcx.emit_artifact_notification(&out, "llvm-ir");
}
}

if config.emit_asm {
Expand Down Expand Up @@ -809,6 +816,10 @@ pub(crate) unsafe fn codegen(
&cgcx.prof,
)
})?;

if config.json_artifact_notifications {
dcx.emit_artifact_notification(&path, "asm");
}
}

match config.emit_obj {
Expand Down Expand Up @@ -844,6 +855,10 @@ pub(crate) unsafe fn codegen(
&cgcx.prof,
)
})?;

if config.json_artifact_notifications {
dcx.emit_artifact_notification(&obj_out, "obj");
}
}

EmitObj::Bitcode => {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct ModuleConfig {
pub emit_asm: bool,
pub emit_obj: EmitObj,
pub emit_thin_lto: bool,
pub json_artifact_notifications: bool,
pub bc_cmdline: String,

// Miscellaneous flags. These are mostly copied from command-line
Expand Down Expand Up @@ -276,6 +277,7 @@ impl ModuleConfig {
inline_threshold: sess.opts.cg.inline_threshold,
emit_lifetime_markers: sess.emit_lifetime_markers(),
llvm_plugins: if_regular!(sess.opts.unstable_opts.llvm_plugins.clone(), vec![]),
json_artifact_notifications: sess.opts.json_artifact_notifications,
}
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_mir_transform/src/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
}
OutFileName::Real(path) => {
let mut f = io::BufWriter::new(File::create(&path)?);
if tcx.sess.opts.json_artifact_notifications {
tcx.dcx().emit_artifact_notification(&path, "mir");
}
write_mir_pretty(tcx, None, &mut f)?;
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/doc/rustc/src/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ Diagnostics have the following format:
Artifact notifications are emitted when the [`--json=artifacts`
flag][option-json] is used. They indicate that a file artifact has been saved
to disk. More information about emit kinds may be found in the [`--emit`
flag][option-emit] documentation.
flag][option-emit] documentation. Notifications can contain more than one file
for each type, for example when using multiple codegen units.

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

0 comments on commit 973a0fb

Please sign in to comment.