@@ -337,6 +337,8 @@ struct CodegenContext<'a> {
337337 remark : Passes ,
338338 // Worker thread number
339339 worker : usize ,
340+ // Directory where incremental data is stored (if any)
341+ incremental : Option < PathBuf > ,
340342}
341343
342344impl < ' a > CodegenContext < ' a > {
@@ -347,6 +349,7 @@ impl<'a> CodegenContext<'a> {
347349 plugin_passes : sess. plugin_llvm_passes . borrow ( ) . clone ( ) ,
348350 remark : sess. opts . cg . remark . clone ( ) ,
349351 worker : 0 ,
352+ incremental : sess. opts . incremental . clone ( ) ,
350353 }
351354 }
352355}
@@ -612,7 +615,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
612615
613616 if copy_bc_to_obj {
614617 debug ! ( "copying bitcode {:?} to obj {:?}" , bc_out, obj_out) ;
615- if let Err ( e) = fs :: copy ( & bc_out, & obj_out) {
618+ if let Err ( e) = link_or_copy ( & bc_out, & obj_out) {
616619 cgcx. handler . err ( & format ! ( "failed to copy bitcode to object file: {}" , e) ) ;
617620 }
618621 }
@@ -754,9 +757,19 @@ pub fn run_passes(sess: &Session,
754757
755758 // If in incr. comp. mode, preserve the `.o` files for potential re-use
756759 for mtrans in trans. modules . iter ( ) {
757- let path_to_obj = crate_output. temp_path ( OutputType :: Object , Some ( & mtrans. name ) ) ;
758- debug ! ( "wrote module {:?} to {:?}" , mtrans. name, path_to_obj) ;
759- save_trans_partition ( sess, & mtrans. name , mtrans. symbol_name_hash , & path_to_obj) ;
760+ let mut files = vec ! [ ] ;
761+
762+ if modules_config. emit_obj {
763+ let path = crate_output. temp_path ( OutputType :: Object , Some ( & mtrans. name ) ) ;
764+ files. push ( ( OutputType :: Object , path) ) ;
765+ }
766+
767+ if modules_config. emit_bc {
768+ let path = crate_output. temp_path ( OutputType :: Bitcode , Some ( & mtrans. name ) ) ;
769+ files. push ( ( OutputType :: Bitcode , path) ) ;
770+ }
771+
772+ save_trans_partition ( sess, & mtrans. name , mtrans. symbol_name_hash , & files) ;
760773 }
761774
762775 // All codegen is finished.
@@ -941,20 +954,24 @@ fn execute_work_item(cgcx: &CodegenContext,
941954 work_item. config ,
942955 work_item. output_names ) ;
943956 }
944- ModuleSource :: Preexisting ( ref buf) => {
945- let obj_out = work_item. output_names . temp_path ( OutputType :: Object ,
946- Some ( & work_item. mtrans . name ) ) ;
947- debug ! ( "copying pre-existing module `{}` from {} to {}" ,
948- work_item. mtrans. name,
949- buf. display( ) ,
950- obj_out. display( ) ) ;
951- match link_or_copy ( buf, & obj_out) {
952- Ok ( ( ) ) => { }
953- Err ( err) => {
954- cgcx. handler . err ( & format ! ( "unable to copy {} to {}: {}" ,
955- buf. display( ) ,
956- obj_out. display( ) ,
957- err) ) ;
957+ ModuleSource :: Preexisting ( wp) => {
958+ let incremental = cgcx. incremental . as_ref ( ) . unwrap ( ) ;
959+ let name = & work_item. mtrans . name ;
960+ for ( kind, saved_file) in wp. saved_files {
961+ let obj_out = work_item. output_names . temp_path ( kind, Some ( name) ) ;
962+ let source_file = incremental. join ( & saved_file) ;
963+ debug ! ( "copying pre-existing module `{}` from {:?} to {}" ,
964+ work_item. mtrans. name,
965+ source_file,
966+ obj_out. display( ) ) ;
967+ match link_or_copy ( & source_file, & obj_out) {
968+ Ok ( ( ) ) => { }
969+ Err ( err) => {
970+ cgcx. handler . err ( & format ! ( "unable to copy {} to {}: {}" ,
971+ source_file. display( ) ,
972+ obj_out. display( ) ,
973+ err) ) ;
974+ }
958975 }
959976 }
960977 }
@@ -994,6 +1011,8 @@ fn run_work_multithreaded(sess: &Session,
9941011 let mut tx = Some ( tx) ;
9951012 futures. push ( rx) ;
9961013
1014+ let incremental = sess. opts . incremental . clone ( ) ;
1015+
9971016 thread:: Builder :: new ( ) . name ( format ! ( "codegen-{}" , i) ) . spawn ( move || {
9981017 let diag_handler = Handler :: with_emitter ( true , false , box diag_emitter) ;
9991018
@@ -1005,6 +1024,7 @@ fn run_work_multithreaded(sess: &Session,
10051024 plugin_passes : plugin_passes,
10061025 remark : remark,
10071026 worker : i,
1027+ incremental : incremental,
10081028 } ;
10091029
10101030 loop {
0 commit comments