mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +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 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> {
|
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 {
|
match target {
|
||||||
Triple {
|
Triple {
|
||||||
architecture: Architecture::Wasm32,
|
architecture: Architecture::Wasm32,
|
||||||
..
|
..
|
||||||
} => Some(concatcp!("wasm32", '.', PRECOMPILED_HOST_EXT)),
|
} => Some(concatcp!(WASM_TARGET_STR, '.', PRECOMPILED_HOST_EXT)),
|
||||||
Triple {
|
Triple {
|
||||||
operating_system: OperatingSystem::Linux,
|
operating_system: OperatingSystem::Linux,
|
||||||
architecture: Architecture::X86_64,
|
architecture: Architecture::X86_64,
|
||||||
..
|
..
|
||||||
} => Some(concatcp!("linux-x64", '.', PRECOMPILED_HOST_EXT)),
|
} => Some(concatcp!(
|
||||||
|
LINUX_X86_64_TARGET_STR,
|
||||||
|
'.',
|
||||||
|
PRECOMPILED_HOST_EXT
|
||||||
|
)),
|
||||||
Triple {
|
Triple {
|
||||||
operating_system: OperatingSystem::Linux,
|
operating_system: OperatingSystem::Linux,
|
||||||
architecture: Architecture::Aarch64(_),
|
architecture: Architecture::Aarch64(_),
|
||||||
..
|
..
|
||||||
} => Some(concatcp!("linux-arm64", '.', PRECOMPILED_HOST_EXT)),
|
} => Some(concatcp!(LINUX_ARM64_TARGET_STR, '.', PRECOMPILED_HOST_EXT)),
|
||||||
Triple {
|
Triple {
|
||||||
operating_system: OperatingSystem::Darwin,
|
operating_system: OperatingSystem::Darwin,
|
||||||
architecture: Architecture::Aarch64(_),
|
architecture: Architecture::Aarch64(_),
|
||||||
..
|
..
|
||||||
} => Some(concatcp!("macos-arm64", '.', PRECOMPILED_HOST_EXT)),
|
} => Some(concatcp!(MACOS_ARM64_TARGET_STR, '.', PRECOMPILED_HOST_EXT)),
|
||||||
Triple {
|
Triple {
|
||||||
operating_system: OperatingSystem::Darwin,
|
operating_system: OperatingSystem::Darwin,
|
||||||
architecture: Architecture::X86_64,
|
architecture: Architecture::X86_64,
|
||||||
..
|
..
|
||||||
} => Some(concatcp!("macos-x64", '.', PRECOMPILED_HOST_EXT)),
|
} => Some(concatcp!(
|
||||||
|
MACOS_X86_64_TARGET_STR,
|
||||||
|
'.',
|
||||||
|
PRECOMPILED_HOST_EXT
|
||||||
|
)),
|
||||||
Triple {
|
Triple {
|
||||||
operating_system: OperatingSystem::Windows,
|
operating_system: OperatingSystem::Windows,
|
||||||
architecture: Architecture::X86_64,
|
architecture: Architecture::X86_64,
|
||||||
..
|
..
|
||||||
} => Some(concatcp!("windows-x64", '.', PRECOMPILED_HOST_EXT)),
|
} => Some(concatcp!(
|
||||||
|
WINDOWS_X86_64_TARGET_STR,
|
||||||
|
'.',
|
||||||
|
PRECOMPILED_HOST_EXT
|
||||||
|
)),
|
||||||
Triple {
|
Triple {
|
||||||
operating_system: OperatingSystem::Windows,
|
operating_system: OperatingSystem::Windows,
|
||||||
architecture: Architecture::X86_32(_),
|
architecture: Architecture::X86_32(_),
|
||||||
..
|
..
|
||||||
} => Some(concatcp!("windows-x86", '.', PRECOMPILED_HOST_EXT)),
|
} => Some(concatcp!(
|
||||||
|
WINDOWS_X86_32_TARGET_STR,
|
||||||
|
'.',
|
||||||
|
PRECOMPILED_HOST_EXT
|
||||||
|
)),
|
||||||
Triple {
|
Triple {
|
||||||
operating_system: OperatingSystem::Windows,
|
operating_system: OperatingSystem::Windows,
|
||||||
architecture: Architecture::Aarch64(_),
|
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,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
//! practical to use a regular linker.
|
//! practical to use a regular linker.
|
||||||
use memmap2::{Mmap, MmapMut};
|
use memmap2::{Mmap, MmapMut};
|
||||||
use object::Object;
|
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_error_macros::internal_error;
|
||||||
use roc_load::{EntryPoint, ExecutionMode, LoadConfig, Threading};
|
use roc_load::{EntryPoint, ExecutionMode, LoadConfig, Threading};
|
||||||
use roc_mono::ir::OptLevel;
|
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);
|
let stub_dll_symbols = make_stub_dll_symbols(exposed_to_host, exported_closure_types);
|
||||||
generate_dynamic_lib(target, &stub_dll_symbols, &stub_lib);
|
generate_dynamic_lib(target, &stub_dll_symbols, &stub_lib);
|
||||||
rebuild_host(opt_level, target, host_input_path, Some(&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());
|
// let prehost = host_input_path.with_file_name(preprocessed_host_filename(target).unwrap());
|
||||||
|
|
||||||
preprocess(
|
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(
|
pub fn link_preprocessed_host(
|
||||||
target: &Triple,
|
target: &Triple,
|
||||||
host_input_path: &Path,
|
host_input_path: &Path,
|
||||||
roc_app_bytes: &[u8],
|
roc_app_bytes: &[u8],
|
||||||
binary_path: &Path,
|
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)
|
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
|
libapp.so
|
||||||
dynhost
|
dynhost
|
||||||
preprocessedhost
|
preprocessedhost
|
||||||
metadata
|
*.rm1
|
||||||
|
*.rh1
|
||||||
|
|
||||||
helloWorld
|
helloWorld
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue