@@ -11,31 +11,37 @@ pub fn main() {
1111 }
1212}
1313
14+ // Used to detect the value of the `__ANDROID_API__`
15+ // builtin #define
16+ const MARKER : & str = "BACKTRACE_RS_ANDROID_APIVERSION" ;
17+ const ANDROID_API_C : & str = "
18+ BACKTRACE_RS_ANDROID_APIVERSION __ANDROID_API__
19+ " ;
20+
1421fn build_android ( ) {
15- // Resolve `src/ android-api.c` relative to this file .
22+ // Create ` android-api.c` on demand .
1623 // Required to support calling this from the `std` build script.
17- let android_api_c = Path :: new ( file ! ( ) )
18- . parent ( )
19- . unwrap ( )
20- . join ( "src/android-api.c" ) ;
21- let expansion = match cc:: Build :: new ( ) . file ( android_api_c) . try_expand ( ) {
24+ let out_dir = env :: var_os ( "OUT_DIR" ) . unwrap ( ) ;
25+ let android_api_c = Path :: new ( & out_dir ) . join ( "android-api.c" ) ;
26+ std :: fs :: write ( & android_api_c , ANDROID_API_C ) . unwrap ( ) ;
27+
28+ let expansion = match cc:: Build :: new ( ) . file ( & android_api_c) . try_expand ( ) {
2229 Ok ( result) => result,
2330 Err ( e) => {
24- println ! ( "failed to run C compiler: {}" , e) ;
31+ eprintln ! ( "warning: android detection failed while running C compiler: {}" , e) ;
2532 return ;
2633 }
2734 } ;
2835 let expansion = match std:: str:: from_utf8 ( & expansion) {
2936 Ok ( s) => s,
3037 Err ( _) => return ,
3138 } ;
32- println ! ( "expanded android version detection:\n {}" , expansion) ;
33- let marker = "APIVERSION" ;
34- let i = match expansion. find ( marker) {
39+ eprintln ! ( "expanded android version detection:\n {}" , expansion) ;
40+ let i = match expansion. find ( MARKER ) {
3541 Some ( i) => i,
3642 None => return ,
3743 } ;
38- let version = match expansion[ i + marker . len ( ) + 1 ..] . split_whitespace ( ) . next ( ) {
44+ let version = match expansion[ i + MARKER . len ( ) + 1 ..] . split_whitespace ( ) . next ( ) {
3945 Some ( s) => s,
4046 None => return ,
4147 } ;
0 commit comments