#[macro_export]
macro_rules! backend {
($($args:tt)+) => {
$crate::init_with(|app| $crate::__tdn_args!(__tdn_backend_host (app,) $($args)+))
};
}
#[macro_export]
macro_rules! backend_options {
($app:expr, $($args:tt)+) => {
$crate::__tdn_args!(__tdn_backend_options ($app,) $($args)+)
};
}
#[macro_export]
macro_rules! embedded_backend_options {
($($args:tt)+) => {
$crate::__tdn_args!(__tdn_embedded_backend_options () $($args)+)
};
}
#[macro_export]
macro_rules! any_backend_options {
($app:expr, $($args:tt)+) => {{
#[cfg(feature = "embedded-backend")]
{
let _ = &$app;
$crate::embedded_backend_options!($($args)+)
}
#[cfg(not(feature = "embedded-backend"))]
{
$crate::backend_options!($app, $($args)+)
}
}};
}
#[macro_export]
macro_rules! any_backend_host {
($app:expr, $($args:tt)+) => {{
#[cfg(feature = "embedded-backend")]
{
let _ = &$app;
$crate::HostfxrHost::new($crate::embedded_backend_options!($($args)+))
}
#[cfg(not(feature = "embedded-backend"))]
{
$crate::__tdn_args!(__tdn_backend_host ($app,) $($args)+)
}
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_args {
($callback:ident ($($prefix:tt)*) $project:literal $(,)?) => {
$crate::$callback!($($prefix)* $project, $project, "net8.0")
};
($callback:ident ($($prefix:tt)*) $project:literal, tfm = $tfm:literal $(,)?) => {
$crate::$callback!($($prefix)* $project, $project, $tfm)
};
($callback:ident ($($prefix:tt)*) $project:literal, assembly = $assembly:literal $(,)?) => {
$crate::$callback!($($prefix)* $project, $assembly, "net8.0")
};
($callback:ident ($($prefix:tt)*) $project:literal, assembly = $assembly:literal, tfm = $tfm:literal $(,)?) => {
$crate::$callback!($($prefix)* $project, $assembly, $tfm)
};
($callback:ident ($($prefix:tt)*) $project:literal, tfm = $tfm:literal, assembly = $assembly:literal $(,)?) => {
$crate::$callback!($($prefix)* $project, $assembly, $tfm)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_backend_options {
($app:expr, $project:literal, $assembly:literal, $tfm:literal) => {{
#[cfg(debug_assertions)]
fn __tauri_plugin_dotnet_options<R: ::tauri::Runtime>(
_app: &::tauri::AppHandle<R>,
) -> $crate::HostfxrOptions {
$crate::HostfxrOptions::new(::std::path::PathBuf::from($crate::__tdn_debug_dll!(
$project, $assembly, $tfm
)))
}
#[cfg(not(debug_assertions))]
fn __tauri_plugin_dotnet_options<R: ::tauri::Runtime>(
app: &::tauri::AppHandle<R>,
) -> $crate::HostfxrOptions {
use ::tauri::Manager as _;
let dir = app.path().resource_dir().expect("no resource directory");
$crate::HostfxrOptions::new(dir.join($crate::__tdn_release_dll!($project, $assembly, $tfm)))
}
__tauri_plugin_dotnet_options($app)
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_backend_host {
($app:expr, $project:literal, $assembly:literal, $tfm:literal) => {{
#[cfg(debug_assertions)]
fn __tauri_plugin_dotnet_host<R: ::tauri::Runtime>(_app: &::tauri::AppHandle<R>) -> $crate::SidecarHost {
$crate::SidecarHost::new(
$crate::SidecarOptions::new(
::std::path::PathBuf::from($crate::__tdn_debug_csproj!($project, $assembly, $tfm)),
$assembly,
)
.tfm($tfm),
)
}
#[cfg(not(debug_assertions))]
fn __tauri_plugin_dotnet_host<R: ::tauri::Runtime>(app: &::tauri::AppHandle<R>) -> $crate::HostfxrHost {
$crate::HostfxrHost::new($crate::__tdn_backend_options!(app, $project, $assembly, $tfm))
}
__tauri_plugin_dotnet_host($app)
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_embedded_backend_options {
($project:literal, $assembly:literal, $tfm:literal) => {{
#[cfg(debug_assertions)]
{
$crate::HostfxrOptions::embedded(include_bytes!($crate::__tdn_bundle!(
"Debug", $project, $assembly, $tfm
)))
}
#[cfg(not(debug_assertions))]
{
$crate::HostfxrOptions::embedded(include_bytes!($crate::__tdn_bundle!(
"Release", $project, $assembly, $tfm
)))
}
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_debug_dll {
($project:literal, $assembly:literal, $tfm:literal) => {
concat!(
env!("CARGO_MANIFEST_DIR"),
"/../src-dotnet/",
$project,
"/bin/Debug/",
$tfm,
"/",
$assembly,
".dll"
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_debug_csproj {
($project:literal, $assembly:literal, $tfm:literal) => {
concat!(env!("CARGO_MANIFEST_DIR"), "/../src-dotnet/", $project, "/", $project, ".csproj")
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_release_dll {
($project:literal, $assembly:literal, $tfm:literal) => {
concat!("dotnet/", $assembly, ".dll")
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tdn_bundle {
($configuration:literal, $project:literal, $assembly:literal, $tfm:literal) => {
concat!(
env!("CARGO_MANIFEST_DIR"),
"/../src-dotnet/",
$project,
"/bin/",
$configuration,
"/",
$tfm,
"/",
$assembly,
".tdnbundle"
)
};
}
#[cfg(test)]
mod tests {
const ROOT: &str = env!("CARGO_MANIFEST_DIR");
#[test]
fn the_project_name_is_also_the_assembly_name_and_net8_the_default() {
assert_eq!(
crate::__tdn_args!(__tdn_debug_dll () "MyApp.Backend"),
format!("{ROOT}/../src-dotnet/MyApp.Backend/bin/Debug/net8.0/MyApp.Backend.dll")
);
assert_eq!(crate::__tdn_args!(__tdn_release_dll () "MyApp.Backend"), "dotnet/MyApp.Backend.dll");
}
#[test]
fn the_assembly_name_names_the_file_and_the_project_the_folder() {
assert_eq!(
crate::__tdn_args!(__tdn_debug_dll () "backend", assembly = "MyApp"),
format!("{ROOT}/../src-dotnet/backend/bin/Debug/net8.0/MyApp.dll")
);
assert_eq!(crate::__tdn_args!(__tdn_release_dll () "backend", assembly = "MyApp"), "dotnet/MyApp.dll");
assert_eq!(
crate::__tdn_args!(__tdn_bundle ("Release",) "backend", assembly = "MyApp"),
format!("{ROOT}/../src-dotnet/backend/bin/Release/net8.0/MyApp.tdnbundle")
);
}
#[test]
fn the_target_framework_changes_only_the_build_output_folder() {
assert_eq!(
crate::__tdn_args!(__tdn_debug_dll () "MyApp.Backend", tfm = "net9.0"),
format!("{ROOT}/../src-dotnet/MyApp.Backend/bin/Debug/net9.0/MyApp.Backend.dll")
);
assert_eq!(
crate::__tdn_args!(__tdn_release_dll () "MyApp.Backend", tfm = "net9.0"),
"dotnet/MyApp.Backend.dll"
);
assert_eq!(
crate::__tdn_args!(__tdn_bundle ("Debug",) "MyApp.Backend", tfm = "net9.0"),
format!("{ROOT}/../src-dotnet/MyApp.Backend/bin/Debug/net9.0/MyApp.Backend.tdnbundle")
);
}
#[test]
fn the_keys_can_come_in_either_order_with_a_trailing_comma() {
let expected = format!("{ROOT}/../src-dotnet/backend/bin/Debug/net9.0/MyApp.dll");
assert_eq!(crate::__tdn_args!(__tdn_debug_dll () "backend", assembly = "MyApp", tfm = "net9.0"), expected);
assert_eq!(crate::__tdn_args!(__tdn_debug_dll () "backend", tfm = "net9.0", assembly = "MyApp"), expected);
assert_eq!(crate::__tdn_args!(__tdn_debug_dll () "backend", tfm = "net9.0", assembly = "MyApp",), expected);
assert_eq!(
crate::__tdn_args!(__tdn_debug_dll () "MyApp.Backend",),
format!("{ROOT}/../src-dotnet/MyApp.Backend/bin/Debug/net8.0/MyApp.Backend.dll")
);
}
}