mod unwind;
#[macro_export]
macro_rules! manifest {
(
id: $id:literal,
side: $side:ident
$(, version: $version:literal)?
$(, name: $name:literal)?
$(, description: $description:literal)?
$(, authors: [$($author:literal),* $(,)?])?
$(, license: $license:literal)?
$(, homepage: $homepage:literal)?
$(, join: $join:expr)?
$(, reload: $reload:expr)?
$(, requires: [$($req:literal => $range:literal),* $(,)?])?
$(, after: [$($after:literal),* $(,)?])?
$(, recommends: [$($rec:literal => $rec_range:literal),* $(,)?])?
$(, breaks: [$($breaks:literal => $breaks_range:literal),* $(,)?])?
$(, replaces: [$($replaces:literal),* $(,)?])?
$(, was: [$($was:literal),* $(,)?])?
$(, points: [$($point:ty),* $(,)?])?
$(, events: [$($event:ty),* $(,)?])?
$(, calls: [$($call:ty),* $(,)?])?
$(, builds: [$({
side: $bside:ident,
guid: $guid:literal,
age: $age:literal,
symbols: [$($sym:literal => $rva:expr),* $(,)?]
$(, constants: [$($constant:literal => $value:expr),* $(,)?])? $(,)?
}),* $(,)?])?
$(,)?
) => {{
const _: () = ::core::assert!($crate::abi::is_valid_id($id), "a mod id is <author>.<name>, each of [a-z0-9-]");
$($(const _: () = ::core::assert!(
<$event as $crate::services::ModEvent>::DESCRIBED,
"an event's schema cannot describe a field's type: derive `Shape` for it",
);)*)?
$($(const _: () = ::core::assert!($crate::abi::is_valid_former_id($replaces), "a replaced mod id is <author>.<name> or [a-z0-9-]+");)*)?
$($(const _: () = ::core::assert!($crate::abi::is_valid_former_id($was), "a former mod id is <author>.<name> or [a-z0-9-]+");)*)?
static DEPENDENCIES: &[$crate::abi::Dependency] = &[
$($($crate::abi::Dependency {
id: $crate::abi::Str::new($req),
range: $crate::abi::Str::new($range),
relation: $crate::abi::Relation::REQUIRES,
},)*)?
$($($crate::abi::Dependency {
id: $crate::abi::Str::new($after),
range: $crate::abi::Str::EMPTY,
relation: $crate::abi::Relation::AFTER,
},)*)?
$($($crate::abi::Dependency {
id: $crate::abi::Str::new($rec),
range: $crate::abi::Str::new($rec_range),
relation: $crate::abi::Relation::RECOMMENDS,
},)*)?
$($($crate::abi::Dependency {
id: $crate::abi::Str::new($breaks),
range: $crate::abi::Str::new($breaks_range),
relation: $crate::abi::Relation::BREAKS,
},)*)?
$($($crate::abi::Dependency {
id: $crate::abi::Str::new($replaces),
range: $crate::abi::Str::EMPTY,
relation: $crate::abi::Relation::REPLACES,
},)*)?
$($($crate::abi::Dependency {
id: $crate::abi::Str::new($was),
range: $crate::abi::Str::EMPTY,
relation: $crate::abi::Relation::WAS,
},)*)?
];
const AUTHOR_COUNT: usize = $crate::__private::author_count(
&[$($($author),*)?],
::core::env!("CARGO_PKG_AUTHORS"),
);
static AUTHORS: [$crate::abi::Str; AUTHOR_COUNT] = $crate::__private::authors(
&[$($($author),*)?],
::core::env!("CARGO_PKG_AUTHORS"),
);
static BUILDS: &[$crate::abi::BuildRow] = &[
$($($crate::abi::BuildRow {
side: $crate::abi::Side::$bside,
fingerprint: $crate::abi::Fingerprint { guid: $crate::abi::guid($guid), age: $age },
symbols: (&[$($crate::abi::Symbol { name: $crate::abi::Str::new($sym), rva: $rva }),*]
as &[$crate::abi::Symbol]).as_ptr(),
symbol_count: (&[$($crate::abi::Symbol { name: $crate::abi::Str::new($sym), rva: $rva }),*]
as &[$crate::abi::Symbol]).len(),
constants: (&[$($($crate::abi::Symbol { name: $crate::abi::Str::new($constant), rva: $value }),*)?]
as &[$crate::abi::Symbol]).as_ptr(),
constant_count: (&[$($($crate::abi::Symbol { name: $crate::abi::Str::new($constant), rva: $value }),*)?]
as &[$crate::abi::Symbol]).len(),
},)*)?
];
const VERSION: &str = $crate::__private::or_default(
&[$($version)?],
::core::env!("CARGO_PKG_VERSION"),
);
const POINTS: &str = $crate::__private::point_schemas(
$crate::__private::concatcp!(
"schema = 1\nmod = \"", $id, "\"\nversion = \"", VERSION, "\"\n",
$($(<$point as $crate::points::Point>::SCHEMA,)*)?
$($(<$event as $crate::services::ModEvent>::SCHEMA,)*)?
$($(<$call as $crate::services::Call>::SCHEMA,)*)?
),
);
#[cfg_attr(windows, unsafe(link_section = ".enshpt"))]
#[used]
static POINT_SECTION: [u8; POINTS.len()] = $crate::__private::bytes(POINTS);
static MANIFEST: $crate::abi::Manifest = $crate::abi::Manifest {
header: $crate::abi::Header::of::<$crate::abi::Manifest>(),
id: $crate::abi::Str::new($id),
version: $crate::abi::Str::new(VERSION),
side: $crate::abi::Side::$side,
flags: $crate::__private::flags(&[$($join)?], &[$($reload)?]),
dependencies: DEPENDENCIES.as_ptr(),
dependency_count: DEPENDENCIES.len(),
builds: BUILDS.as_ptr(),
build_count: BUILDS.len(),
name: $crate::abi::Str::new($crate::__private::first_text(&[$($name)?])),
description: $crate::abi::Str::new($crate::__private::first_text(
&[$($description,)? ::core::env!("CARGO_PKG_DESCRIPTION")],
)),
authors: AUTHORS.as_ptr(),
author_count: AUTHOR_COUNT,
license: $crate::abi::Str::new($crate::__private::first_text(
&[$($license,)? ::core::env!("CARGO_PKG_LICENSE")],
)),
homepage: $crate::abi::Str::new($crate::__private::first_text(
&[$($homepage,)? ::core::env!("CARGO_PKG_HOMEPAGE"), ::core::env!("CARGO_PKG_REPOSITORY")],
)),
points: $crate::abi::Str::new(POINTS),
};
&MANIFEST
}};
}
#[macro_export]
macro_rules! declare_mod {
($ty:ty) => {
$crate::__require_unwind!();
static __ENSHWICK_INSTANCE: $crate::__private::Slot<$ty> = $crate::__private::Slot::new();
impl $ty {
pub fn instance() -> ::core::option::Option<&'static Self> {
__ENSHWICK_INSTANCE.get()
}
}
#[cfg_attr(not(test), unsafe(no_mangle))]
pub extern "system" fn enshwick_mod_abi() -> u32 {
::core::primitive::u32::from($crate::abi::ABI_MAJOR)
}
#[cfg_attr(not(test), unsafe(no_mangle))]
pub extern "system" fn enshwick_mod_query() -> *const $crate::abi::Manifest {
$crate::__private::query::<$ty>()
}
#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "system" fn enshwick_mod_init(
api: *const $crate::abi::HostApi,
me: $crate::abi::ModHandle,
) -> $crate::abi::Status {
unsafe { $crate::__private::init::<$ty>(api, me, &__ENSHWICK_INSTANCE) }
}
#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "system" fn enshwick_mod_ready(
_api: *const $crate::abi::HostApi,
_me: $crate::abi::ModHandle,
) {
$crate::__private::ready::<$ty>(&__ENSHWICK_INSTANCE);
}
#[cfg_attr(not(test), unsafe(no_mangle))]
pub extern "system" fn enshwick_mod_shutdown() {
$crate::__private::shutdown::<$ty>(&__ENSHWICK_INSTANCE);
}
};
}
#[macro_export]
macro_rules! error {
($($arg:tt)+) => { $crate::__log!($crate::abi::Level::ERROR, $($arg)+) };
}
#[macro_export]
macro_rules! warn {
($($arg:tt)+) => { $crate::__log!($crate::abi::Level::WARN, $($arg)+) };
}
#[macro_export]
macro_rules! info {
($($arg:tt)+) => { $crate::__log!($crate::abi::Level::INFO, $($arg)+) };
}
#[macro_export]
macro_rules! debug {
($($arg:tt)+) => { $crate::__log!($crate::abi::Level::DEBUG, $($arg)+) };
}
#[macro_export]
macro_rules! info_once {
($($arg:tt)+) => { $crate::__once!($crate::abi::Level::INFO, $($arg)+) };
}
#[macro_export]
macro_rules! warn_once {
($($arg:tt)+) => { $crate::__once!($crate::abi::Level::WARN, $($arg)+) };
}
#[macro_export]
macro_rules! error_once {
($($arg:tt)+) => { $crate::__once!($crate::abi::Level::ERROR, $($arg)+) };
}
#[macro_export]
macro_rules! info_every {
($period:expr, $($arg:tt)+) => { $crate::__every!($crate::abi::Level::INFO, $period, $($arg)+) };
}
#[macro_export]
macro_rules! warn_every {
($period:expr, $($arg:tt)+) => { $crate::__every!($crate::abi::Level::WARN, $period, $($arg)+) };
}
#[macro_export]
macro_rules! error_every {
($period:expr, $($arg:tt)+) => { $crate::__every!($crate::abi::Level::ERROR, $period, $($arg)+) };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __log {
($level:expr, $($arg:tt)+) => {
if $crate::__private::enabled($level) {
$crate::__private::log($level, ::std::format_args!($($arg)+));
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __once {
($level:expr, $($arg:tt)+) => {{
static ONCE: $crate::__private::Once = $crate::__private::Once::new();
if $crate::__private::enabled($level) && ONCE.first() {
$crate::__private::log($level, ::std::format_args!($($arg)+));
}
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __every {
($level:expr, $period:expr, $($arg:tt)+) => {{
static EVERY: $crate::__private::Every = $crate::__private::Every::new();
if $crate::__private::enabled($level)
&& let ::core::option::Option::Some(skipped) = EVERY.due($period)
{
match skipped {
0 => $crate::__private::log($level, ::std::format_args!($($arg)+)),
skipped => $crate::__private::log(
$level,
::std::format_args!("{} ({skipped} more since the last)", ::std::format_args!($($arg)+)),
),
}
}
}};
}