@@ -8,7 +8,7 @@ macro_rules! get_version_info {
8
8
let patch = env!( "CARGO_PKG_VERSION_PATCH" ) . parse:: <u16 >( ) . unwrap( ) ;
9
9
let crate_name = String :: from( env!( "CARGO_PKG_NAME" ) ) ;
10
10
11
- let host_compiler = $crate :: get_channel ( ) ;
11
+ let host_compiler = option_env! ( "RUSTC_RELEASE_CHANNEL" ) . map ( str :: to_string ) ;
12
12
let commit_hash = option_env!( "GIT_HASH" ) . map( str :: to_string) ;
13
13
let commit_date = option_env!( "COMMIT_DATE" ) . map( str :: to_string) ;
14
14
@@ -79,15 +79,6 @@ impl std::fmt::Debug for VersionInfo {
79
79
}
80
80
}
81
81
82
- pub fn get_channel ( ) -> Option < String > {
83
- if let Ok ( channel) = env:: var ( "CFG_RELEASE_CHANNEL" ) {
84
- Some ( channel)
85
- } else {
86
- // we could ask ${RUSTC} -Vv and do some parsing and find out
87
- Some ( String :: from ( "nightly" ) )
88
- }
89
- }
90
-
91
82
pub fn get_commit_hash ( ) -> Option < String > {
92
83
std:: process:: Command :: new ( "git" )
93
84
. args ( & [ "rev-parse" , "--short" , "HEAD" ] )
@@ -104,6 +95,34 @@ pub fn get_commit_date() -> Option<String> {
104
95
. and_then ( |r| String :: from_utf8 ( r. stdout ) . ok ( ) )
105
96
}
106
97
98
+ pub fn get_channel ( ) -> Option < String > {
99
+ match env:: var ( "CFG_RELEASE_CHANNEL" ) {
100
+ Ok ( channel) => Some ( channel) ,
101
+ Err ( _) => {
102
+ // if that failed, try to ask rustc -V, do some parsing and find out
103
+ match std:: process:: Command :: new ( "rustc" )
104
+ . arg ( "-V" )
105
+ . output ( )
106
+ . ok ( )
107
+ . and_then ( |r| String :: from_utf8 ( r. stdout ) . ok ( ) )
108
+ {
109
+ Some ( rustc_output) => {
110
+ if rustc_output. contains ( "beta" ) {
111
+ Some ( String :: from ( "beta" ) )
112
+ } else if rustc_output. contains ( "stable" ) {
113
+ Some ( String :: from ( "stable" ) )
114
+ } else {
115
+ // default to nightly if we fail to parse
116
+ Some ( String :: from ( "nightly" ) )
117
+ }
118
+ } ,
119
+ // default to nightly
120
+ None => Some ( String :: from ( "nightly" ) ) ,
121
+ }
122
+ } ,
123
+ }
124
+ }
125
+
107
126
#[ cfg( test) ]
108
127
mod test {
109
128
use super :: * ;
0 commit comments