Skip to content

Commit 5cb5fc3

Browse files
committed
llvm-ar usage for build_native_static_lib
1 parent 89c1b4a commit 5cb5fc3

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3131
pub use clang::{clang, Clang};
3232
pub use diff::{diff, Diff};
3333
pub use llvm::{
34-
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
35-
LlvmProfdata, LlvmReadobj,
34+
llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck,
35+
LlvmObjdump, LlvmProfdata, LlvmReadobj,
3636
};
3737
pub use run::{cmd, run, run_fail, run_with_args};
3838
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};
@@ -333,7 +333,7 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
333333
obj_file.set_extension("");
334334
obj_file.set_extension("obj");
335335
}
336-
ar(&[obj_file], &lib_path);
336+
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
337337
path(lib_path)
338338
}
339339

src/tools/run-make-support/src/llvm.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub fn llvm_objdump() -> LlvmObjdump {
2929
LlvmObjdump::new()
3030
}
3131

32+
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
33+
/// at `$LLVM_BIN_DIR/llvm-ar`.
34+
pub fn llvm_ar() -> LlvmAr {
35+
LlvmAr::new()
36+
}
37+
3238
/// A `llvm-readobj` invocation builder.
3339
#[derive(Debug)]
3440
#[must_use]
@@ -57,10 +63,18 @@ pub struct LlvmObjdump {
5763
cmd: Command,
5864
}
5965

66+
/// A `llvm-ar` invocation builder.
67+
#[derive(Debug)]
68+
#[must_use]
69+
pub struct LlvmAr {
70+
cmd: Command,
71+
}
72+
6073
crate::impl_common_helpers!(LlvmReadobj);
6174
crate::impl_common_helpers!(LlvmProfdata);
6275
crate::impl_common_helpers!(LlvmFilecheck);
6376
crate::impl_common_helpers!(LlvmObjdump);
77+
crate::impl_common_helpers!(LlvmAr);
6478

6579
/// Generate the path to the bin directory of LLVM.
6680
#[must_use]
@@ -204,3 +218,26 @@ impl LlvmObjdump {
204218
self
205219
}
206220
}
221+
222+
impl LlvmAr {
223+
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
224+
/// at `$LLVM_BIN_DIR/llvm-ar`.
225+
pub fn new() -> Self {
226+
let llvm_ar = llvm_bin_dir().join("llvm-ar");
227+
let cmd = Command::new(llvm_ar);
228+
Self { cmd }
229+
}
230+
231+
pub fn obj_to_ar(&mut self) -> &mut Self {
232+
self.cmd.arg("rcus");
233+
self
234+
}
235+
236+
/// Provide an output, then an input file. Bundled in one function, as llvm-ar has
237+
/// no "--output"-style flag.
238+
pub fn output_input(&mut self, out: impl AsRef<Path>, input: impl AsRef<Path>) -> &mut Self {
239+
self.cmd.arg(out.as_ref());
240+
self.cmd.arg(input.as_ref());
241+
self
242+
}
243+
}

0 commit comments

Comments
 (0)