cuno_toolchain/host.rs
1//! The operating system cuno runs on, received as a value so that every
2//! platform's branch is tested on any machine (`docs/en/specs/architecture.md`,
3//! "Dependencies between crates").
4
5use cuno_core::NameCase;
6
7/// The host operating system, as far as finding tools cares.
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum HostOs {
10 /// Windows: executables end in `.exe`, and LLVM and Visual Studio have
11 /// standard install locations to look in.
12 Windows,
13 /// Any other system.
14 Other,
15}
16
17impl HostOs {
18 /// The system cuno itself was built for. Only the binary calls this.
19 pub fn current() -> HostOs {
20 if cfg!(windows) {
21 HostOs::Windows
22 } else {
23 HostOs::Other
24 }
25 }
26
27 /// How this system's file systems compare names: on Windows, without
28 /// regard to case.
29 pub fn name_case(self) -> NameCase {
30 match self {
31 HostOs::Windows => NameCase::Insensitive,
32 HostOs::Other => NameCase::Sensitive,
33 }
34 }
35
36 /// `name` as an executable file name on this system.
37 pub fn executable(self, name: &str) -> String {
38 match self {
39 HostOs::Windows => format!("{name}.exe"),
40 HostOs::Other => name.to_owned(),
41 }
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 /// Mutation: drop or misplace the `.exe` suffix; this test fails.
50 #[test]
51 fn executables_are_named_for_the_host() {
52 assert_eq!(HostOs::Windows.executable("clang"), "clang.exe");
53 assert_eq!(HostOs::Other.executable("clang"), "clang");
54 }
55}