|
| 1 | +use std::env; |
| 2 | +use std::path::Path; |
| 3 | +use std::process::Command; |
| 4 | + |
| 5 | +usecrate::{bin_name, handle_failed_output, tmp_dir}; |
| 6 | + |
| 7 | +/// Construct a new `clang` invocation. `clang` is not always available for all targets. |
| 8 | +pubfnclang() -> Clang{ |
| 9 | +Clang::new() |
| 10 | +} |
| 11 | + |
| 12 | +/// A `clang` invocation builder. |
| 13 | +#[derive(Debug)] |
| 14 | +pubstructClang{ |
| 15 | +cmd:Command, |
| 16 | +} |
| 17 | + |
| 18 | +crate::impl_common_helpers!(Clang); |
| 19 | + |
| 20 | +implClang{ |
| 21 | +/// Construct a new `clang` invocation. `clang` is not always available for all targets. |
| 22 | +pubfnnew() -> Self{ |
| 23 | +let clang = |
| 24 | + env::var("CLANG").expect("`CLANG` not specified, but this is required to find `clang`"); |
| 25 | +let cmd = Command::new(clang); |
| 26 | +Self{ cmd } |
| 27 | +} |
| 28 | + |
| 29 | +/// Provide an input file. |
| 30 | +pubfninput<P:AsRef<Path>>(&mutself,path:P) -> &mutSelf{ |
| 31 | +self.cmd.arg(path.as_ref()); |
| 32 | +self |
| 33 | +} |
| 34 | + |
| 35 | +/// Specify the name of the executable. The executable will be placed under `$TMPDIR`, and the |
| 36 | +/// extension will be determined by [`bin_name`]. |
| 37 | +pubfnout_exe(&mutself,name:&str) -> &mutSelf{ |
| 38 | +self.cmd.arg("-o"); |
| 39 | +self.cmd.arg(tmp_dir().join(bin_name(name))); |
| 40 | +self |
| 41 | +} |
| 42 | + |
| 43 | +/// Specify which target triple clang should target. |
| 44 | +pubfntarget(&mutself,target_triple:&str) -> &mutSelf{ |
| 45 | +self.cmd.arg("-target"); |
| 46 | +self.cmd.arg(target_triple); |
| 47 | +self |
| 48 | +} |
| 49 | + |
| 50 | +/// Pass `-nostdlib` to disable linking the C standard library. |
| 51 | +pubfnno_stdlib(&mutself) -> &mutSelf{ |
| 52 | +self.cmd.arg("-nostdlib"); |
| 53 | +self |
| 54 | +} |
| 55 | + |
| 56 | +/// Specify architecture. |
| 57 | +pubfnarch(&mutself,arch:&str) -> &mutSelf{ |
| 58 | +self.cmd.arg(format!("-march={arch}")); |
| 59 | +self |
| 60 | +} |
| 61 | + |
| 62 | +/// Specify LTO settings. |
| 63 | +pubfnlto(&mutself,lto:&str) -> &mutSelf{ |
| 64 | +self.cmd.arg(format!("-flto={lto}")); |
| 65 | +self |
| 66 | +} |
| 67 | + |
| 68 | +/// Specify which ld to use. |
| 69 | +pubfnuse_ld(&mutself,ld:&str) -> &mutSelf{ |
| 70 | +self.cmd.arg(format!("-fuse-ld={ld}")); |
| 71 | +self |
| 72 | +} |
| 73 | +} |
0 commit comments