mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Change precompiled host filename format
This commit is contained in:
parent
fa2e0648ca
commit
7f617c87bf
5 changed files with 85 additions and 28 deletions
|
@ -31,6 +31,7 @@ roc_utils = { path = "../../utils" }
|
|||
|
||||
wasi_libc_sys = { path = "../../wasi-libc-sys" }
|
||||
|
||||
const_format.workspace = true
|
||||
bumpalo.workspace = true
|
||||
libloading.workspace = true
|
||||
tempfile.workspace = true
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::target::{arch_str, target_zig_str};
|
||||
use const_format::concatcp;
|
||||
use libloading::{Error, Library};
|
||||
use roc_builtins::bitcode;
|
||||
use roc_error_macros::internal_error;
|
||||
|
@ -59,9 +60,9 @@ pub fn link(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn host_filename(target: &Triple, opt_level: OptLevel) -> Option<&'static str> {
|
||||
match roc_target::OperatingSystem::from(target.operating_system) {
|
||||
roc_target::OperatingSystem::Wasi => {
|
||||
const fn legacy_host_filename_ext(target: &Triple, opt_level: OptLevel) -> Option<&'static str> {
|
||||
match roc_target::OperatingSystem::new(target.operating_system) {
|
||||
Some(roc_target::OperatingSystem::Wasi) => {
|
||||
// TODO wasm host extension should be something else ideally
|
||||
// .bc does not seem to work because
|
||||
//
|
||||
|
@ -69,55 +70,101 @@ pub fn host_filename(target: &Triple, opt_level: OptLevel) -> Option<&'static st
|
|||
//
|
||||
// and zig does not currently emit `.a` webassembly static libraries
|
||||
if matches!(opt_level, OptLevel::Development) {
|
||||
Some("wasm32.wasm")
|
||||
Some("wasm")
|
||||
} else {
|
||||
Some("wasm32.zig")
|
||||
Some("zig")
|
||||
}
|
||||
}
|
||||
_ => match target {
|
||||
Some(_) => match target {
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some("linux-x64.o"),
|
||||
} => Some("o"),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some("linux-arm64.o"),
|
||||
} => Some("o"),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some("macos-arm64.o"),
|
||||
} => Some("o"),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some("macos-x64.o"),
|
||||
} => Some("o"),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some("windows-x64.obj"),
|
||||
} => Some("obj"),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_32(_),
|
||||
..
|
||||
} => Some("windows-x86.obj"),
|
||||
} => Some("obj"),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some("windows-arm64.obj"),
|
||||
} => Some("obj"),
|
||||
_ => None,
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The surgical linker should use the same name format, but without the "legacy_" prefix
|
||||
const PRECOMPILED_HOST_EXT: &str = "rh1"; // Short for "roc host version 1" (so we can change format in the future)
|
||||
|
||||
pub const fn precompiled_host_filename(target: &Triple) -> Option<&'static str> {
|
||||
match target {
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(concatcp!("linux-x64", '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Linux,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(concatcp!("linux-arm64", '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(concatcp!("macos-arm64", '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Darwin,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(concatcp!("macos-x64", '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_64,
|
||||
..
|
||||
} => Some(concatcp!("windows-x64", '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::X86_32(_),
|
||||
..
|
||||
} => Some(concatcp!("windows-x86", '.', PRECOMPILED_HOST_EXT)),
|
||||
Triple {
|
||||
operating_system: OperatingSystem::Windows,
|
||||
architecture: Architecture::Aarch64(_),
|
||||
..
|
||||
} => Some(concatcp!("windows-arm64", '.', PRECOMPILED_HOST_EXT)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Same format as the precompiled host filename, except with a file extension like ".o" or ".obj"
|
||||
pub fn legacy_host_filename(target: &Triple, opt_level: OptLevel) -> Option<String> {
|
||||
host_filename(target, opt_level).map(|str| format!("legacy_{str}"))
|
||||
let ext = legacy_host_filename_ext(target, opt_level)?;
|
||||
|
||||
Some(precompiled_host_filename(target)?.replace(PRECOMPILED_HOST_EXT, ext))
|
||||
}
|
||||
|
||||
fn find_zig_str_path() -> PathBuf {
|
||||
|
|
|
@ -12,17 +12,24 @@ pub enum OperatingSystem {
|
|||
Wasi,
|
||||
}
|
||||
|
||||
impl OperatingSystem {
|
||||
pub const fn new(target: target_lexicon::OperatingSystem) -> Option<Self> {
|
||||
match target {
|
||||
target_lexicon::OperatingSystem::Windows => Some(OperatingSystem::Windows),
|
||||
target_lexicon::OperatingSystem::Wasi => Some(OperatingSystem::Wasi),
|
||||
target_lexicon::OperatingSystem::Linux => Some(OperatingSystem::Unix),
|
||||
target_lexicon::OperatingSystem::MacOSX { .. } => Some(OperatingSystem::Unix),
|
||||
target_lexicon::OperatingSystem::Darwin => Some(OperatingSystem::Unix),
|
||||
target_lexicon::OperatingSystem::Unknown => Some(OperatingSystem::Unix),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<target_lexicon::OperatingSystem> for OperatingSystem {
|
||||
fn from(target: target_lexicon::OperatingSystem) -> Self {
|
||||
match target {
|
||||
target_lexicon::OperatingSystem::Windows => OperatingSystem::Windows,
|
||||
target_lexicon::OperatingSystem::Wasi => OperatingSystem::Wasi,
|
||||
target_lexicon::OperatingSystem::Linux => OperatingSystem::Unix,
|
||||
target_lexicon::OperatingSystem::MacOSX { .. } => OperatingSystem::Unix,
|
||||
target_lexicon::OperatingSystem::Darwin => OperatingSystem::Unix,
|
||||
target_lexicon::OperatingSystem::Unknown => OperatingSystem::Unix,
|
||||
other => unreachable!("unsupported operating system {:?}", other),
|
||||
}
|
||||
Self::new(target)
|
||||
.unwrap_or_else(|| unreachable!("unsupported operating system {:?}", target))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue