Skip to content

Commit be961b0

Browse files
committed
Auto merge of rust-lang#122597 - pacak:master, r=bjorn3
Show files produced by `--emit foo` in json artifact notifications Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`. Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477 Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35 This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files. Most users won't notice this behavior, to be affected by it all of the following must hold: - user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything) - user must specify both `--emit xxx` and `--json artifacts` - user must refuse to handle unknown artifact types - user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
2 parents db4dbc8 + 0a298ed commit be961b0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/driver/aot.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,29 @@ fn produce_final_output_artifacts(
288288
}
289289
}
290290

291+
if sess.opts.json_artifact_notifications {
292+
if codegen_results.modules.len() == 1 {
293+
codegen_results.modules[0].for_each_output(|_path, ty| {
294+
if sess.opts.output_types.contains_key(&ty) {
295+
let descr = ty.shorthand();
296+
// for single cgu file is renamed to drop cgu specific suffix
297+
// so we regenerate it the same way
298+
let path = crate_output.path(ty);
299+
sess.dcx().emit_artifact_notification(path.as_path(), descr);
300+
}
301+
});
302+
} else {
303+
for module in &codegen_results.modules {
304+
module.for_each_output(|path, ty| {
305+
if sess.opts.output_types.contains_key(&ty) {
306+
let descr = ty.shorthand();
307+
sess.dcx().emit_artifact_notification(&path, descr);
308+
}
309+
});
310+
}
311+
}
312+
}
313+
291314
// We leave the following files around by default:
292315
// - #crate#.o
293316
// - #crate#.crate.metadata.o

0 commit comments

Comments
 (0)