use std::
{
env,
process::Command,
};
fn main()
{
if env::var("WHY2_DEV_BYPASS").is_ok() { return; }
let client_feature = env::var("CARGO_FEATURE_CLIENT_BASE").is_ok();
let server_feature = env::var("CARGO_FEATURE_SERVER").is_ok();
let chat_feature = env::var("CARGO_FEATURE_CHAT").is_ok();
if chat_feature && !(client_feature || server_feature)
{
panic!("Do not enable `chat` directly - use `client` or `server`.");
}
if client_feature && server_feature
{
panic!
(
"Error: You are trying to enable both `client` and `server` features at the same time.\n\
By default, the 'client' feature is enabled.\n\n\
To install the SERVER, use:\n\
cargo install why2-chat --no-default-features --features server"
);
}
let config_dir = env::var("WHY2_CONFIG_DIR").unwrap_or_else(|_| "{HOME}/.config/WHY2".to_string());
println!("cargo:rustc-env=WHY2_CONFIG_DIR={config_dir}");
println!("cargo:rerun-if-env-changed=WHY2_CONFIG_DIR");
let git_hash = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| String::new());
println!("cargo:rustc-env=WHY2_GIT_HASH={git_hash}");
println!("cargo:rerun-if-changed=../.git/HEAD");
println!("cargo:rerun-if-changed=../.git/index");
println!("cargo:rustc-env=WHY2_SKIP_TOFU={}", env::var("WHY2_SKIP_TOFU").is_ok());
println!("cargo::rerun-if-env-changed=WHY2_SKIP_TOFU");
}