run_make_support/external_deps/
clang.rs
1use std::path::Path;
2
3use crate::command::Command;
4use crate::{bin_name, cwd, env_var};
5
6#[track_caller]
8pub fn clang() -> Clang {
9 Clang::new()
10}
11
12#[derive(Debug)]
14#[must_use]
15pub struct Clang {
16 cmd: Command,
17}
18
19crate::macros::impl_common_helpers!(Clang);
20
21impl Clang {
22 #[track_caller]
24 pub fn new() -> Self {
25 let clang = env_var("CLANG");
26 let mut cmd = Command::new(clang);
27 cmd.arg("-L").arg(cwd());
28 Self { cmd }
29 }
30
31 pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
33 self.cmd.arg(path.as_ref());
34 self
35 }
36
37 pub fn out_exe(&mut self, name: &str) -> &mut Self {
40 self.cmd.arg("-o");
41 self.cmd.arg(bin_name(name));
42 self
43 }
44
45 pub fn target(&mut self, target_triple: &str) -> &mut Self {
47 self.cmd.arg("-target");
48 self.cmd.arg(target_triple);
49 self
50 }
51
52 pub fn no_stdlib(&mut self) -> &mut Self {
54 self.cmd.arg("-nostdlib");
55 self
56 }
57
58 pub fn arch(&mut self, arch: &str) -> &mut Self {
60 self.cmd.arg(format!("-march={arch}"));
61 self
62 }
63
64 pub fn lto(&mut self, lto: &str) -> &mut Self {
66 self.cmd.arg(format!("-flto={lto}"));
67 self
68 }
69
70 pub fn use_ld(&mut self, ld: &str) -> &mut Self {
72 self.cmd.arg(format!("-fuse-ld={ld}"));
73 self
74 }
75}