@ -9,20 +9,25 @@ fn main() {
println! ( "cargo:rustc-cfg=mysql" ) ;
println! ( "cargo:rustc-cfg=mysql" ) ;
#[ cfg(feature = " postgresql " ) ]
#[ cfg(feature = " postgresql " ) ]
println! ( "cargo:rustc-cfg=postgresql" ) ;
println! ( "cargo:rustc-cfg=postgresql" ) ;
#[ cfg(feature = " query_logger " ) ]
println! ( "cargo:rustc-cfg=query_logger" ) ;
#[ cfg(not(any(feature = " sqlite " , feature = " mysql " , feature = " postgresql " ))) ]
#[ cfg(not(any(feature = " sqlite " , feature = " mysql " , feature = " postgresql " ))) ]
compile_error! (
compile_error! (
"You need to enable one DB backend. To build with previous defaults do: cargo build --features sqlite"
"You need to enable one DB backend. To build with previous defaults do: cargo build --features sqlite"
) ;
) ;
#[ cfg(all(not(debug_assertions), feature = " query_logger " )) ]
compile_error! ( "Query Logging is only allowed during development, it is not intented for production usage!" ) ;
// Support $BWRS_VERSION for legacy compatibility, but default to $VW_VERSION.
// Support $BWRS_VERSION for legacy compatibility, but default to $VW_VERSION.
// If neither exist, read from git.
// If neither exist, read from git.
let maybe_vaultwarden_version =
let maybe_vaultwarden_version =
env ::var ( "VW_VERSION" ) . or_else ( | _ | env ::var ( "BWRS_VERSION" ) ) . or_else ( | _ | version_from_git_info ( ) ) ;
env ::var ( "VW_VERSION" ) . or_else ( | _ | env ::var ( "BWRS_VERSION" ) ) . or_else ( | _ | version_from_git_info ( ) ) ;
if let Ok ( version ) = maybe_vaultwarden_version {
if let Ok ( version ) = maybe_vaultwarden_version {
println! ( "cargo:rustc-env=VW_VERSION={ }", version) ;
println! ( "cargo:rustc-env=VW_VERSION={ version}" ) ;
println! ( "cargo:rustc-env=CARGO_PKG_VERSION={ }", version) ;
println! ( "cargo:rustc-env=CARGO_PKG_VERSION={ version}" ) ;
}
}
}
}
@ -47,29 +52,29 @@ fn version_from_git_info() -> Result<String, std::io::Error> {
// the current commit doesn't have an associated tag
// the current commit doesn't have an associated tag
let exact_tag = run ( & [ "git" , "describe" , "--abbrev=0" , "--tags" , "--exact-match" ] ) . ok ( ) ;
let exact_tag = run ( & [ "git" , "describe" , "--abbrev=0" , "--tags" , "--exact-match" ] ) . ok ( ) ;
if let Some ( ref exact ) = exact_tag {
if let Some ( ref exact ) = exact_tag {
println! ( "cargo:rustc-env=GIT_EXACT_TAG={ }", exact) ;
println! ( "cargo:rustc-env=GIT_EXACT_TAG={ exact}" ) ;
}
}
// The last available tag, equal to exact_tag when
// The last available tag, equal to exact_tag when
// the current commit is tagged
// the current commit is tagged
let last_tag = run ( & [ "git" , "describe" , "--abbrev=0" , "--tags" ] ) ? ;
let last_tag = run ( & [ "git" , "describe" , "--abbrev=0" , "--tags" ] ) ? ;
println! ( "cargo:rustc-env=GIT_LAST_TAG={ }", last_tag) ;
println! ( "cargo:rustc-env=GIT_LAST_TAG={ last_tag}" ) ;
// The current branch name
// The current branch name
let branch = run ( & [ "git" , "rev-parse" , "--abbrev-ref" , "HEAD" ] ) ? ;
let branch = run ( & [ "git" , "rev-parse" , "--abbrev-ref" , "HEAD" ] ) ? ;
println! ( "cargo:rustc-env=GIT_BRANCH={ }", branch) ;
println! ( "cargo:rustc-env=GIT_BRANCH={ branch}" ) ;
// The current git commit hash
// The current git commit hash
let rev = run ( & [ "git" , "rev-parse" , "HEAD" ] ) ? ;
let rev = run ( & [ "git" , "rev-parse" , "HEAD" ] ) ? ;
let rev_short = rev . get ( .. 8 ) . unwrap_or_default ( ) ;
let rev_short = rev . get ( .. 8 ) . unwrap_or_default ( ) ;
println! ( "cargo:rustc-env=GIT_REV={ }", rev_short) ;
println! ( "cargo:rustc-env=GIT_REV={ rev_short}" ) ;
// Combined version
// Combined version
if let Some ( exact ) = exact_tag {
if let Some ( exact ) = exact_tag {
Ok ( exact )
Ok ( exact )
} else if & branch ! = "main" & & & branch ! = "master" {
} else if & branch ! = "main" & & & branch ! = "master" {
Ok ( format! ( "{ }-{} ({})", last_tag , rev_short , branch ) )
Ok ( format! ( "{ last_tag}-{rev_short} ({branch})" ) )
} else {
} else {
Ok ( format! ( "{ }-{}", last_tag , rev_short ) )
Ok ( format! ( "{ last_tag}-{rev_short}" ) )
}
}
}
}