mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 22:30:03 +00:00
Investigate incorrect target detection (#1376)
* detect-targets: add debug tracing See #1375. * Add new feature `tracing` & `cli-tracing` to `detect-targets Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix clippy lints Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Co-authored-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
680accd0d3
commit
2db8e254bc
7 changed files with 49 additions and 12 deletions
|
@ -202,6 +202,7 @@ pub fn logging(log_level: LevelFilter, json_output: bool) {
|
|||
"binstalk_registry",
|
||||
"cargo_binstall",
|
||||
"cargo_toml_workspace",
|
||||
"detect_targets",
|
||||
"simple_git",
|
||||
]);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ binstalk-types = { version = "0.5.0", path = "../binstalk-types" }
|
|||
cargo-toml-workspace = { version = "1.0.0", path = "../cargo-toml-workspace" }
|
||||
command-group = { version = "2.1.0", features = ["with-tokio"] }
|
||||
compact_str = { version = "0.7.0", features = ["serde"] }
|
||||
detect-targets = { version = "0.1.11", path = "../detect-targets" }
|
||||
detect-targets = { version = "0.1.11", path = "../detect-targets", features = ["tracing"] }
|
||||
either = "1.8.1"
|
||||
itertools = "0.11.0"
|
||||
jobslot = { version = "0.2.11", features = ["tokio"] }
|
||||
|
|
|
@ -11,9 +11,15 @@ license = "Apache-2.0 OR MIT"
|
|||
|
||||
[dependencies]
|
||||
tokio = { version = "1.28.2", features = ["rt", "process", "sync"], default-features = false }
|
||||
tracing = { version = "0.1.37", optional = true }
|
||||
tracing-subscriber = { version = "0.3.17", features = ["fmt"], default-features = false, optional = true }
|
||||
cfg-if = "1.0.0"
|
||||
guess_host_triple = "0.1.3"
|
||||
|
||||
[features]
|
||||
tracing = ["dep:tracing"]
|
||||
cli-logging = ["tracing", "dep:tracing-subscriber"]
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
windows-sys = { version = "0.48.0", features = ["Win32_System_Threading", "Win32_System_SystemInformation", "Win32_Foundation"] }
|
||||
windows-dll = { version = "0.4.1", features = ["windows"], default-features = false }
|
||||
|
|
|
@ -7,6 +7,8 @@ use std::{
|
|||
|
||||
use cfg_if::cfg_if;
|
||||
use tokio::process::Command;
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::debug;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_os = "linux")] {
|
||||
|
@ -32,10 +34,14 @@ cfg_if! {
|
|||
/// Check [this issue](https://github.com/ryankurte/cargo-binstall/issues/155)
|
||||
/// for more information.
|
||||
pub async fn detect_targets() -> Vec<String> {
|
||||
let target = get_target_from_rustc().await.unwrap_or_else(|| {
|
||||
guess_host_triple::guess_host_triple()
|
||||
.unwrap_or(crate::TARGET)
|
||||
.to_string()
|
||||
let target = get_target_from_rustc().await;
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("get_target_from_rustc()={target:?}");
|
||||
let target = target.unwrap_or_else(|| {
|
||||
let target = guess_host_triple::guess_host_triple();
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("guess_host_triple::guess_host_triple()={target:?}");
|
||||
target.unwrap_or(crate::TARGET).to_string()
|
||||
});
|
||||
|
||||
cfg_if! {
|
||||
|
|
|
@ -4,6 +4,8 @@ use std::{
|
|||
};
|
||||
|
||||
use tokio::{process::Command, task};
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::debug;
|
||||
|
||||
pub(super) async fn detect_targets(target: String) -> Vec<String> {
|
||||
let (prefix, postfix) = target
|
||||
|
@ -79,12 +81,25 @@ async fn get_ld_flavor(cmd: &str) -> Option<Libc> {
|
|||
status,
|
||||
stdout,
|
||||
stderr,
|
||||
} = Command::new(cmd)
|
||||
} = match Command::new(cmd)
|
||||
.arg("--version")
|
||||
.stdin(Stdio::null())
|
||||
.output()
|
||||
.await
|
||||
.ok()?;
|
||||
{
|
||||
Ok(output) => output,
|
||||
Err(_err) => {
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("Running `{cmd} --version`: err={_err:?}");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
let stdout = String::from_utf8_lossy(&stdout);
|
||||
let stderr = String::from_utf8_lossy(&stderr);
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("`{cmd} --version`: status={status}, stdout='{stdout}', stderr='{stderr}'");
|
||||
|
||||
const ALPINE_GCOMPAT: &str = r#"This is the gcompat ELF interpreter stub.
|
||||
You are not meant to run this directly.
|
||||
|
@ -93,16 +108,14 @@ You are not meant to run this directly.
|
|||
if status.success() {
|
||||
// Executing glibc ldd or /lib/ld-linux-{cpu_arch}.so.1 will always
|
||||
// succeeds.
|
||||
String::from_utf8_lossy(&stdout)
|
||||
.contains("GLIBC")
|
||||
.then_some(Libc::Gnu)
|
||||
stdout.contains("GLIBC").then_some(Libc::Gnu)
|
||||
} else if status.code() == Some(1) {
|
||||
// On Alpine, executing both the gcompat glibc and the ldd and
|
||||
// /lib/ld-musl-{cpu_arch}.so.1 will fail with exit status 1.
|
||||
if str::from_utf8(&stdout).as_deref() == Ok(ALPINE_GCOMPAT) {
|
||||
if stdout == ALPINE_GCOMPAT {
|
||||
// Alpine's gcompat package will output ALPINE_GCOMPAT to stdout
|
||||
Some(Libc::Gnu)
|
||||
} else if String::from_utf8_lossy(&stderr).contains("musl libc") {
|
||||
} else if stderr.contains("musl libc") {
|
||||
// Alpine/s ldd and musl dynlib will output to stderr
|
||||
Some(Libc::Musl)
|
||||
} else {
|
||||
|
@ -120,6 +133,9 @@ You are not meant to run this directly.
|
|||
.await
|
||||
.ok()?;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("`{cmd} --version`: status={status}");
|
||||
|
||||
status.success().then_some(Libc::Gnu)
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -4,6 +4,12 @@ use detect_targets::detect_targets;
|
|||
use tokio::runtime;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
#[cfg(feature = "cli-logging")]
|
||||
tracing_subscriber::fmt::fmt()
|
||||
.with_max_level(tracing::Level::TRACE)
|
||||
.with_writer(std::io::stderr)
|
||||
.init();
|
||||
|
||||
let targets = runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue