replace stray strings with impl on Target

This commit is contained in:
Luke Boswell 2024-07-09 14:39:36 +10:00
parent 753cfb4285
commit 85447ec2cc
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
7 changed files with 58 additions and 54 deletions

View file

@ -771,7 +771,7 @@ fn build_loaded_file<'a>(
let output_exe_path = get_exe_path(
out_path,
&app_module_path,
app_module_path.as_path(),
target,
linking_strategy,
link_type,
@ -866,8 +866,7 @@ fn build_loaded_file<'a>(
match (linking_strategy, link_type) {
(LinkingStrategy::Surgical, _) => {
let metadata_file =
platform_main_roc.with_file_name(roc_linker::metadata_file_name(target));
let metadata_file = platform_main_roc.with_file_name(target.metadata_file_name());
roc_linker::link_preprocessed_host(
target,
@ -950,7 +949,7 @@ fn build_loaded_file<'a>(
/// use that directory, but use the app module's filename for the filename.
fn get_exe_path(
out_path: Option<&Path>,
app_module_path: &PathBuf,
app_module_path: &Path,
target: Target,
linking_strategy: LinkingStrategy,
link_type: LinkType,
@ -986,7 +985,7 @@ fn get_exe_path(
path.to_path_buf()
}
}
None => with_output_extension(&app_module_path, target, linking_strategy, link_type),
None => with_output_extension(app_module_path, target, linking_strategy, link_type),
}
}
@ -1000,8 +999,7 @@ fn get_host_path(
output_exe_path: &Path,
dll_stub_symbols: Vec<String>,
) -> PathBuf {
let preprocessed_host_path =
platform_main_roc.with_file_name(roc_linker::preprocessed_host_filename(target));
let preprocessed_host_path = platform_main_roc.with_file_name(target.prebuilt_surgical_host());
if build_host_requested {
let rebuild_thread = match linking_strategy {
@ -1012,9 +1010,9 @@ fn get_host_path(
preprocessed_host_path.to_owned(),
),
LinkingStrategy::Surgical => {
let preprocessed_path = platform_main_roc.with_file_name(format!("{}.rh", target));
let metadata_path =
platform_main_roc.with_file_name(roc_linker::metadata_file_name(target));
let preprocessed_path =
platform_main_roc.with_file_name(target.prebuilt_surgical_host());
let metadata_path = platform_main_roc.with_file_name(target.metadata_file_name());
spawn_surgical_host_build_thread(
code_gen_options.opt_level,
@ -1139,7 +1137,7 @@ fn spawn_surgical_host_build_thread(
// Copy preprocessed host to executable location.
// The surgical linker will modify that copy in-place.
std::fs::copy(&preprocessed_path, output_exe_path.to_owned()).unwrap();
std::fs::copy(&preprocessed_path, &output_exe_path).unwrap();
(start.elapsed().as_millis(), output_exe_path)
})

View file

@ -134,6 +134,7 @@ impl Target {
self.architecture().ptr_alignment_bytes()
}
// file extension for an object file
pub const fn object_file_ext(&self) -> &str {
use Target::*;
match self {
@ -143,6 +144,7 @@ impl Target {
}
}
// file extension for a static library file
pub const fn static_library_file_ext(&self) -> &str {
use Target::*;
match self {
@ -152,6 +154,18 @@ impl Target {
}
}
// file extension for a dynamic/shared library file
pub const fn dynamic_library_file_ext(&self) -> &str {
use Target::*;
match self {
LinuxX32 | LinuxX64 | LinuxArm64 => "so",
MacX64 | MacArm64 => "dylib",
WinX32 | WinX64 | WinArm64 => "dll",
Wasm32 => "wasm",
}
}
// file extension for an executable file
pub const fn executable_file_ext(&self) -> Option<&str> {
use Target::*;
match self {
@ -161,32 +175,49 @@ impl Target {
}
}
// file name for a prebuilt host object file
// used for legacy linking
pub fn prebuilt_static_object(&self) -> String {
use Target::*;
match self {
LinuxX32 | LinuxX64 | LinuxArm64 | MacX64 | MacArm64 | Wasm32 => {
format!("{}-{}.o", self.operating_system(), self.architecture())
format!("{}.o", self)
}
WinX32 | WinX64 | WinArm64 => {
format!("{}-{}.obj", self.operating_system(), self.architecture())
format!("{}.obj", self)
}
}
}
// file name for a prebuilt host static library file
// used for legacy linking
pub fn prebuilt_static_library(&self) -> String {
use Target::*;
match self {
LinuxX32 | LinuxX64 | LinuxArm64 | MacX64 | MacArm64 | Wasm32 => {
format!("{}-{}.a", self.operating_system(), self.architecture())
format!("{}.a", self)
}
WinX32 | WinX64 | WinArm64 => {
format!("{}-{}.lib", self.operating_system(), self.architecture())
format!("{}.lib", self)
}
}
}
// file name for a preprocessed host executable file
// used for surgical linking
pub fn prebuilt_surgical_host(&self) -> String {
format!("{}-{}.rh", self.operating_system(), self.architecture())
format!("{}.rh", self) // short for roc host
}
// file name for a preprocessed host metadata file
// used for surgical linking
pub fn metadata_file_name(&self) -> String {
format!("metadata_{}.rm", self) // short for roc metadata
}
// file name for a stubbed app dynamic library file
pub fn stub_app_lib_file_name(&self) -> String {
format!("libapp.{}", self.dynamic_library_file_ext())
}
}