File tree Expand file tree Collapse file tree 3 files changed +25
-30
lines changed
Expand file tree Collapse file tree 3 files changed +25
-30
lines changed Original file line number Diff line number Diff line change 1010
1111``` toml
1212[lib ]
13- crate-type = [" cdylib" ]
13+ crate-type = [" lib " , " cdylib" ]
1414```
1515
1616``` rust
1717#[cfg(target_os = " android" )]
18- #[no_mangle]
19- pub unsafe extern " C" fn ANativeActivity_onCreate (
20- activity : * mut std :: os :: raw :: c_void ,
21- saved_state : * mut std :: os :: raw :: c_void ,
22- saved_state_size : usize ,
23- ) {
24- ndk_glue :: init (
25- activity as _ ,
26- saved_state as _ ,
27- saved_state_size as _ ,
28- app_main ,
29- );
30- }
18+ ndk_glue :: ndk_glue! (main );
3119
32- pub fn app_main () {
20+ fn main () {
3321 println! (" hello world" );
3422}
3523```
Original file line number Diff line number Diff line change 11#[ cfg( target_os = "android" ) ]
2- #[ no_mangle]
3- pub unsafe extern "C" fn ANativeActivity_onCreate (
4- activity : * mut std:: os:: raw:: c_void ,
5- saved_state : * mut std:: os:: raw:: c_void ,
6- saved_state_size : usize ,
7- ) {
8- std:: env:: set_var ( "RUST_BACKTRACE" , "1" ) ;
9- ndk_glue:: init (
10- activity as _ ,
11- saved_state as _ ,
12- saved_state_size as _ ,
13- app_main,
14- ) ;
15- }
2+ ndk_glue:: ndk_glue!( main) ;
163
17- pub fn app_main ( ) {
4+ fn main ( ) {
185 println ! ( "hello world" ) ;
196}
Original file line number Diff line number Diff line change @@ -14,6 +14,26 @@ use std::ptr::NonNull;
1414use std:: sync:: { RwLock , RwLockReadGuard } ;
1515use std:: thread;
1616
17+ #[ macro_export]
18+ macro_rules! ndk_glue {
19+ ( $main: ident) => {
20+ #[ no_mangle]
21+ unsafe extern "C" fn ANativeActivity_onCreate (
22+ activity: * mut std:: os:: raw:: c_void,
23+ saved_state: * mut std:: os:: raw:: c_void,
24+ saved_state_size: usize ,
25+ ) {
26+ std:: env:: set_var( "RUST_BACKTRACE" , "1" ) ;
27+ $crate:: init(
28+ activity as _,
29+ saved_state as _,
30+ saved_state_size as _,
31+ $main,
32+ ) ;
33+ }
34+ }
35+ }
36+
1737pub fn android_log ( level : Level , tag : & CStr , msg : & CStr ) {
1838 use android_log_sys:: LogPriority ;
1939 let prio = match level {
You can’t perform that action at this time.
0 commit comments