Fix a couple of preprocessed host bugs

This commit is contained in:
Richard Feldman 2022-11-22 23:34:31 -05:00
parent d9f3e11634
commit c0b065b51a
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 13 additions and 22 deletions

View file

@ -163,13 +163,8 @@ pub fn build_file<'a>(
}) })
.collect(); .collect();
let preprocessed_host_path = match linking_strategy { let preprocessed_host_path =
LinkingStrategy::Surgical | LinkingStrategy::Additive => { host_input_path.with_file_name(preprocessed_host_filename(target).unwrap());
host_input_path.with_file_name(preprocessed_host_filename(target).unwrap())
}
LinkingStrategy::Legacy => host_input_path
.with_file_name(legacy_host_filename(target, code_gen_options.opt_level).unwrap()),
};
// We don't need to spawn a rebuild thread when using a prebuilt host. // We don't need to spawn a rebuild thread when using a prebuilt host.
let rebuild_thread = if prebuilt { let rebuild_thread = if prebuilt {
@ -182,12 +177,6 @@ pub fn build_file<'a>(
std::process::exit(1); std::process::exit(1);
} }
if linking_strategy == LinkingStrategy::Surgical {
// Copy preprocessed host to executable location.
// The surgical linker will modify that copy in-place.
std::fs::copy(&preprocessed_host_path, binary_path.as_path()).unwrap();
}
None None
} else { } else {
Some(spawn_rebuild_thread( Some(spawn_rebuild_thread(
@ -202,6 +191,12 @@ pub fn build_file<'a>(
)) ))
}; };
if linking_strategy == LinkingStrategy::Surgical {
// Copy preprocessed host to executable location.
// The surgical linker will modify that copy in-place.
std::fs::copy(&preprocessed_host_path, binary_path.as_path()).unwrap();
}
let buf = &mut String::with_capacity(1024); let buf = &mut String::with_capacity(1024);
let mut it = loaded.timings.iter().peekable(); let mut it = loaded.timings.iter().peekable();
@ -441,6 +436,9 @@ fn spawn_rebuild_thread(
exported_symbols, exported_symbols,
exported_closure_types, exported_closure_types,
); );
// Copy preprocessed host to executable location.
std::fs::copy(preprocessed_host_path, binary_path.as_path()).unwrap();
} }
LinkingStrategy::Legacy => { LinkingStrategy::Legacy => {
rebuild_host( rebuild_host(
@ -452,14 +450,7 @@ fn spawn_rebuild_thread(
} }
} }
if linking_strategy == LinkingStrategy::Surgical { rebuild_host_start.elapsed().as_millis()
// Copy preprocessed host to executable location.
std::fs::copy(preprocessed_host_path, binary_path.as_path()).unwrap();
}
let rebuild_host_end = rebuild_host_start.elapsed();
rebuild_host_end.as_millis()
}) })
} }

View file

@ -134,7 +134,7 @@ pub const fn preprocessed_host_filename(target: &Triple) -> Option<&'static str>
/// Same format as the precompiled host filename, except with a file extension like ".o" or ".obj" /// Same format as the precompiled host filename, except with a file extension like ".o" or ".obj"
pub fn legacy_host_filename(target: &Triple, opt_level: OptLevel) -> Option<String> { pub fn legacy_host_filename(target: &Triple, opt_level: OptLevel) -> Option<String> {
let os = roc_target::OperatingSystem::new(target.operating_system)?; let os = roc_target::OperatingSystem::from(target.operating_system);
let ext = legacy_host_filename_ext(os, opt_level); let ext = legacy_host_filename_ext(os, opt_level);
Some(preprocessed_host_filename(target)?.replace(PRECOMPILED_HOST_EXT, ext)) Some(preprocessed_host_filename(target)?.replace(PRECOMPILED_HOST_EXT, ext))