2
2
3
3
use std:: env;
4
4
5
+ /// This macro creates the version string during compilation from the
6
+ /// current environment
5
7
#[ macro_export]
6
8
macro_rules! get_version_info {
7
9
( ) => { {
8
- let major = env!( "CARGO_PKG_VERSION_MAJOR" ) . parse:: <u8 >( ) . unwrap( ) ;
9
- let minor = env!( "CARGO_PKG_VERSION_MINOR" ) . parse:: <u8 >( ) . unwrap( ) ;
10
- let patch = env!( "CARGO_PKG_VERSION_PATCH" ) . parse:: <u16 >( ) . unwrap( ) ;
11
- let crate_name = String :: from( env!( "CARGO_PKG_NAME" ) ) ;
10
+ let major = std :: env!( "CARGO_PKG_VERSION_MAJOR" ) . parse:: <u8 >( ) . unwrap( ) ;
11
+ let minor = std :: env!( "CARGO_PKG_VERSION_MINOR" ) . parse:: <u8 >( ) . unwrap( ) ;
12
+ let patch = std :: env!( "CARGO_PKG_VERSION_PATCH" ) . parse:: <u16 >( ) . unwrap( ) ;
13
+ let crate_name = String :: from( std :: env!( "CARGO_PKG_NAME" ) ) ;
12
14
13
- let host_compiler = option_env!( "RUSTC_RELEASE_CHANNEL" ) . map( str :: to_string) ;
14
- let commit_hash = option_env!( "GIT_HASH" ) . map( str :: to_string) ;
15
- let commit_date = option_env!( "COMMIT_DATE" ) . map( str :: to_string) ;
15
+ let host_compiler = std :: option_env!( "RUSTC_RELEASE_CHANNEL" ) . map( str :: to_string) ;
16
+ let commit_hash = std :: option_env!( "GIT_HASH" ) . map( str :: to_string) ;
17
+ let commit_date = std :: option_env!( "COMMIT_DATE" ) . map( str :: to_string) ;
16
18
17
- VersionInfo {
19
+ $crate :: VersionInfo {
18
20
major,
19
21
minor,
20
22
patch,
@@ -26,6 +28,24 @@ macro_rules! get_version_info {
26
28
} } ;
27
29
}
28
30
31
+ /// This macro can be used in `build.rs` to automatically set the needed
32
+ /// environment values, namely `GIT_HASH`, `COMMIT_DATE` and
33
+ /// `RUSTC_RELEASE_CHANNEL`
34
+ #[ macro_export]
35
+ macro_rules! setup_version_info {
36
+ ( ) => { {
37
+ println!(
38
+ "cargo:rustc-env=GIT_HASH={}" ,
39
+ $crate:: get_commit_hash( ) . unwrap_or_default( )
40
+ ) ;
41
+ println!(
42
+ "cargo:rustc-env=COMMIT_DATE={}" ,
43
+ $crate:: get_commit_date( ) . unwrap_or_default( )
44
+ ) ;
45
+ println!( "cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}" , $crate:: get_channel( ) ) ;
46
+ } } ;
47
+ }
48
+
29
49
// some code taken and adapted from RLS and cargo
30
50
pub struct VersionInfo {
31
51
pub major : u8 ,
0 commit comments