mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Use legacy_host_filename instead of always host.o
This commit is contained in:
parent
0b2c2ab36c
commit
b80d92e344
2 changed files with 70 additions and 27 deletions
|
@ -1,6 +1,9 @@
|
|||
use bumpalo::Bump;
|
||||
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},
|
||||
};
|
||||
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
|
||||
{
|
||||
cwd.join(platform_path)
|
||||
.with_file_name("host")
|
||||
.with_extension(host_extension)
|
||||
.with_file_name(legacy_host_filename(target).unwrap())
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
@ -170,12 +172,16 @@ pub fn build_file<'a>(
|
|||
})
|
||||
.collect();
|
||||
|
||||
let preprocessed_host_path = if emit_wasm {
|
||||
host_input_path.with_file_name("preprocessedhost.o")
|
||||
} else {
|
||||
host_input_path.with_file_name("preprocessedhost")
|
||||
let preprocessed_host_path = match linking_strategy {
|
||||
LinkingStrategy::Surgical | LinkingStrategy::Additive => {
|
||||
host_input_path.with_file_name(host_filename(target).unwrap())
|
||||
}
|
||||
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(
|
||||
code_gen_options.opt_level,
|
||||
linking_strategy,
|
||||
|
|
|
@ -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 {
|
||||
// First try using the lib path relative to the executable location.
|
||||
let lib_path_opt = get_lib_path();
|
||||
|
@ -528,27 +578,14 @@ pub fn rebuild_host(
|
|||
roc_target::OperatingSystem::Wasi => "",
|
||||
};
|
||||
|
||||
let object_extension = match os {
|
||||
roc_target::OperatingSystem::Windows => "obj",
|
||||
roc_target::OperatingSystem::Unix => "o",
|
||||
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")
|
||||
let host_dest =
|
||||
if shared_lib_path.is_none() || matches!(target.architecture, Architecture::Wasm32) {
|
||||
host_input_path.with_file_name(legacy_host_filename(target).unwrap())
|
||||
} else {
|
||||
host_input_path.with_file_name("host.bc")
|
||||
}
|
||||
} else if shared_lib_path.is_some() {
|
||||
host_input_path
|
||||
.with_file_name("dynhost")
|
||||
.with_extension(executable_extension)
|
||||
} else {
|
||||
host_input_path
|
||||
.with_file_name("host")
|
||||
.with_extension(object_extension)
|
||||
};
|
||||
host_input_path
|
||||
.with_file_name("dynhost")
|
||||
.with_extension(executable_extension)
|
||||
};
|
||||
|
||||
let env_path = env::var("PATH").unwrap_or_else(|_| "".to_string());
|
||||
let env_home = env::var("HOME").unwrap_or_else(|_| "".to_string());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue