Skip to content

Commit f5df0df

Browse files
committed
fix(cli): Skip tracing-chrome for platforms without 64bit atomics
1 parent 00b9882 commit f5df0df

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,15 @@ time.workspace = true
199199
toml.workspace = true
200200
toml_edit.workspace = true
201201
tracing.workspace = true
202-
tracing-chrome.workspace = true
203202
tracing-subscriber.workspace = true
204203
unicase.workspace = true
205204
unicode-width.workspace = true
206205
url.workspace = true
207206
walkdir.workspace = true
208207

208+
[target.'cfg(target_has_atomic = "64")'.dependencies]
209+
tracing-chrome.workspace = true
210+
209211
[target.'cfg(target_os = "linux")'.dependencies]
210212
cargo-credential-libsecret.workspace = true
211213

src/bin/cargo/main.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() {
4141
}
4242
}
4343

44-
fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
44+
fn setup_logger() -> Option<ChromeFlushGuard> {
4545
#![allow(clippy::disallowed_methods)]
4646

4747
use tracing_subscriber::prelude::*;
@@ -53,17 +53,7 @@ fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
5353
.with_writer(std::io::stderr)
5454
.with_filter(env);
5555

56-
let (profile_layer, profile_guard) =
57-
if env_to_bool(std::env::var_os("CARGO_LOG_PROFILE").as_deref()) {
58-
let capture_args =
59-
env_to_bool(std::env::var_os("CARGO_LOG_PROFILE_CAPTURE_ARGS").as_deref());
60-
let (layer, guard) = tracing_chrome::ChromeLayerBuilder::new()
61-
.include_args(capture_args)
62-
.build();
63-
(Some(layer), Some(guard))
64-
} else {
65-
(None, None)
66-
};
56+
let (profile_layer, profile_guard) = chrome_layer();
6757

6858
let registry = tracing_subscriber::registry()
6959
.with(fmt_layer)
@@ -73,6 +63,42 @@ fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
7363
profile_guard
7464
}
7565

66+
#[cfg(target_has_atomic = "64")]
67+
type ChromeFlushGuard = tracing_chrome::FlushGuard;
68+
#[cfg(target_has_atomic = "64")]
69+
fn chrome_layer<S>() -> (
70+
Option<tracing_chrome::ChromeLayer<S>>,
71+
Option<ChromeFlushGuard>,
72+
)
73+
where
74+
S: tracing::Subscriber
75+
+ for<'span> tracing_subscriber::registry::LookupSpan<'span>
76+
+ Send
77+
+ Sync,
78+
{
79+
if env_to_bool(std::env::var_os("CARGO_LOG_PROFILE").as_deref()) {
80+
let capture_args =
81+
env_to_bool(std::env::var_os("CARGO_LOG_PROFILE_CAPTURE_ARGS").as_deref());
82+
let (layer, guard) = tracing_chrome::ChromeLayerBuilder::new()
83+
.include_args(capture_args)
84+
.build();
85+
(Some(layer), Some(guard))
86+
} else {
87+
(None, None)
88+
}
89+
}
90+
91+
#[cfg(not(target_has_atomic = "64"))]
92+
type ChromeFlushGuard = ();
93+
#[cfg(not(target_has_atomic = "64"))]
94+
fn chrome_layer() -> (
95+
Option<tracing_subscriber::layer::Identity>,
96+
Option<ChromeFlushGuard>,
97+
) {
98+
(None, None)
99+
}
100+
101+
#[cfg(target_has_atomic = "64")]
76102
fn env_to_bool(os: Option<&OsStr>) -> bool {
77103
match os.and_then(|os| os.to_str()) {
78104
Some("1") | Some("true") => true,

0 commit comments

Comments
 (0)