run-make-support: add llvm-dis and llvm-objcopy

This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-10-18 17:34:11 +08:00
parent 562d08ee27
commit ef743af119
2 changed files with 73 additions and 4 deletions

View File

@ -60,6 +60,18 @@ pub fn llvm_pdbutil() -> LlvmPdbutil {
LlvmPdbutil::new()
}
/// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
/// at `$LLVM_BIN_DIR/llvm-dis`.
pub fn llvm_dis() -> LlvmDis {
LlvmDis::new()
}
/// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
/// at `$LLVM_BIN_DIR/llvm-objcopy`.
pub fn llvm_objcopy() -> LlvmObjcopy {
LlvmObjcopy::new()
}
/// A `llvm-readobj` invocation builder.
#[derive(Debug)]
#[must_use]
@ -123,6 +135,20 @@ pub struct LlvmPdbutil {
cmd: Command,
}
/// A `llvm-dis` invocation builder.
#[derive(Debug)]
#[must_use]
pub struct LlvmDis {
cmd: Command,
}
/// A `llvm-objcopy` invocation builder.
#[derive(Debug)]
#[must_use]
pub struct LlvmObjcopy {
cmd: Command,
}
crate::macros::impl_common_helpers!(LlvmReadobj);
crate::macros::impl_common_helpers!(LlvmProfdata);
crate::macros::impl_common_helpers!(LlvmFilecheck);
@ -132,6 +158,8 @@ crate::macros::impl_common_helpers!(LlvmNm);
crate::macros::impl_common_helpers!(LlvmBcanalyzer);
crate::macros::impl_common_helpers!(LlvmDwarfdump);
crate::macros::impl_common_helpers!(LlvmPdbutil);
crate::macros::impl_common_helpers!(LlvmDis);
crate::macros::impl_common_helpers!(LlvmObjcopy);
/// Generate the path to the bin directory of LLVM.
#[must_use]
@ -390,3 +418,41 @@ impl LlvmPdbutil {
self
}
}
impl LlvmObjcopy {
/// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
/// at `$LLVM_BIN_DIR/llvm-objcopy`.
pub fn new() -> Self {
let llvm_objcopy = llvm_bin_dir().join("llvm-objcopy");
let cmd = Command::new(llvm_objcopy);
Self { cmd }
}
/// Dump the contents of `section` into the file at `path`.
#[track_caller]
pub fn dump_section<S: AsRef<str>, P: AsRef<Path>>(
&mut self,
section_name: S,
path: P,
) -> &mut Self {
self.cmd.arg("--dump-section");
self.cmd.arg(format!("{}={}", section_name.as_ref(), path.as_ref().to_str().unwrap()));
self
}
}
impl LlvmDis {
/// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
/// at `$LLVM_BIN_DIR/llvm-dis`.
pub fn new() -> Self {
let llvm_dis = llvm_bin_dir().join("llvm-dis");
let cmd = Command::new(llvm_dis);
Self { cmd }
}
/// Provide an input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}
}

View File

@ -49,14 +49,17 @@ pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rust
// These rely on external dependencies.
pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
pub use c_build::{build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_optimized, build_native_static_lib_cxx};
pub use c_build::{
build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_cxx,
build_native_static_lib_optimized,
};
pub use cargo::cargo;
pub use clang::{clang, Clang};
pub use htmldocck::htmldocck;
pub use llvm::{
llvm_ar, llvm_bcanalyzer, llvm_dwarfdump, llvm_filecheck, llvm_nm, llvm_objdump, llvm_profdata,
llvm_readobj, LlvmAr, LlvmBcanalyzer, LlvmDwarfdump, LlvmFilecheck, LlvmNm, LlvmObjdump,
LlvmProfdata, LlvmReadobj,
llvm_ar, llvm_bcanalyzer, llvm_dis, llvm_dwarfdump, llvm_filecheck, llvm_nm, llvm_objcopy,
llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmBcanalyzer, LlvmDis, LlvmDwarfdump,
LlvmFilecheck, LlvmNm, LlvmObjcopy, LlvmObjdump, LlvmProfdata, LlvmReadobj,
};
pub use python::python_command;
pub use rustc::{aux_build, bare_rustc, rustc, rustc_path, Rustc};