@@ -19,38 +19,42 @@ pub(crate) fn get(cargo_toml: Option<&ManifestPath>, target: Option<&str>) -> Ve
19
19
}
20
20
21
21
match get_rust_cfgs ( cargo_toml, target) {
22
- Ok ( rustc_cfgs) => res. extend ( rustc_cfgs. lines ( ) . map ( |it| it. parse ( ) . unwrap ( ) ) ) ,
23
- Err ( e) => tracing:: error!( "failed to get rustc cfgs: {:#}" , e) ,
22
+ Ok ( rustc_cfgs) => {
23
+ tracing:: debug!(
24
+ "rustc cfgs found: {:?}" ,
25
+ rustc_cfgs
26
+ . lines( )
27
+ . map( |it| it. parse:: <CfgFlag >( ) . map( |it| it. to_string( ) ) )
28
+ . collect:: <Vec <_>>( )
29
+ ) ;
30
+ res. extend ( rustc_cfgs. lines ( ) . filter_map ( |it| it. parse ( ) . ok ( ) ) ) ;
31
+ }
32
+ Err ( e) => tracing:: error!( "failed to get rustc cfgs: {e:?}" ) ,
24
33
}
25
34
26
35
res
27
36
}
28
37
29
38
fn get_rust_cfgs ( cargo_toml : Option < & ManifestPath > , target : Option < & str > ) -> Result < String > {
30
- let cargo_rust_cfgs = match cargo_toml {
31
- Some ( cargo_toml) => {
32
- let mut cargo_config = Command :: new ( toolchain:: cargo ( ) ) ;
33
- cargo_config
34
- . current_dir ( cargo_toml. parent ( ) )
35
- . args ( & [ "-Z" , "unstable-options" , "rustc" , "--print" , "cfg" ] )
36
- . env ( "RUSTC_BOOTSTRAP" , "1" ) ;
37
- if let Some ( target) = target {
38
- cargo_config. args ( & [ "--target" , target] ) ;
39
- }
40
- utf8_stdout ( cargo_config) . ok ( )
39
+ if let Some ( cargo_toml) = cargo_toml {
40
+ let mut cargo_config = Command :: new ( toolchain:: cargo ( ) ) ;
41
+ cargo_config
42
+ . current_dir ( cargo_toml. parent ( ) )
43
+ . args ( & [ "-Z" , "unstable-options" , "rustc" , "--print" , "cfg" ] )
44
+ . env ( "RUSTC_BOOTSTRAP" , "1" ) ;
45
+ if let Some ( target) = target {
46
+ cargo_config. args ( & [ "--target" , target] ) ;
41
47
}
42
- None => None ,
43
- } ;
44
- match cargo_rust_cfgs {
45
- Some ( stdout) => Ok ( stdout) ,
46
- None => {
47
- // using unstable cargo features failed, fall back to using plain rustc
48
- let mut cmd = Command :: new ( toolchain:: rustc ( ) ) ;
49
- cmd. args ( & [ "--print" , "cfg" , "-O" ] ) ;
50
- if let Some ( target) = target {
51
- cmd. args ( & [ "--target" , target] ) ;
52
- }
53
- utf8_stdout ( cmd)
48
+ match utf8_stdout ( cargo_config) {
49
+ Ok ( it) => return Ok ( it) ,
50
+ Err ( e) => tracing:: debug!( "{e:?}: falling back to querying rustc for cfgs" ) ,
54
51
}
55
52
}
53
+ // using unstable cargo features failed, fall back to using plain rustc
54
+ let mut cmd = Command :: new ( toolchain:: rustc ( ) ) ;
55
+ cmd. args ( & [ "--print" , "cfg" , "-O" ] ) ;
56
+ if let Some ( target) = target {
57
+ cmd. args ( & [ "--target" , target] ) ;
58
+ }
59
+ utf8_stdout ( cmd)
56
60
}
0 commit comments