os_xtask_utils/
binutils.rs1use crate::{ext, Cargo, CommandExt};
2use std::{ffi::OsStr, process::Command};
3
4ext!(def; BinUtil);
5
6impl BinUtil {
7 fn new(which: impl AsRef<OsStr>) -> Self {
8 let which = which.as_ref();
9 let installed = Cargo::install().arg("--list").output().stdout;
10 let check = String::from_utf8_lossy(&installed)
11 .lines()
12 .filter_map(|line| {
13 if cfg!(target_os = "windows") {
14 line.trim().strip_suffix(".exe")
15 } else {
16 Some(line.trim())
17 }
18 })
19 .any(|line| OsStr::new(line) == which);
20 if !check {
21 Cargo::install().arg("cargo-binutils").invoke();
22 }
23 Self(Command::new(which))
24 }
25
26 #[inline]
27 pub fn objcopy() -> Self {
28 Self::new("rust-objcopy")
29 }
30
31 #[inline]
32 pub fn objdump() -> Self {
33 Self::new("rust-objdump")
34 }
35}