From 307ad0c4966dcde99535d0d029e5ed674d43b637 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 6 Mar 2024 10:35:58 -0600 Subject: [PATCH] fix(cli): Skip tracing-chrome for platforms without 64bit atomics --- Cargo.toml | 4 +++- src/bin/cargo/main.rs | 54 ++++++++++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 277c72b80f7..ddb9b59aac3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -199,13 +199,15 @@ time.workspace = true toml.workspace = true toml_edit.workspace = true tracing.workspace = true -tracing-chrome.workspace = true tracing-subscriber.workspace = true unicase.workspace = true unicode-width.workspace = true url.workspace = true walkdir.workspace = true +[target.'cfg(target_has_atomic = "64")'.dependencies] +tracing-chrome.workspace = true + [target.'cfg(target_os = "linux")'.dependencies] cargo-credential-libsecret.workspace = true diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index a2147b4d037..ea4f899f9fd 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -41,9 +41,7 @@ fn main() { } } -fn setup_logger() -> Option { - #![allow(clippy::disallowed_methods)] - +fn setup_logger() -> Option { use tracing_subscriber::prelude::*; let env = tracing_subscriber::EnvFilter::from_env("CARGO_LOG"); @@ -53,17 +51,7 @@ fn setup_logger() -> Option { .with_writer(std::io::stderr) .with_filter(env); - let (profile_layer, profile_guard) = - if env_to_bool(std::env::var_os("CARGO_LOG_PROFILE").as_deref()) { - let capture_args = - env_to_bool(std::env::var_os("CARGO_LOG_PROFILE_CAPTURE_ARGS").as_deref()); - let (layer, guard) = tracing_chrome::ChromeLayerBuilder::new() - .include_args(capture_args) - .build(); - (Some(layer), Some(guard)) - } else { - (None, None) - }; + let (profile_layer, profile_guard) = chrome_layer(); let registry = tracing_subscriber::registry() .with(fmt_layer) @@ -73,6 +61,44 @@ fn setup_logger() -> Option { profile_guard } +#[cfg(target_has_atomic = "64")] +type ChromeFlushGuard = tracing_chrome::FlushGuard; +#[cfg(target_has_atomic = "64")] +fn chrome_layer() -> ( + Option>, + Option, +) +where + S: tracing::Subscriber + + for<'span> tracing_subscriber::registry::LookupSpan<'span> + + Send + + Sync, +{ + #![allow(clippy::disallowed_methods)] + + if env_to_bool(std::env::var_os("CARGO_LOG_PROFILE").as_deref()) { + let capture_args = + env_to_bool(std::env::var_os("CARGO_LOG_PROFILE_CAPTURE_ARGS").as_deref()); + let (layer, guard) = tracing_chrome::ChromeLayerBuilder::new() + .include_args(capture_args) + .build(); + (Some(layer), Some(guard)) + } else { + (None, None) + } +} + +#[cfg(not(target_has_atomic = "64"))] +type ChromeFlushGuard = (); +#[cfg(not(target_has_atomic = "64"))] +fn chrome_layer() -> ( + Option, + Option, +) { + (None, None) +} + +#[cfg(target_has_atomic = "64")] fn env_to_bool(os: Option<&OsStr>) -> bool { match os.and_then(|os| os.to_str()) { Some("1") | Some("true") => true,