use std::path::Path;
use crate::command::Command;
use crate::{bin_name, cwd, env_var};
#[track_caller]
pub fn clang() -> Clang {
Clang::new()
}
#[derive(Debug)]
#[must_use]
pub struct Clang {
cmd: Command,
}
crate::macros::impl_common_helpers!(Clang);
impl Clang {
#[track_caller]
pub fn new() -> Self {
let clang = env_var("CLANG");
let mut cmd = Command::new(clang);
cmd.arg("-L").arg(cwd());
Self { cmd }
}
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}
pub fn out_exe(&mut self, name: &str) -> &mut Self {
self.cmd.arg("-o");
self.cmd.arg(bin_name(name));
self
}
pub fn target(&mut self, target_triple: &str) -> &mut Self {
self.cmd.arg("-target");
self.cmd.arg(target_triple);
self
}
pub fn no_stdlib(&mut self) -> &mut Self {
self.cmd.arg("-nostdlib");
self
}
pub fn arch(&mut self, arch: &str) -> &mut Self {
self.cmd.arg(format!("-march={arch}"));
self
}
pub fn lto(&mut self, lto: &str) -> &mut Self {
self.cmd.arg(format!("-flto={lto}"));
self
}
pub fn use_ld(&mut self, ld: &str) -> &mut Self {
self.cmd.arg(format!("-fuse-ld={ld}"));
self
}
}