mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
add the concept of an OS to target info
This commit is contained in:
parent
6f3c8477e6
commit
7df31619dd
6 changed files with 45 additions and 28 deletions
|
@ -136,7 +136,7 @@ pub fn build_zig_host_native(
|
|||
zig_str_path,
|
||||
"--pkg-end",
|
||||
// include the zig runtime
|
||||
"-fcompiler-rt",
|
||||
// "-fcompiler-rt",
|
||||
// include libc
|
||||
"--library",
|
||||
"c",
|
||||
|
@ -158,6 +158,7 @@ pub fn build_zig_host_native(
|
|||
} else if matches!(opt_level, OptLevel::Size) {
|
||||
command.args(&["-O", "ReleaseSmall"]);
|
||||
}
|
||||
|
||||
command.output().unwrap()
|
||||
}
|
||||
|
||||
|
@ -423,9 +424,10 @@ pub fn rebuild_host(
|
|||
host_input_path.with_file_name(if shared_lib_path.is_some() {
|
||||
"dynhost"
|
||||
} else {
|
||||
match roc_target::Architecture::from(target.architecture) {
|
||||
roc_target::Architecture::Windows64 => "host.obj",
|
||||
_ => "host.o",
|
||||
match roc_target::OperatingSystem::from(target.operating_system) {
|
||||
roc_target::OperatingSystem::Windows => "host.obj",
|
||||
roc_target::OperatingSystem::Unix => "host.o",
|
||||
roc_target::OperatingSystem::Wasi => "host.o",
|
||||
}
|
||||
})
|
||||
};
|
||||
|
@ -1101,7 +1103,6 @@ fn link_windows(
|
|||
_link_type: LinkType,
|
||||
) -> io::Result<(Child, PathBuf)> {
|
||||
let zig_str_path = find_zig_str_path();
|
||||
let wasi_libc_path = find_wasi_libc_path();
|
||||
|
||||
let child = Command::new(&zig_executable())
|
||||
.args(&["build-exe"])
|
||||
|
|
|
@ -60,7 +60,7 @@ impl FloatWidth {
|
|||
match self {
|
||||
F32 => 4,
|
||||
F64 | F128 => match target_info.architecture {
|
||||
X86_64 | Aarch64 | Wasm32 | Windows64 => 8,
|
||||
X86_64 | Aarch64 | Wasm32 => 8,
|
||||
X86_32 | Aarch32 => 4,
|
||||
},
|
||||
}
|
||||
|
@ -127,8 +127,7 @@ impl IntWidth {
|
|||
Architecture::X86_64
|
||||
| Architecture::Aarch64
|
||||
| Architecture::Aarch32
|
||||
| Architecture::Wasm32
|
||||
| Architecture::Windows64 => 8,
|
||||
| Architecture::Wasm32 => 8,
|
||||
Architecture::X86_32 => 4,
|
||||
},
|
||||
U128 | I128 => {
|
||||
|
|
|
@ -4,9 +4,30 @@
|
|||
|
||||
use strum_macros::{EnumCount, EnumIter};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum OperatingSystem {
|
||||
Windows,
|
||||
Unix,
|
||||
Wasi,
|
||||
}
|
||||
|
||||
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,
|
||||
other => unreachable!("unsupported operating system {:?}", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct TargetInfo {
|
||||
pub architecture: Architecture,
|
||||
pub operating_system: OperatingSystem,
|
||||
}
|
||||
|
||||
impl TargetInfo {
|
||||
|
@ -28,18 +49,21 @@ impl TargetInfo {
|
|||
pub const fn default_aarch64() -> Self {
|
||||
TargetInfo {
|
||||
architecture: Architecture::Aarch64,
|
||||
operating_system: OperatingSystem::Unix,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn default_x86_64() -> Self {
|
||||
TargetInfo {
|
||||
architecture: Architecture::X86_64,
|
||||
operating_system: OperatingSystem::Unix,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn default_wasm32() -> Self {
|
||||
TargetInfo {
|
||||
architecture: Architecture::Wasm32,
|
||||
operating_system: OperatingSystem::Wasi,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,14 +71,9 @@ impl TargetInfo {
|
|||
impl From<&target_lexicon::Triple> for TargetInfo {
|
||||
fn from(triple: &target_lexicon::Triple) -> Self {
|
||||
let architecture = Architecture::from(triple.architecture);
|
||||
let operating_system = OperatingSystem::from(triple.operating_system);
|
||||
|
||||
Self { architecture }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Architecture> for TargetInfo {
|
||||
fn from(architecture: Architecture) -> Self {
|
||||
Self { architecture }
|
||||
Self { architecture, operating_system }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +93,6 @@ pub enum Architecture {
|
|||
Wasm32,
|
||||
X86_32,
|
||||
X86_64,
|
||||
Windows64,
|
||||
}
|
||||
|
||||
impl Architecture {
|
||||
|
@ -82,7 +100,7 @@ impl Architecture {
|
|||
use Architecture::*;
|
||||
|
||||
match self {
|
||||
X86_64 | Aarch64 | Windows64 => PtrWidth::Bytes8,
|
||||
X86_64 | Aarch64 => PtrWidth::Bytes8,
|
||||
X86_32 | Aarch32 | Wasm32 => PtrWidth::Bytes4,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue