mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
change matadata filename based on target
This commit is contained in:
parent
5570fe4108
commit
91266a03c6
3 changed files with 95 additions and 12 deletions
|
@ -87,47 +87,122 @@ const fn legacy_host_filename_ext(
|
|||
|
||||
const PRECOMPILED_HOST_EXT: &str = "rh1"; // Short for "roc host version 1" (so we can change format in the future)
|
||||
|
||||
const WASM_TARGET_STR: &str = "wasm32";
|
||||
const LINUX_X86_64_TARGET_STR: &str = "linux-x86_64";
|
||||
const LINUX_ARM64_TARGET_STR: &str = "linux-arm64";
|
||||
const MACOS_ARM64_TARGET_STR: &str = "macos-arm64";
|
||||
const MACOS_X86_64_TARGET_STR: &str = "macos-x86_64";
|
||||
const WINDOWS_X86_64_TARGET_STR: &str = "windows-x86_64";
|
||||
const WINDOWS_X86_32_TARGET_STR: &str = "windows-x86_32";
|
||||
const WIDNOWS_ARM64_TARGET_STR: &str = "windows-arm64";
|
||||
|
||||
pub const fn preprocessed_host_filename(target: &Triple) -> Option<&'static str> {
|
||||
// Don't try to split this match off in a different function, it will not work with concatcp
|
||||
match target {
|
||||
Triple {
|
||||
architecture: Architecture::Wasm32,
|
||||
..
|
||||
} => Some(concatcp!("wasm32", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(WASM_TARGET_STR, '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(concatcp!("linux-x64", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(
|
||||
LINUX_X86_64_TARGET_STR,
|
||||
'.',
|
||||
PRECOMPILED_HOST_EXT
|
||||
)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(concatcp!("linux-arm64", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(LINUX_ARM64_TARGET_STR, '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(concatcp!("macos-arm64", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(MACOS_ARM64_TARGET_STR, '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(concatcp!("macos-x64", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(
|
||||
MACOS_X86_64_TARGET_STR,
|
||||
'.',
|
||||
PRECOMPILED_HOST_EXT
|
||||
)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(concatcp!("windows-x64", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(
|
||||
WINDOWS_X86_64_TARGET_STR,
|
||||
'.',
|
||||
PRECOMPILED_HOST_EXT
|
||||
)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_32(_),
|
||||
..
|
||||
} => Some(concatcp!("windows-x86", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(
|
||||
WINDOWS_X86_32_TARGET_STR,
|
||||
'.',
|
||||
PRECOMPILED_HOST_EXT
|
||||
)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(concatcp!("windows-arm64", '.', PRECOMPILED_HOST_EXT)),
|
||||
} => Some(concatcp!(
|
||||
WIDNOWS_ARM64_TARGET_STR,
|
||||
'.',
|
||||
PRECOMPILED_HOST_EXT
|
||||
)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_target_triple_str(target: &Triple) -> Option<&'static str> {
|
||||
match target {
|
||||
Triple {
|
||||
architecture: Architecture::Wasm32,
|
||||
..
|
||||
} => Some(WASM_TARGET_STR),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(LINUX_X86_64_TARGET_STR),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(LINUX_ARM64_TARGET_STR),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(MACOS_ARM64_TARGET_STR),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(MACOS_X86_64_TARGET_STR),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(WINDOWS_X86_64_TARGET_STR),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_32(_),
|
||||
..
|
||||
} => Some(WINDOWS_X86_32_TARGET_STR),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(WIDNOWS_ARM64_TARGET_STR),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! practical to use a regular linker.
|
||||
use memmap2::{Mmap, MmapMut};
|
||||
use object::Object;
|
||||
use roc_build::link::{rebuild_host, LinkType};
|
||||
use roc_build::link::{get_target_triple_str, rebuild_host, LinkType};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_load::{EntryPoint, ExecutionMode, LoadConfig, Threading};
|
||||
use roc_mono::ir::OptLevel;
|
||||
|
@ -77,7 +77,8 @@ pub fn build_and_preprocess_host(
|
|||
let stub_dll_symbols = make_stub_dll_symbols(exposed_to_host, exported_closure_types);
|
||||
generate_dynamic_lib(target, &stub_dll_symbols, &stub_lib);
|
||||
rebuild_host(opt_level, target, host_input_path, Some(&stub_lib));
|
||||
let metadata = host_input_path.with_file_name("metadata");
|
||||
|
||||
let metadata = host_input_path.with_file_name(metadata_file_name(target));
|
||||
// let prehost = host_input_path.with_file_name(preprocessed_host_filename(target).unwrap());
|
||||
|
||||
preprocess(
|
||||
|
@ -92,13 +93,19 @@ pub fn build_and_preprocess_host(
|
|||
)
|
||||
}
|
||||
|
||||
fn metadata_file_name(target: &Triple) -> String {
|
||||
let target_triple_str = get_target_triple_str(target);
|
||||
|
||||
format!("metadata_{}.rm1", target_triple_str.unwrap_or("unknown"))
|
||||
}
|
||||
|
||||
pub fn link_preprocessed_host(
|
||||
target: &Triple,
|
||||
host_input_path: &Path,
|
||||
roc_app_bytes: &[u8],
|
||||
binary_path: &Path,
|
||||
) {
|
||||
let metadata = host_input_path.with_file_name("metadata");
|
||||
let metadata = host_input_path.with_file_name(metadata_file_name(target));
|
||||
surgery(roc_app_bytes, &metadata, binary_path, false, false, target)
|
||||
}
|
||||
|
||||
|
|
3
examples/.gitignore
vendored
3
examples/.gitignore
vendored
|
@ -3,6 +3,7 @@ libhost.a
|
|||
libapp.so
|
||||
dynhost
|
||||
preprocessedhost
|
||||
metadata
|
||||
*.rm1
|
||||
*.rh1
|
||||
|
||||
helloWorld
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue