@@ -15,8 +15,18 @@ use bootstrap::{
15
15
human_readable_changes, t,
16
16
} ;
17
17
use build_helper:: ci:: CiEnv ;
18
-
18
+ #[ cfg( feature = "tracing" ) ]
19
+ use tracing:: * ;
20
+ #[ cfg( feature = "tracing" ) ]
21
+ use tracing_subscriber:: EnvFilter ;
22
+ #[ cfg( feature = "tracing" ) ]
23
+ use tracing_subscriber:: prelude:: * ;
24
+
25
+ #[ cfg_attr( feature = "tracing" , instrument( level = "trace" , name = "main" ) ) ]
19
26
fn main ( ) {
27
+ #[ cfg( feature = "tracing" ) ]
28
+ setup_tracing ( ) ;
29
+
20
30
let args = env:: args ( ) . skip ( 1 ) . collect :: < Vec < _ > > ( ) ;
21
31
22
32
if Flags :: try_parse_verbose_help ( & args) {
@@ -187,3 +197,28 @@ fn check_version(config: &Config) -> Option<String> {
187
197
188
198
Some ( msg)
189
199
}
200
+
201
+ // # Note on `tracing` usage in bootstrap
202
+ //
203
+ // Due to the conditional compilation via the `tracing` cargo feature, this means that `tracing`
204
+ // usages in bootstrap need to be also gated behind the `tracing` feature:
205
+ //
206
+ // - `tracing` macros (like `trace!`) and anything from `tracing`, `tracing_subscriber` and
207
+ // `tracing-tree` will need to be gated by `#[cfg(feature = "tracing")]`.
208
+ // - `tracing`'s `#[instrument(..)]` macro will need to be gated like `#![cfg_attr(feature =
209
+ // "tracing", instrument(..))]`.
210
+ #[ cfg( feature = "tracing" ) ]
211
+ fn setup_tracing ( ) {
212
+ let filter = EnvFilter :: from_env ( "BOOTSTRAP_TRACING" ) ;
213
+ let layer = tracing_tree:: HierarchicalLayer :: default ( )
214
+ . with_writer ( std:: io:: stderr)
215
+ . with_ansi ( true )
216
+ . with_targets ( true )
217
+ . with_bracketed_fields ( true )
218
+ . with_indent_amount ( 2 )
219
+ . with_indent_lines ( true ) ;
220
+ let subscriber = tracing_subscriber:: registry ( ) . with ( filter) . with ( layer) ;
221
+
222
+ tracing:: subscriber:: set_global_default ( subscriber) . unwrap ( ) ;
223
+ trace ! ( "tracing subscriber setup" ) ;
224
+ }
0 commit comments