1use crate::errors::{SystemError, SystemResult};
4use serde::Deserialize;
5use std::fmt::Display;
6
7pub const OS: OperatingSystem = if cfg!(target_os = "windows") {
9 OperatingSystem::WINDOWS
10} else if cfg!(target_os = "macos") {
11 OperatingSystem::OSX
12} else if cfg!(target_os = "linux") {
13 OperatingSystem::LINUX
14} else {
15 OperatingSystem::UNKNOWN
16};
17
18pub const ARCHITECTURE: Architecture = if cfg!(target_arch = "x86") {
20 Architecture::X86
21} else if cfg!(target_arch = "x86_64") {
22 Architecture::X64
23} else if cfg!(target_arch = "arm") {
24 Architecture::ARM
25} else if cfg!(target_arch = "aarch64") {
26 Architecture::AARCH64
27} else {
28 Architecture::UNKNOWN
29};
30
31#[derive(Deserialize, PartialEq, Eq, Hash, Debug)]
33pub enum OperatingSystem {
34 #[serde(rename = "windows")]
35 WINDOWS,
36 #[serde(rename = "linux")]
37 LINUX,
38 #[serde(rename = "osx")]
39 OSX,
40 #[serde(rename = "unknown")]
41 UNKNOWN,
42}
43
44#[derive(Deserialize, Clone, PartialEq, Eq, Hash, Debug)]
46pub enum Architecture {
47 #[serde(rename = "x86")]
48 X86,
49 #[serde(rename = "x64")]
50 X64,
51 #[serde(rename = "arm")]
52 ARM,
53 #[serde(rename = "aarch64")]
54 AARCH64,
55 #[serde(rename = "unknown")]
56 UNKNOWN,
57}
58
59impl OperatingSystem {
60 pub fn get_vanilla_os(&self) -> SystemResult<&'static str> {
63 match self {
64 OperatingSystem::WINDOWS => Ok("windows"),
65 OperatingSystem::LINUX => Ok("linux"),
66 OperatingSystem::OSX => Ok("osx"),
67 OperatingSystem::UNKNOWN => Err(SystemError::UnsupportedOS),
68 }
69 }
70
71 pub fn get_adoptium_name(&self) -> SystemResult<&'static str> {
74 match self {
75 OperatingSystem::WINDOWS => Ok("windows"),
76 OperatingSystem::LINUX => Ok("linux"),
77 OperatingSystem::OSX => Ok("mac"),
78 OperatingSystem::UNKNOWN => Err(SystemError::UnsupportedOS),
79 }
80 }
81
82 pub fn get_graal_name(&self) -> SystemResult<&'static str> {
85 match self {
86 OperatingSystem::WINDOWS => Ok("windows"),
87 OperatingSystem::LINUX => Ok("linux"),
88 OperatingSystem::OSX => Ok("macos"),
89 OperatingSystem::UNKNOWN => Err(SystemError::UnsupportedOS),
90 }
91 }
92
93 pub fn get_zulu_name(&self) -> SystemResult<&'static str> {
96 match self {
97 OperatingSystem::WINDOWS => Ok("windows"),
98 OperatingSystem::LINUX => Ok("linux"),
99 OperatingSystem::OSX => Ok("macos"),
100 OperatingSystem::UNKNOWN => Err(SystemError::UnsupportedOS),
101 }
102 }
103
104 pub fn get_zulu_ext(&self) -> SystemResult<&'static str> {
107 match self {
108 OperatingSystem::WINDOWS => Ok("zip"),
109 OperatingSystem::LINUX | OperatingSystem::OSX => Ok("tar.gz"),
110 OperatingSystem::UNKNOWN => Err(SystemError::UnsupportedOS),
111 }
112 }
113
114 pub fn get_archive_type(&self) -> SystemResult<&'static str> {
117 match self {
118 OperatingSystem::WINDOWS => Ok("zip"),
119 OperatingSystem::LINUX | OperatingSystem::OSX => Ok("tar.gz"),
120 OperatingSystem::UNKNOWN => Err(SystemError::UnsupportedOS),
121 }
122 }
123}
124
125impl Display for OperatingSystem {
126 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
127 match self {
128 OperatingSystem::WINDOWS => f.write_str("windows"),
129 OperatingSystem::LINUX => f.write_str("linux"),
130 OperatingSystem::OSX => f.write_str("osx"),
131 OperatingSystem::UNKNOWN => f.write_str("unknown"),
132 }
133 }
134}
135
136impl Architecture {
137 pub fn get_simple_name(&self) -> SystemResult<&'static str> {
139 match self {
140 Architecture::X86 => Ok("x86"),
141 Architecture::X64 => Ok("x64"),
142 Architecture::ARM => Ok("arm"),
143 Architecture::AARCH64 => Ok("aarch64"),
144 Architecture::UNKNOWN => Err(SystemError::UnsupportedArchitecture),
145 }
146 }
147
148 pub fn get_vanilla_arch(&self) -> SystemResult<&'static str> {
151 match self {
152 Architecture::X86 => Ok("-x86"),
153 Architecture::X64 => Ok(""),
154 Architecture::ARM => Ok("-arm"),
155 Architecture::AARCH64 => Ok("-arm64"),
156 Architecture::UNKNOWN => Err(SystemError::UnsupportedArchitecture),
157 }
158 }
159
160 pub fn get_arch_bits(&self) -> SystemResult<&'static str> {
163 match self {
164 Architecture::X86 => Ok("32"),
165 Architecture::X64 => Ok("64"),
166 Architecture::ARM => Ok("32"),
167 Architecture::AARCH64 => Ok("64"),
168 Architecture::UNKNOWN => Err(SystemError::UnsupportedArchitecture),
169 }
170 }
171
172 pub fn get_zulu_arch(&self) -> SystemResult<&'static str> {
175 match self {
176 Architecture::X86 => Ok("i686"),
178 Architecture::X64 => Ok("x64"),
179 Architecture::ARM => Ok("arm"),
180 Architecture::AARCH64 => Ok("aarch64"),
181 Architecture::UNKNOWN => Err(SystemError::UnsupportedArchitecture),
182 }
183 }
184}
185
186impl Display for Architecture {
187 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
188 match self {
189 Architecture::X86 => f.write_str("x86"),
190 Architecture::X64 => f.write_str("x64"),
191 Architecture::ARM => f.write_str("arm"),
192 Architecture::AARCH64 => f.write_str("aarch64"),
193 Architecture::UNKNOWN => f.write_str("unknown"),
194 }
195 }
196}