Simplify legacy_host_filename_ext

This commit is contained in:
Richard Feldman 2022-11-22 17:19:36 -05:00
parent 87ad2cdf82
commit 2dba97d6a2
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B

View file

@ -60,9 +60,14 @@ pub fn link(
} }
} }
const fn legacy_host_filename_ext(target: &Triple, opt_level: OptLevel) -> Option<&'static str> { const fn legacy_host_filename_ext(
match roc_target::OperatingSystem::new(target.operating_system) { os: roc_target::OperatingSystem,
Some(roc_target::OperatingSystem::Wasi) => { opt_level: OptLevel,
) -> &'static str {
use roc_target::OperatingSystem::*;
match os {
Wasi => {
// TODO wasm host extension should be something else ideally // TODO wasm host extension should be something else ideally
// .bc does not seem to work because // .bc does not seem to work because
// //
@ -70,50 +75,13 @@ const fn legacy_host_filename_ext(target: &Triple, opt_level: OptLevel) -> Optio
// //
// and zig does not currently emit `.a` webassembly static libraries // and zig does not currently emit `.a` webassembly static libraries
if matches!(opt_level, OptLevel::Development) { if matches!(opt_level, OptLevel::Development) {
Some("wasm") "wasm"
} else { } else {
Some("zig") "zig"
} }
} }
Some(_) => match target { Unix => "o",
Triple { Windows => "obj",
operating_system: OperatingSystem::Linux,
architecture: Architecture::X86_64,
..
} => Some("o"),
Triple {
operating_system: OperatingSystem::Linux,
architecture: Architecture::Aarch64(_),
..
} => Some("o"),
Triple {
operating_system: OperatingSystem::Darwin,
architecture: Architecture::Aarch64(_),
..
} => Some("o"),
Triple {
operating_system: OperatingSystem::Darwin,
architecture: Architecture::X86_64,
..
} => Some("o"),
Triple {
operating_system: OperatingSystem::Windows,
architecture: Architecture::X86_64,
..
} => Some("obj"),
Triple {
operating_system: OperatingSystem::Windows,
architecture: Architecture::X86_32(_),
..
} => Some("obj"),
Triple {
operating_system: OperatingSystem::Windows,
architecture: Architecture::Aarch64(_),
..
} => Some("obj"),
_ => None,
},
None => None,
} }
} }
@ -162,7 +130,8 @@ pub const fn preprocessed_host_filename(target: &Triple) -> Option<&'static str>
/// Same format as the precompiled host filename, except with a file extension like ".o" or ".obj" /// 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> { pub fn legacy_host_filename(target: &Triple, opt_level: OptLevel) -> Option<String> {
let ext = legacy_host_filename_ext(target, opt_level)?; let os = roc_target::OperatingSystem::new(target.operating_system)?;
let ext = legacy_host_filename_ext(os, opt_level);
Some(preprocessed_host_filename(target)?.replace(PRECOMPILED_HOST_EXT, ext)) Some(preprocessed_host_filename(target)?.replace(PRECOMPILED_HOST_EXT, ext))
} }