Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add
mobile_entry_point
macro (#4983)
- Loading branch information
1 parent
16360ae
commit 9890486
Showing
11 changed files
with
126 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"tauri-build": patch | ||
--- | ||
|
||
Set environment variables used by `tauri::mobile_entry_point`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"tauri-macros": minor | ||
--- | ||
|
||
Added the `mobile_entry_point` macro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"tauri": minor | ||
--- | ||
|
||
Export types required by the `mobile_entry_point` macro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use proc_macro::TokenStream; | ||
use proc_macro2::TokenStream as TokenStream2; | ||
use quote::{format_ident, quote}; | ||
use std::env::var; | ||
use syn::{parse_macro_input, spanned::Spanned, ItemFn}; | ||
|
||
fn get_env_var(name: &str, error: &mut Option<TokenStream2>, function: &ItemFn) -> TokenStream2 { | ||
match var(name) { | ||
Ok(value) => { | ||
let ident = format_ident!("{}", value); | ||
quote!(#ident) | ||
} | ||
Err(_) => { | ||
error.replace( | ||
syn::Error::new( | ||
function.span(), | ||
format!( | ||
"`{}` env var not set, do you have a build script with tauri-build?", | ||
name, | ||
), | ||
) | ||
.into_compile_error(), | ||
); | ||
quote!() | ||
} | ||
} | ||
} | ||
|
||
pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream { | ||
let function = parse_macro_input!(item as ItemFn); | ||
let function_name = function.sig.ident.clone(); | ||
|
||
let mut error = None; | ||
let domain = get_env_var("TAURI_ANDROID_DOMAIN", &mut error, &function); | ||
let app_name = get_env_var("TAURI_ANDROID_APP_NAME", &mut error, &function); | ||
|
||
if let Some(e) = error { | ||
quote!(#e).into() | ||
} else { | ||
quote!( | ||
fn stop_unwind<F: FnOnce() -> T, T>(f: F) -> T { | ||
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) { | ||
Ok(t) => t, | ||
Err(err) => { | ||
eprintln!("attempt to unwind out of `rust` with err: {:?}", err); | ||
std::process::abort() | ||
} | ||
} | ||
} | ||
|
||
#function | ||
|
||
fn _start_app() { | ||
#[cfg(target_os = "android")] | ||
{ | ||
use ::tauri::paste; | ||
::tauri::wry_android_binding!(#domain, #app_name, _start_app, ::tauri::wry); | ||
} | ||
stop_unwind(#function_name); | ||
} | ||
|
||
#[cfg(not(target_os = "android"))] | ||
#[no_mangle] | ||
#[inline(never)] | ||
pub extern "C" fn start_app() { | ||
_start_app() | ||
} | ||
) | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters