File tree Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,18 @@ On Windows:
43
43
44
44
### NDK
45
45
46
+ #### Command-line install
47
+
48
+ Assuming ` sdkmanager ` from the "Command-Line Tools" package is in your PATH:
49
+
50
+ ``` bash
51
+ cargo install toml-cli
52
+ ANDROID_NDK_VERSION=$( toml get gradle/libs.versions.toml versions.ndk --raw)
53
+ sdkmanager --install " ndk;$ANDROID_NDK_VERSION "
54
+ ```
55
+
56
+ #### GUI install
57
+
46
58
In Android Studio, choose the Tools>SDK Manager menu option.
47
59
48
60
- In SDK tools, enable "show package details"
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ targetSdk = "34"
4
4
minSdk = " 21"
5
5
6
6
# https://developer.android.com/ndk/downloads
7
- ndk = " 27 .0.12077973 "
7
+ ndk = " 28 .0.13004108 "
8
8
9
9
# https://developer.android.com/jetpack/androidx/releases/appcompat
10
10
androidxAppCompat = " 1.7.0"
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pub mod proto;
7
7
use std:: {
8
8
env:: { self , consts:: OS } ,
9
9
path:: PathBuf ,
10
+ process:: Command ,
10
11
} ;
11
12
12
13
use anyhow:: Result ;
@@ -33,10 +34,41 @@ fn main() -> Result<()> {
33
34
} else {
34
35
"windows-x86_64"
35
36
} ;
36
- let lib_dir = format ! ( "/toolchains/llvm/prebuilt/{platform}/lib/clang/18/lib/linux/" ) ;
37
+
38
+ // cargo-ndk sets CC_x86_64-linux-android to the path to `clang`, within the
39
+ // Android NDK.
40
+ let clang_path = PathBuf :: from (
41
+ env:: var ( "CC_x86_64-linux-android" ) . expect ( "CC_x86_64-linux-android not set" ) ,
42
+ ) ;
43
+ let clang_version = get_clang_major_version ( & clang_path) ;
44
+
45
+ let lib_dir =
46
+ format ! ( "/toolchains/llvm/prebuilt/{platform}/lib/clang/{clang_version}/lib/linux/" ) ;
37
47
println ! ( "cargo:rustc-link-search={android_ndk_home}/{lib_dir}" ) ;
38
48
println ! ( "cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android" ) ;
39
49
}
40
50
41
51
Ok ( ( ) )
42
52
}
53
+
54
+ /// Run the clang binary at `clang_path`, and return its major version number
55
+ fn get_clang_major_version ( clang_path : & PathBuf ) -> String {
56
+ let clang_output = Command :: new ( clang_path)
57
+ . arg ( "-dumpversion" )
58
+ . output ( )
59
+ . expect ( "failed to start clang" ) ;
60
+
61
+ if !clang_output. status . success ( ) {
62
+ panic ! (
63
+ "failed to run clang: {}" ,
64
+ String :: from_utf8_lossy( & clang_output. stderr)
65
+ ) ;
66
+ }
67
+
68
+ let clang_version = String :: from_utf8 ( clang_output. stdout ) . expect ( "clang output is not utf8" ) ;
69
+ clang_version
70
+ . split ( '.' )
71
+ . next ( )
72
+ . expect ( "could not parse clang output" )
73
+ . to_owned ( )
74
+ }
You can’t perform that action at this time.
0 commit comments