Skip to main content

leafbuild/buildsys-utils/toolchain/flags/
c.rs

1pub enum CSTD {
2    // ANSI = C89 = C90
3    ANSI,
4
5    C99,
6    GNU99,
7
8    C11,
9    GNU11,
10    // TODO: add more here as they come
11}
12
13impl CSTD {
14    pub(crate) fn as_str(&self) -> &'static str {
15        match self {
16            CSTD::ANSI => "ansi",
17            CSTD::C99 => "c99",
18            CSTD::GNU99 => "gnu99",
19            CSTD::C11 => "c11",
20            CSTD::GNU11 => "gnu11",
21        }
22    }
23}
24
25pub enum CFlag {
26    PositionIndependentCode,
27}
28
29pub enum CCompilationFlag {
30    FromString { s: String },
31    CSTD { std: CSTD },
32    IncludeDir { include_dir: String },
33
34    Flag { flag: CFlag },
35
36    None,
37}
38
39impl CCompilationFlag {
40    /// creates a flag from a string
41    fn from_string(s: impl Into<String>) -> Self {
42        Self::FromString { s: s.into() }
43    }
44}
45
46pub enum CLinkFlag {
47    FromString { s: String },
48    LibLocation { s: String },
49    Lib { name: String },
50    LibShared,
51    None,
52}
53
54impl CLinkFlag {
55    /// creates a flag from a string
56    fn from_string(s: impl Into<String>) -> Self {
57        Self::FromString { s: s.into() }
58    }
59}
60
61pub struct CCompilationFlags {
62    flags: Vec<CCompilationFlag>,
63}
64
65impl CCompilationFlags {
66    #[inline]
67    pub fn empty() -> Self {
68        Self::new(vec![])
69    }
70    #[inline]
71    pub fn new(flags: Vec<CCompilationFlag>) -> Self {
72        Self { flags }
73    }
74
75    pub(crate) fn into_flags_iter(self) -> impl Iterator<Item = CCompilationFlag> {
76        self.flags.into_iter()
77    }
78}
79
80pub struct CLinkFlags {
81    flags: Vec<CLinkFlag>,
82}
83
84impl CLinkFlags {
85    #[inline]
86    pub fn empty() -> Self {
87        Self::new(vec![])
88    }
89    #[inline]
90    pub fn new(flags: Vec<CLinkFlag>) -> Self {
91        Self { flags }
92    }
93
94    pub(crate) fn into_flags_iter(self) -> impl Iterator<Item = CLinkFlag> {
95        self.flags.into_iter()
96    }
97}