Use legacy_host_filename instead of always host.o

This commit is contained in:
Richard Feldman 2022-11-18 09:57:30 -05:00
parent 0b2c2ab36c
commit b80d92e344
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 70 additions and 27 deletions

View file

@ -1,6 +1,9 @@
use bumpalo::Bump; use bumpalo::Bump;
use roc_build::{ use roc_build::{
link::{link, preprocess_host_wasm32, rebuild_host, LinkType, LinkingStrategy}, link::{
host_filename, legacy_host_filename, link, preprocess_host_wasm32, rebuild_host, LinkType,
LinkingStrategy,
},
program::{self, CodeGenOptions, Problems}, program::{self, CodeGenOptions, Problems},
}; };
use roc_builtins::bitcode; use roc_builtins::bitcode;
@ -139,8 +142,7 @@ pub fn build_file<'a>(
let host_input_path = if let EntryPoint::Executable { platform_path, .. } = &loaded.entry_point let host_input_path = if let EntryPoint::Executable { platform_path, .. } = &loaded.entry_point
{ {
cwd.join(platform_path) cwd.join(platform_path)
.with_file_name("host") .with_file_name(legacy_host_filename(target).unwrap())
.with_extension(host_extension)
} else { } else {
unreachable!(); unreachable!();
}; };
@ -170,12 +172,16 @@ pub fn build_file<'a>(
}) })
.collect(); .collect();
let preprocessed_host_path = if emit_wasm { let preprocessed_host_path = match linking_strategy {
host_input_path.with_file_name("preprocessedhost.o") LinkingStrategy::Surgical | LinkingStrategy::Additive => {
} else { host_input_path.with_file_name(host_filename(target).unwrap())
host_input_path.with_file_name("preprocessedhost") }
LinkingStrategy::Legacy => {
host_input_path.with_file_name(legacy_host_filename(target).unwrap())
}
}; };
// TODO can we not spawn the rebuild thread if we have a preprocessed host already?
let rebuild_thread = spawn_rebuild_thread( let rebuild_thread = spawn_rebuild_thread(
code_gen_options.opt_level, code_gen_options.opt_level,
linking_strategy, linking_strategy,

View file

@ -59,6 +59,56 @@ pub fn link(
} }
} }
pub const fn host_filename(target: &Triple) -> Result<&'static str, ()> {
match target {
Triple {
architecture: Architecture::Wasm32,
..
} => Ok("wasm32"),
Triple {
operating_system: OperatingSystem::Linux,
architecture: Architecture::X86_64,
..
} => Ok("linux-x64.o"),
Triple {
operating_system: OperatingSystem::Linux,
architecture: Architecture::Aarch64(_),
..
} => Ok("linux-arm64.o"),
Triple {
operating_system: OperatingSystem::Darwin,
architecture: Architecture::Aarch64(_),
..
} => Ok("macos-arm64.o"),
Triple {
operating_system: OperatingSystem::Darwin,
architecture: Architecture::X86_64,
..
} => Ok("macos-x64.o"),
Triple {
operating_system: OperatingSystem::Windows,
architecture: Architecture::X86_64,
..
} => Ok("windows-x64.obj"),
Triple {
operating_system: OperatingSystem::Windows,
architecture: Architecture::X86_32(_),
..
} => Ok("windows-x86.obj"),
Triple {
operating_system: OperatingSystem::Windows,
architecture: Architecture::Aarch64(_),
..
} => Ok("windows-arm64.obj"),
_ => Err(()),
}
}
/// The surgical linker should use the same name format, but without the "legacy_" prefix
pub fn legacy_host_filename(target: &Triple) -> Result<String, ()> {
host_filename(target).map(|str| format!("legacy_{str}"))
}
fn find_zig_str_path() -> PathBuf { fn find_zig_str_path() -> PathBuf {
// First try using the lib path relative to the executable location. // First try using the lib path relative to the executable location.
let lib_path_opt = get_lib_path(); let lib_path_opt = get_lib_path();
@ -528,26 +578,13 @@ pub fn rebuild_host(
roc_target::OperatingSystem::Wasi => "", roc_target::OperatingSystem::Wasi => "",
}; };
let object_extension = match os { let host_dest =
roc_target::OperatingSystem::Windows => "obj", if shared_lib_path.is_none() || matches!(target.architecture, Architecture::Wasm32) {
roc_target::OperatingSystem::Unix => "o", host_input_path.with_file_name(legacy_host_filename(target).unwrap())
roc_target::OperatingSystem::Wasi => "o",
};
let host_dest = if matches!(target.architecture, Architecture::Wasm32) {
if matches!(opt_level, OptLevel::Development) {
host_input_path.with_file_name("host.o")
} else { } else {
host_input_path.with_file_name("host.bc")
}
} else if shared_lib_path.is_some() {
host_input_path host_input_path
.with_file_name("dynhost") .with_file_name("dynhost")
.with_extension(executable_extension) .with_extension(executable_extension)
} else {
host_input_path
.with_file_name("host")
.with_extension(object_extension)
}; };
let env_path = env::var("PATH").unwrap_or_else(|_| "".to_string()); let env_path = env::var("PATH").unwrap_or_else(|_| "".to_string());