Skip to content

Commit a4c63fe

Browse files
committed
Auto merge of #13551 - epage:cfg, r=weihanglo
fix(cli): Skip tracing-chrome for platforms without 64bit atomics See rust-lang/rust#122054 I also created thoren-d/tracing-chrome#27
2 parents bc0ab3d + 307ad0c commit a4c63fe

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
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: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ fn main() {
4141
}
4242
}
4343

44-
fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
45-
#![allow(clippy::disallowed_methods)]
46-
44+
fn setup_logger() -> Option<ChromeFlushGuard> {
4745
use tracing_subscriber::prelude::*;
4846

4947
let env = tracing_subscriber::EnvFilter::from_env("CARGO_LOG");
@@ -53,17 +51,7 @@ fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
5351
.with_writer(std::io::stderr)
5452
.with_filter(env);
5553

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-
};
54+
let (profile_layer, profile_guard) = chrome_layer();
6755

6856
let registry = tracing_subscriber::registry()
6957
.with(fmt_layer)
@@ -73,6 +61,44 @@ fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
7361
profile_guard
7462
}
7563

64+
#[cfg(target_has_atomic = "64")]
65+
type ChromeFlushGuard = tracing_chrome::FlushGuard;
66+
#[cfg(target_has_atomic = "64")]
67+
fn chrome_layer<S>() -> (
68+
Option<tracing_chrome::ChromeLayer<S>>,
69+
Option<ChromeFlushGuard>,
70+
)
71+
where
72+
S: tracing::Subscriber
73+
+ for<'span> tracing_subscriber::registry::LookupSpan<'span>
74+
+ Send
75+
+ Sync,
76+
{
77+
#![allow(clippy::disallowed_methods)]
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)