Skip to content

Commit 255bee1

Browse files
committed
run-make-support: add clang and llvm-readobj command wrappers
1 parent 6c6b302 commit 255bee1

3 files changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}

‎src/tools/run-make-support/src/lib.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! as `object` or `wasmparser`, they can be re-exported and be made available through this library.
55
66
pubmod cc;
7+
pubmod clang;
8+
pubmod llvm_readobj;
79
pubmod run;
810
pubmod rustc;
911
pubmod rustdoc;
@@ -17,6 +19,8 @@ pub use regex;
1719
pubuse wasmparser;
1820

1921
pubuse cc::{cc, extra_c_flags, extra_cxx_flags,Cc};
22+
pubuse clang::{clang,Clang};
23+
pubuse llvm_readobj::{llvm_readobj,LlvmReadobj};
2024
pubuse run::{run, run_fail};
2125
pubuse rustc::{aux_build, rustc,Rustc};
2226
pubuse rustdoc::{bare_rustdoc, rustdoc,Rustdoc};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use std::env;
2+
use std::path::{Path,PathBuf};
3+
use std::process::Command;
4+
5+
usecrate::handle_failed_output;
6+
7+
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
8+
/// at `$LLVM_BIN_DIR/llvm-readobj`.
9+
pubfnllvm_readobj() -> LlvmReadobj{
10+
LlvmReadobj::new()
11+
}
12+
13+
/// A `llvm-readobj` invocation builder.
14+
#[derive(Debug)]
15+
pubstructLlvmReadobj{
16+
cmd:Command,
17+
}
18+
19+
crate::impl_common_helpers!(LlvmReadobj);
20+
21+
implLlvmReadobj{
22+
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
23+
/// at `$LLVM_BIN_DIR/llvm-readobj`.
24+
pubfnnew() -> Self{
25+
let llvm_bin_dir = env::var("LLVM_BIN_DIR")
26+
.expect("`LLVM_BIN_DIR` not specified, but this is required to find `llvm-readobj`");
27+
let llvm_bin_dir = PathBuf::from(llvm_bin_dir);
28+
let llvm_readobj = llvm_bin_dir.join("llvm-readobj");
29+
let cmd = Command::new(llvm_readobj);
30+
Self{ cmd }
31+
}
32+
33+
/// Provide an input file.
34+
pubfninput<P:AsRef<Path>>(&mutself,path:P) -> &mutSelf{
35+
self.cmd.arg(path.as_ref());
36+
self
37+
}
38+
39+
/// Pass `--file-header` to display file headers.
40+
pubfnfile_header(&mutself) -> &mutSelf{
41+
self.cmd.arg("--file-header");
42+
self
43+
}
44+
}

0 commit comments

Comments
 (0)