run_make_support/external_deps/c_cxx_compiler/
gcc.rs

1use std::path::Path;
2
3use crate::command::Command;
4
5/// Construct a gcc invocation.
6///
7/// WARNING: This assumes *a* `gcc` exists in the environment and is suitable for use.
8#[track_caller]
9pub fn gcc() -> Gcc {
10    Gcc::new()
11}
12
13/// A specific `gcc`.
14#[derive(Debug)]
15#[must_use]
16pub struct Gcc {
17    cmd: Command,
18}
19
20crate::macros::impl_common_helpers!(Gcc);
21
22impl Gcc {
23    /// Construct a `gcc` invocation. This assumes that *a* suitable `gcc` is available in the
24    /// environment.
25    ///
26    /// Note that this does **not** prepopulate the `gcc` invocation with `CC_DEFAULT_FLAGS`.
27    #[track_caller]
28    pub fn new() -> Self {
29        let cmd = Command::new("gcc");
30        Self { cmd }
31    }
32
33    /// Specify path of the input file.
34    pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
35        self.cmd.arg(path.as_ref());
36        self
37    }
38
39    /// Adds directories to the list that the linker searches for libraries.
40    /// Equivalent to `-L`.
41    pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
42        self.cmd.arg("-L");
43        self.cmd.arg(path.as_ref());
44        self
45    }
46
47    /// Specify `-o`.
48    pub fn out_exe(&mut self, name: &str) -> &mut Self {
49        self.cmd.arg("-o");
50        self.cmd.arg(name);
51        self
52    }
53
54    /// Specify path of the output binary.
55    pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
56        self.cmd.arg("-o");
57        self.cmd.arg(path.as_ref());
58        self
59    }
60
61    /// Optimize the output at `-O3`.
62    pub fn optimize(&mut self) -> &mut Self {
63        self.cmd.arg("-O3");
64        self
65    }
66}