@@ -11,31 +11,40 @@ 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 ! (
32+ "warning: android version detection failed while running C compiler: {}" ,
33+ e
34+ ) ;
2535 return ;
2636 }
2737 } ;
2838 let expansion = match std:: str:: from_utf8 ( & expansion) {
2939 Ok ( s) => s,
3040 Err ( _) => return ,
3141 } ;
32- println ! ( "expanded android version detection:\n {}" , expansion) ;
33- let marker = "APIVERSION" ;
34- let i = match expansion. find ( marker) {
42+ eprintln ! ( "expanded android version detection:\n {}" , expansion) ;
43+ let i = match expansion. find ( MARKER ) {
3544 Some ( i) => i,
3645 None => return ,
3746 } ;
38- let version = match expansion[ i + marker . len ( ) + 1 ..] . split_whitespace ( ) . next ( ) {
47+ let version = match expansion[ i + MARKER . len ( ) + 1 ..] . split_whitespace ( ) . next ( ) {
3948 Some ( s) => s,
4049 None => return ,
4150 } ;
0 commit comments