cpclib_runner/runner/
hspcompiler.rs

1use std::fmt::Display;
2
3use crate::delegated::{
4    ArchiveFormat, CompilableInformation, DownloadableInformation, ExecutableInformation,
5    GithubCompilableApplication, GithubInformation
6};
7
8pub const HSPC_CMD: &str = "hspcompiler";
9
10#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
11pub enum HspCompilerVersion {
12    #[default]
13    V_2_0 // V2_2_5
14}
15
16impl HspCompilerVersion {
17    pub fn get_command(&self) -> &str {
18        HSPC_CMD
19    }
20}
21impl GithubCompilableApplication for HspCompilerVersion {}
22
23impl Display for HspCompilerVersion {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        write!(f, "rasm {}", self.version_name())
26    }
27}
28
29impl GithubInformation for HspCompilerVersion {
30    fn version_name(&self) -> &'static str {
31        match self {
32            Self::V_2_0 => "v2.0"
33        }
34    }
35
36    fn project(&self) -> &'static str {
37        "hspcompiler"
38    }
39
40    fn owner(&self) -> &'static str {
41        "EdouardBERGE"
42    }
43
44    fn linux_key(&self) -> Option<&'static str> {
45        Some("Source code (zip)")
46    }
47
48    fn windows_key(&self) -> Option<&'static str> {
49        Some("compiler.exe")
50    }
51}
52
53impl ExecutableInformation for HspCompilerVersion {
54    fn target_os_folder(&self) -> &'static str {
55        match self {
56            Self::V_2_0 => "hspcompiler_2_0"
57        }
58    }
59
60    fn target_os_exec_fname(&self) -> &'static str {
61        #[cfg(target_os = "windows")]
62        return "compiler.exe";
63        #[cfg(target_os = "macos")]
64        unimplemented!();
65        #[cfg(target_os = "linux")]
66        return "hspcompiler";
67    }
68}
69
70impl CompilableInformation for HspCompilerVersion {
71    fn target_os_commands(&self) -> Option<&'static [&'static [&'static str]]> {
72        if cfg!(target_os = "linux") {
73            Some(&[&["gcc", "compiler.c", "-O2", "-o", "hspcompiler"]])
74        }
75        else {
76            None
77        }
78    }
79}
80
81impl DownloadableInformation for HspCompilerVersion {
82    fn target_os_archive_format(&self) -> ArchiveFormat {
83        #[cfg(target_os = "linux")]
84        return ArchiveFormat::Zip;
85        #[cfg(target_os = "windows")]
86        return ArchiveFormat::Raw;
87    }
88}