#[cfg(target_os = "linux")]
#[macro_export]
macro_rules! note {
() => {
::std::println!("cargo:warning=\x1b[2K\r");
};
($($arg:tt)+) => {
::std::println!("cargo:warning=\x1b[2K\r \x1b[1m\x1b[36mInfo:\x1b[0m {}", ::std::format!($($arg)+))
}
}
#[cfg(not(target_os = "linux"))]
#[macro_export]
macro_rules! note {
() => {};
($($arg:tt)+) => {};
}
#[cfg(target_os = "linux")]
macro_rules! error {
($($arg:tt)+) => {
::std::println!("cargo:warning=\x1b[2K\r \x1b[1m\x1b[31mError:\x1b[0m {}", ::std::format!($($arg)+))
}
}
#[cfg(target_os = "linux")]
macro_rules! warn {
($($arg:tt)*) => {{
::std::println!("cargo:warning=\x1b[2K\r \x1b[1m\x1b[33mWarning:\x1b[0m {}", ::std::format!($($arg)*))
}};
}
#[cfg(target_os = "linux")]
macro_rules! debug {
($($arg:tt)*) => {{
static DEBUG_STATE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0);
if DEBUG_STATE.load(std::sync::atomic::Ordering::Relaxed) == 0 {
let val = ::std::env::var("MODULE_INFO_DEBUG")
.map(|v| v.to_lowercase() == "true")
.unwrap_or(false);
DEBUG_STATE.store(if val { 1 } else { 2 }, std::sync::atomic::Ordering::Relaxed);
}
if DEBUG_STATE.load(std::sync::atomic::Ordering::Relaxed) == 1 {
::std::println!("cargo:warning=\x1b[2K\r \x1b[1m\x1b[35mDebug:\x1b[0m {}", ::std::format!($($arg)*));
}
}};
}
#[cfg(all(feature = "embed-module-info", target_os = "linux"))]
#[macro_export]
macro_rules! get_module_info {
(@__extract $symbol:ident) => {{
extern "C" {
#[allow(non_upper_case_globals)]
static $symbol: u8;
}
unsafe { $crate::extract_module_info(&$symbol as *const u8) }
}};
(@__add_to_map $info_map:ident, $symbol:ident, $key:literal) => {{
if let Ok(value) = get_module_info!(@__extract $symbol) {
$info_map.insert($key.to_string(), value);
}
}};
(ModuleInfoField::Binary) => { get_module_info!(@__extract module_info_binary) };
(ModuleInfoField::Version) => { get_module_info!(@__extract module_info_version) };
(ModuleInfoField::ModuleVersion) => { get_module_info!(@__extract module_info_moduleVersion) };
(ModuleInfoField::Maintainer) => { get_module_info!(@__extract module_info_maintainer) };
(ModuleInfoField::Name) => { get_module_info!(@__extract module_info_name) };
(ModuleInfoField::Type) => { get_module_info!(@__extract module_info_type) };
(ModuleInfoField::Repo) => { get_module_info!(@__extract module_info_repo) };
(ModuleInfoField::Branch) => { get_module_info!(@__extract module_info_branch) };
(ModuleInfoField::Hash) => { get_module_info!(@__extract module_info_hash) };
(ModuleInfoField::Copyright) => { get_module_info!(@__extract module_info_copyright) };
(ModuleInfoField::Os) => { get_module_info!(@__extract module_info_os) };
(ModuleInfoField::OsVersion) => { get_module_info!(@__extract module_info_osVersion) };
() => {{
let mut info_map: ::std::collections::HashMap<::std::string::String, ::std::string::String> =
::std::collections::HashMap::with_capacity($crate::ModuleInfoField::count());
get_module_info!(@__add_to_map info_map, module_info_binary, "binary");
get_module_info!(@__add_to_map info_map, module_info_version, "version");
get_module_info!(@__add_to_map info_map, module_info_moduleVersion, "moduleVersion");
get_module_info!(@__add_to_map info_map, module_info_maintainer, "maintainer");
get_module_info!(@__add_to_map info_map, module_info_name, "name");
get_module_info!(@__add_to_map info_map, module_info_type, "type");
get_module_info!(@__add_to_map info_map, module_info_repo, "repo");
get_module_info!(@__add_to_map info_map, module_info_branch, "branch");
get_module_info!(@__add_to_map info_map, module_info_hash, "hash");
get_module_info!(@__add_to_map info_map, module_info_copyright, "copyright");
get_module_info!(@__add_to_map info_map, module_info_os, "os");
get_module_info!(@__add_to_map info_map, module_info_osVersion, "osVersion");
$crate::ModuleInfoResult::<::std::collections::HashMap<::std::string::String, ::std::string::String>>::Ok(info_map)
}};
}
#[cfg(any(not(feature = "embed-module-info"), not(target_os = "linux")))]
#[macro_export]
macro_rules! get_module_info {
(ModuleInfoField::Binary) => { $crate::__module_info_not_available!("Binary") };
(ModuleInfoField::Version) => { $crate::__module_info_not_available!("Version") };
(ModuleInfoField::ModuleVersion) => { $crate::__module_info_not_available!("ModuleVersion") };
(ModuleInfoField::Maintainer) => { $crate::__module_info_not_available!("Maintainer") };
(ModuleInfoField::Name) => { $crate::__module_info_not_available!("Name") };
(ModuleInfoField::Type) => { $crate::__module_info_not_available!("Type") };
(ModuleInfoField::Repo) => { $crate::__module_info_not_available!("Repo") };
(ModuleInfoField::Branch) => { $crate::__module_info_not_available!("Branch") };
(ModuleInfoField::Hash) => { $crate::__module_info_not_available!("Hash") };
(ModuleInfoField::Copyright) => { $crate::__module_info_not_available!("Copyright") };
(ModuleInfoField::Os) => { $crate::__module_info_not_available!("Os") };
(ModuleInfoField::OsVersion) => { $crate::__module_info_not_available!("OsVersion") };
() => {{
$crate::ModuleInfoResult::<::std::collections::HashMap<::std::string::String, ::std::string::String>>::Err(
$crate::ModuleInfoError::NotAvailable(
"Module info is only available on Linux platforms with embed-module-info feature enabled.".to_string(),
),
)
}};
}
#[cfg(any(not(feature = "embed-module-info"), not(target_os = "linux")))]
#[doc(hidden)]
#[macro_export]
macro_rules! __module_info_not_available {
($field:literal) => {{
$crate::ModuleInfoResult::<String>::Err($crate::ModuleInfoError::NotAvailable(format!(
"Module info field '{}' is only available on Linux platforms with embed-module-info feature enabled.",
$field
)))
}};
}