mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 04:58:42 +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
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -833,6 +833,8 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"guess_host_triple",
|
"guess_host_triple",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
"windows-dll",
|
"windows-dll",
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
|
@ -202,6 +202,7 @@ pub fn logging(log_level: LevelFilter, json_output: bool) {
|
||||||
"binstalk_registry",
|
"binstalk_registry",
|
||||||
"cargo_binstall",
|
"cargo_binstall",
|
||||||
"cargo_toml_workspace",
|
"cargo_toml_workspace",
|
||||||
|
"detect_targets",
|
||||||
"simple_git",
|
"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" }
|
cargo-toml-workspace = { version = "1.0.0", path = "../cargo-toml-workspace" }
|
||||||
command-group = { version = "2.1.0", features = ["with-tokio"] }
|
command-group = { version = "2.1.0", features = ["with-tokio"] }
|
||||||
compact_str = { version = "0.7.0", features = ["serde"] }
|
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"
|
either = "1.8.1"
|
||||||
itertools = "0.11.0"
|
itertools = "0.11.0"
|
||||||
jobslot = { version = "0.2.11", features = ["tokio"] }
|
jobslot = { version = "0.2.11", features = ["tokio"] }
|
||||||
|
|
|
@ -11,9 +11,15 @@ license = "Apache-2.0 OR MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.28.2", features = ["rt", "process", "sync"], default-features = false }
|
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"
|
cfg-if = "1.0.0"
|
||||||
guess_host_triple = "0.1.3"
|
guess_host_triple = "0.1.3"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
tracing = ["dep:tracing"]
|
||||||
|
cli-logging = ["tracing", "dep:tracing-subscriber"]
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
windows-sys = { version = "0.48.0", features = ["Win32_System_Threading", "Win32_System_SystemInformation", "Win32_Foundation"] }
|
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 }
|
windows-dll = { version = "0.4.1", features = ["windows"], default-features = false }
|
||||||
|
|
|
@ -7,6 +7,8 @@ use std::{
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(target_os = "linux")] {
|
if #[cfg(target_os = "linux")] {
|
||||||
|
@ -32,10 +34,14 @@ cfg_if! {
|
||||||
/// Check [this issue](https://github.com/ryankurte/cargo-binstall/issues/155)
|
/// Check [this issue](https://github.com/ryankurte/cargo-binstall/issues/155)
|
||||||
/// for more information.
|
/// for more information.
|
||||||
pub async fn detect_targets() -> Vec<String> {
|
pub async fn detect_targets() -> Vec<String> {
|
||||||
let target = get_target_from_rustc().await.unwrap_or_else(|| {
|
let target = get_target_from_rustc().await;
|
||||||
guess_host_triple::guess_host_triple()
|
#[cfg(feature = "tracing")]
|
||||||
.unwrap_or(crate::TARGET)
|
debug!("get_target_from_rustc()={target:?}");
|
||||||
.to_string()
|
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! {
|
cfg_if! {
|
||||||
|
|
|
@ -4,6 +4,8 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use tokio::{process::Command, task};
|
use tokio::{process::Command, task};
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
pub(super) async fn detect_targets(target: String) -> Vec<String> {
|
pub(super) async fn detect_targets(target: String) -> Vec<String> {
|
||||||
let (prefix, postfix) = target
|
let (prefix, postfix) = target
|
||||||
|
@ -79,12 +81,25 @@ async fn get_ld_flavor(cmd: &str) -> Option<Libc> {
|
||||||
status,
|
status,
|
||||||
stdout,
|
stdout,
|
||||||
stderr,
|
stderr,
|
||||||
} = Command::new(cmd)
|
} = match Command::new(cmd)
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.output()
|
.output()
|
||||||
.await
|
.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.
|
const ALPINE_GCOMPAT: &str = r#"This is the gcompat ELF interpreter stub.
|
||||||
You are not meant to run this directly.
|
You are not meant to run this directly.
|
||||||
|
@ -93,16 +108,14 @@ You are not meant to run this directly.
|
||||||
if status.success() {
|
if status.success() {
|
||||||
// Executing glibc ldd or /lib/ld-linux-{cpu_arch}.so.1 will always
|
// Executing glibc ldd or /lib/ld-linux-{cpu_arch}.so.1 will always
|
||||||
// succeeds.
|
// succeeds.
|
||||||
String::from_utf8_lossy(&stdout)
|
stdout.contains("GLIBC").then_some(Libc::Gnu)
|
||||||
.contains("GLIBC")
|
|
||||||
.then_some(Libc::Gnu)
|
|
||||||
} else if status.code() == Some(1) {
|
} else if status.code() == Some(1) {
|
||||||
// On Alpine, executing both the gcompat glibc and the ldd and
|
// On Alpine, executing both the gcompat glibc and the ldd and
|
||||||
// /lib/ld-musl-{cpu_arch}.so.1 will fail with exit status 1.
|
// /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
|
// Alpine's gcompat package will output ALPINE_GCOMPAT to stdout
|
||||||
Some(Libc::Gnu)
|
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
|
// Alpine/s ldd and musl dynlib will output to stderr
|
||||||
Some(Libc::Musl)
|
Some(Libc::Musl)
|
||||||
} else {
|
} else {
|
||||||
|
@ -120,6 +133,9 @@ You are not meant to run this directly.
|
||||||
.await
|
.await
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
debug!("`{cmd} --version`: status={status}");
|
||||||
|
|
||||||
status.success().then_some(Libc::Gnu)
|
status.success().then_some(Libc::Gnu)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -4,6 +4,12 @@ use detect_targets::detect_targets;
|
||||||
use tokio::runtime;
|
use tokio::runtime;
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
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()
|
let targets = runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()?
|
.build()?
|
||||||
|
|
Loading…
Add table
Reference in a new issue