checkpoint: Run struct refactor for helpers

This commit is contained in:
Ryan Barth 2024-07-22 04:07:58 -07:00
parent dfa3254088
commit bc29782420
No known key found for this signature in database
GPG key ID: E00C3713D9ED3943
6 changed files with 449 additions and 366 deletions

View file

@ -737,7 +737,7 @@ pub fn build_file<'a>(
}
#[derive(Debug)]
enum PrebuiltHost {
pub enum PrebuiltHost {
Additive(PathBuf),
Legacy(PathBuf),
// metadata, preprocessed_host
@ -829,8 +829,8 @@ fn build_loaded_file<'a>(
let dll_stub_symbols =
roc_linker::ExposedSymbols::from_exposed_to_host(&loaded.interns, &loaded.exposed_to_host);
let mut legacy_host_path = target.find_legacy_host(&platform_main_roc);
let mut surgical_artifacts = target.find_surgical_host(&platform_main_roc);
let legacy_host_path = target.find_legacy_host(&platform_main_roc);
let surgical_artifacts = target.find_surgical_host(&platform_main_roc);
let built_host_path: PrebuiltHost = match (
legacy_host_path,
@ -838,9 +838,21 @@ fn build_loaded_file<'a>(
build_host_requested,
link_type
) {
(Ok(_), _, true, _) => panic!("legacy host already built"),
(_, Ok(_), true, _) => panic!("sugical host already built"),
(_, _, true, LinkType::Executable) => {
// The following 4 cases represent the possible valid host states for the compiler once
// host rebuilding has been removed.
(Ok(host_path), _, false, _) => PrebuiltHost::Legacy(host_path),
(_, Ok(artifacts), false, _) => PrebuiltHost::Surgical(artifacts),
(Err(_), Err(_), false, LinkType::Dylib) => PrebuiltHost::None,
(Err(_), Err(_), false, LinkType::None) => PrebuiltHost::None,
(Err(legacy_paths), Err(surgical_paths), false, LinkType::Executable) => {
report_missing_prebuilt_host(&format!("{legacy_paths}\n {surgical_paths}"));
std::process::exit(1);
},
// The following 3 cases we currently support for host rebuilding. Emit a deprecation
// warning and rebuild the host.
(Ok(existing_legacy_host), _, true, LinkType::Executable) => {
report_rebuilding_existing_host(&existing_legacy_host.to_string_lossy());
build_and_preprocess_host(
code_gen_options,
dll_stub_symbols,
@ -851,17 +863,55 @@ fn build_loaded_file<'a>(
target,
)
}
(Ok(host_path), _, false, _) => PrebuiltHost::Legacy(host_path),
(_, Ok(artifacts), false, _) => PrebuiltHost::Surgical(artifacts),
(Err(_), Err(_), true, LinkType::Dylib) => panic!("trying to rebuild host for dynamic library that is not linked"),
(Err(_), Err(_), true, LinkType::None) => panic!("trying to rebuild host for object that is not linked"),
(Err(legacy_paths), Err(surgical_paths), false, LinkType::Executable) => {
report_missing_prebuilt_host(&format!("{legacy_paths}\n {surgical_paths}"));
(_, Ok(SurgicalHostArtifacts {preprocessed_host, ..}), true, LinkType::Executable) => {
report_rebuilding_existing_host(&preprocessed_host.to_string_lossy());
build_and_preprocess_host(
code_gen_options,
dll_stub_symbols,
emit_timings,
linking_strategy,
&platform_main_roc,
&output_exe_path,
target,
)
}
(Err(legacy_paths), Err(surgical_paths), true, LinkType::Executable) => {
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
build_and_preprocess_host(
code_gen_options,
dll_stub_symbols,
emit_timings,
linking_strategy,
&platform_main_roc,
&output_exe_path,
target,
)
}
// We do not support rebuilding these types of hosts because this would be net new
// functionality on a deprecated feature.
(Ok(host_path), _, true, LinkType::Dylib | LinkType::None) => {
report_refusing_to_rebuild_host(&host_path.to_string_lossy());
std::process::exit(1);
}
(_, Ok(SurgicalHostArtifacts {preprocessed_host, metadata}), true, LinkType::Dylib | LinkType::None) => {
report_refusing_to_rebuild_host(&format!(
"{}\n {}",
preprocessed_host.to_string_lossy(),
metadata.to_string_lossy(),
));
std::process::exit(1);
}
(Err(legacy_paths), Err(surgical_paths), true, LinkType::Dylib) => {
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for a dynamic library.");
std::process::exit(1);
},
(Err(legacy_paths), Err(surgical_paths), true, LinkType::None) => {
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for an unlinked object.");
std::process::exit(1);
},
(Err(_), Err(_), false, LinkType::Dylib) => PrebuiltHost::None,
(Err(_), Err(_), false, LinkType::None) => PrebuiltHost::None,
};
let buf = &mut String::with_capacity(1024);
@ -1066,6 +1116,42 @@ fn get_exe_path(
}
}
fn report_rebuilding_existing_host(host_path: &str) {
eprintln!(
indoc::indoc!(
r#"
WARNING: I found an existing compiled host at:
{}
However, the --build-host flag was set! I will rebuild the host and overwrite the existing file.
Remove the --build-host flag to use the existing host and silence this warning.
Rebuilding hosts using the roc compiler is deprecated and will be removed in a future version.
"#
),
host_path,
);
}
fn report_rebuilding_missing_host(host_path: &str) {
eprintln!(
indoc::indoc!(
r#"
WARNING: I was expecting a prebuilt host to exist at:
{}
However, it was not there! I will rebuild the host and write it to that location.
Rebuilding hosts using the roc compiler is deprecated and will be removed in a future version.
"#
),
host_path,
);
}
fn report_missing_prebuilt_host(msg: &str) {
eprintln!(
indoc::indoc!(
@ -1083,6 +1169,22 @@ fn report_missing_prebuilt_host(msg: &str) {
);
}
fn report_refusing_to_rebuild_host(host_path: &str) {
eprintln!(
indoc::indoc!(
r#"
I found a prebuilt host for this platform, but you requested to rebuild it:
{}
Remove the `--build-host` flag to use the prebuilt host.
The `--build-host` flag is deprecated and will be removed in a future release.
"#
),
host_path,
);
}
fn spawn_wasm32_host_build_thread(
opt_level: OptLevel,
target: Target,