@@ -11,31 +11,37 @@ pub fn main() {
11
11
}
12
12
}
13
13
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
+
14
21
fn build_android ( ) {
15
- // Resolve `src/ android-api.c` relative to this file .
22
+ // Create ` android-api.c` on demand .
16
23
// 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 ( ) {
22
29
Ok ( result) => result,
23
30
Err ( e) => {
24
- println ! ( "failed to run C compiler: {}" , e) ;
31
+ eprintln ! ( "warning: android detection failed while running C compiler: {}" , e) ;
25
32
return ;
26
33
}
27
34
} ;
28
35
let expansion = match std:: str:: from_utf8 ( & expansion) {
29
36
Ok ( s) => s,
30
37
Err ( _) => return ,
31
38
} ;
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 ) {
35
41
Some ( i) => i,
36
42
None => return ,
37
43
} ;
38
- let version = match expansion[ i + marker . len ( ) + 1 ..] . split_whitespace ( ) . next ( ) {
44
+ let version = match expansion[ i + MARKER . len ( ) + 1 ..] . split_whitespace ( ) . next ( ) {
39
45
Some ( s) => s,
40
46
None => return ,
41
47
} ;
0 commit comments