Skip to content

Commit fc42c21

Browse files
mikehardydavid-allison
authored andcommitted
build(deps): adopt ndk v28 / add doc on CLI install of same
- updated the compile workaround for rust-lang/rust#109717 now it gets the clang version dynamically, important as ndk v28 updated the clang version so old static definition failed
1 parent d20d3ee commit fc42c21

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ On Windows:
4343

4444
### NDK
4545

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+
4658
In Android Studio, choose the Tools>SDK Manager menu option.
4759

4860
- In SDK tools, enable "show package details"

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ targetSdk = "34"
44
minSdk = "21"
55

66
# https://developer.android.com/ndk/downloads
7-
ndk = "27.0.12077973"
7+
ndk = "28.0.13004108"
88

99
# https://developer.android.com/jetpack/androidx/releases/appcompat
1010
androidxAppCompat = "1.7.0"

rslib-bridge/build.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod proto;
77
use std::{
88
env::{self, consts::OS},
99
path::PathBuf,
10+
process::Command,
1011
};
1112

1213
use anyhow::Result;
@@ -33,10 +34,41 @@ fn main() -> Result<()> {
3334
} else {
3435
"windows-x86_64"
3536
};
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/");
3747
println!("cargo:rustc-link-search={android_ndk_home}/{lib_dir}");
3848
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
3949
}
4050

4151
Ok(())
4252
}
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+
}

0 commit comments

Comments
 (0)