Skip to content

Commit f53fcc6

Browse files
committed
Save more items into incremental cache
Without it compiler skips codengen stage and generating those intermediate byproducts and then fails when it comes to copying them to stable locations: export RUSTFLAGS=--emit=asm cargo new --lib foo && cd foo cargo build touch src/lib.rs cargo build
1 parent a3cfa03 commit f53fcc6

File tree

8 files changed

+106
-4
lines changed

8 files changed

+106
-4
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ fn emit_cgu(
341341
object: Some(global_asm_object_file),
342342
dwarf_object: None,
343343
bytecode: None,
344+
asm: None,
345+
llvm: None,
344346
}),
345347
existing_work_product: None,
346348
})
@@ -378,7 +380,15 @@ fn emit_module(
378380

379381
prof.artifact_size("object_file", &*name, file.metadata().unwrap().len());
380382

381-
Ok(CompiledModule { name, kind, object: Some(tmp_file), dwarf_object: None, bytecode: None })
383+
Ok(CompiledModule {
384+
name,
385+
kind,
386+
object: Some(tmp_file),
387+
dwarf_object: None,
388+
bytecode: None,
389+
asm: None,
390+
llvm: None,
391+
})
382392
}
383393

384394
fn reuse_workproduct_for_cgu(
@@ -426,13 +436,17 @@ fn reuse_workproduct_for_cgu(
426436
object: Some(obj_out_regular),
427437
dwarf_object: None,
428438
bytecode: None,
439+
asm: None,
440+
llvm: None,
429441
},
430442
module_global_asm: has_global_asm.then(|| CompiledModule {
431443
name: cgu.name().to_string(),
432444
kind: ModuleKind::Regular,
433445
object: Some(obj_out_global_asm),
434446
dwarf_object: None,
435447
bytecode: None,
448+
asm: None,
449+
llvm: None,
436450
}),
437451
existing_work_product: Some((cgu.work_product_id(), work_product)),
438452
})
@@ -678,6 +692,8 @@ pub(crate) fn run_aot(
678692
object: Some(tmp_file),
679693
dwarf_object: None,
680694
bytecode: None,
695+
asm: None,
696+
llvm: None,
681697
})
682698
} else {
683699
None

compiler/rustc_codegen_gcc/src/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pub(crate) unsafe fn codegen(
158158
config.emit_obj != EmitObj::None,
159159
cgcx.target_can_use_split_dwarf && cgcx.split_debuginfo == SplitDebuginfo::Unpacked,
160160
config.emit_bc,
161+
config.emit_asm,
162+
config.emit_ir,
161163
&cgcx.output_filenames,
162164
))
163165
}

compiler/rustc_codegen_llvm/src/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ pub(crate) unsafe fn codegen(
880880
config.emit_obj != EmitObj::None,
881881
dwarf_object_emitted,
882882
config.emit_bc,
883+
config.emit_asm,
884+
config.emit_ir,
883885
&cgcx.output_filenames,
884886
))
885887
}

compiler/rustc_codegen_ssa/src/back/write.rs

+45-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,15 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
533533
if let Some(dwarf_object_file_path) = &module.dwarf_object {
534534
files.push(("dwo", dwarf_object_file_path.as_path()));
535535
}
536-
536+
if let Some(path) = &module.asm {
537+
files.push(("s", path.as_path()));
538+
}
539+
if let Some(path) = &module.llvm {
540+
files.push(("ll", path.as_path()));
541+
}
542+
if let Some(path) = &module.bytecode {
543+
files.push(("bc", path.as_path()));
544+
}
537545
if let Some((id, product)) =
538546
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, files.as_slice())
539547
{
@@ -937,12 +945,47 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
937945
load_from_incr_comp_dir(dwarf_obj_out, saved_dwarf_object_file)
938946
});
939947

948+
let asm = module_config
949+
.emit_asm
950+
.then(|| {
951+
module.source.saved_files.get("s").as_ref().and_then(|saved_asm_file| {
952+
let output_path =
953+
cgcx.output_filenames.temp_path(OutputType::Assembly, Some(&module.name));
954+
load_from_incr_comp_dir(output_path, &saved_asm_file)
955+
})
956+
})
957+
.flatten();
958+
959+
let llvm = module_config
960+
.emit_ir
961+
.then(|| {
962+
module.source.saved_files.get("ll").as_ref().and_then(|saved_ir_file| {
963+
let output_path =
964+
cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, Some(&module.name));
965+
load_from_incr_comp_dir(output_path, &saved_ir_file)
966+
})
967+
})
968+
.flatten();
969+
970+
let bytecode = module_config
971+
.emit_bc
972+
.then(|| {
973+
module.source.saved_files.get("bc").as_ref().and_then(|saved_bc_file| {
974+
let output_path =
975+
cgcx.output_filenames.temp_path(OutputType::Bitcode, Some(&module.name));
976+
load_from_incr_comp_dir(output_path, &saved_bc_file)
977+
})
978+
})
979+
.flatten();
980+
940981
WorkItemResult::Finished(CompiledModule {
941982
name: module.name,
942983
kind: ModuleKind::Regular,
943984
object,
944985
dwarf_object,
945-
bytecode: None,
986+
bytecode,
987+
asm,
988+
llvm,
946989
})
947990
}
948991

compiler/rustc_codegen_ssa/src/base.rs

+2
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
629629
object: Some(file_name),
630630
dwarf_object: None,
631631
bytecode: None,
632+
asm: None,
633+
llvm: None,
632634
}
633635
})
634636
});

compiler/rustc_codegen_ssa/src/lib.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,25 @@ impl<M> ModuleCodegen<M> {
7979
emit_obj: bool,
8080
emit_dwarf_obj: bool,
8181
emit_bc: bool,
82+
emit_asm: bool,
83+
emit_ir: bool,
8284
outputs: &OutputFilenames,
8385
) -> CompiledModule {
8486
let object = emit_obj.then(|| outputs.temp_path(OutputType::Object, Some(&self.name)));
8587
let dwarf_object = emit_dwarf_obj.then(|| outputs.temp_path_dwo(Some(&self.name)));
8688
let bytecode = emit_bc.then(|| outputs.temp_path(OutputType::Bitcode, Some(&self.name)));
89+
let asm = emit_asm.then(|| outputs.temp_path(OutputType::Assembly, Some(&self.name)));
90+
let llvm = emit_ir.then(|| outputs.temp_path(OutputType::LlvmAssembly, Some(&self.name)));
8791

88-
CompiledModule { name: self.name.clone(), kind: self.kind, object, dwarf_object, bytecode }
92+
CompiledModule {
93+
name: self.name.clone(),
94+
kind: self.kind,
95+
object,
96+
dwarf_object,
97+
bytecode,
98+
asm,
99+
llvm,
100+
}
89101
}
90102
}
91103

@@ -96,6 +108,10 @@ pub struct CompiledModule {
96108
pub object: Option<PathBuf>,
97109
pub dwarf_object: Option<PathBuf>,
98110
pub bytecode: Option<PathBuf>,
111+
112+
/// items created to satisfy --emit
113+
pub asm: Option<PathBuf>, // --emit=asm
114+
pub llvm: Option<PathBuf>, // --emit=llvm-ir, llvm-bc is in bytecode
99115
}
100116

101117
pub struct CachedModuleCodegen {
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include ../tools.mk
2+
3+
# ignore-windows
4+
# ignore-freebsd
5+
# FIXME: on windows `rustc --dep-info` produces Makefile dependency with
6+
# windows native paths (e.g. `c:\path\to\libfoo.a`)
7+
# but msys make seems to fail to recognize such paths, so test fails.
8+
9+
all:
10+
cp *.rs $(TMPDIR)
11+
$(RUSTC) --emit obj,asm,dep-info,link --crate-type=lib $(TMPDIR)/lib.rs -C incremental=$(TMPDIR)/inc
12+
sleep 2
13+
touch $(TMPDIR)/lib.rs
14+
# this should compile as usual
15+
$(RUSTC) --emit obj,asm,dep-info,link --crate-type=lib $(TMPDIR)/lib.rs -C incremental=$(TMPDIR)/inc

tests/run-make/asm-incr-cache/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_name = "foo"]
2+
3+
#[inline(never)]
4+
pub fn add(a: u32, b: u32) -> u32 {
5+
a + b
6+
}

0 commit comments

Comments
 (0)