Skip to content

Commit

Permalink
search android ndk also in ANDROID_NDK env var and pass ANDROID_NDK v…
Browse files Browse the repository at this point in the history
…ar to build if not set (cmake compat)
  • Loading branch information
fredszaq committed Sep 29, 2023
1 parent cddf158 commit 329efdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dinghy-lib/src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl PlatformManager for AndroidManager {
binutils_prefix: format!("{}-linux-{}", binutils_cpu, abi_kind),
cc_prefix: format!("{}-linux-{}{}", cc_cpu, abi_kind, api),
};
AndroidPlatform::new(PlatformConfiguration::default(), id, tc, major, libclang_path.clone())
AndroidPlatform::new(PlatformConfiguration::default(), id, tc, major, ndk.clone(),libclang_path.clone())
};
for api in api_levels.iter() {
platforms.push(create_platform(&api, &format!("-api{}", api))?);
Expand Down Expand Up @@ -190,6 +190,9 @@ fn ndk() -> Result<Option<path::PathBuf>> {
if let Ok(path) = env::var("ANDROID_NDK_HOME") {
return Ok(Some(path.into()));
}
if let Ok(path) = env::var("ANDROID_NDK") {
return Ok(Some(path.into()));
}
for sdk in probable_sdk_locs()? {
if sdk.join("ndk-bundle/source.properties").is_file() {
return Ok(Some(sdk.join("ndk-bundle")));
Expand Down
11 changes: 11 additions & 0 deletions dinghy-lib/src/android/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct AndroidPlatform {
regular_platform: Box<dyn Platform>,
toolchain_config: ToolchainConfig,
ndk_major_version: usize,
ndk_path: PathBuf,
libclang_path: PathBuf,
}

Expand All @@ -21,6 +22,7 @@ impl AndroidPlatform {
id: String,
toolchain_config: ToolchainConfig,
ndk_major_version: usize,
ndk_path: PathBuf,
libclang_path: PathBuf,
) -> Result<Box<dyn Platform>> {
Ok(Box::new(Self {
Expand All @@ -31,6 +33,7 @@ impl AndroidPlatform {
)?,
toolchain_config,
ndk_major_version,
ndk_path,
libclang_path
}))
}
Expand Down Expand Up @@ -76,6 +79,14 @@ impl Platform for AndroidPlatform {
set_env("DINGHY_BUILD_LIBCLANG_PATH", &self.libclang_path )
}

if std::env::var("ANDROID_NDK").is_err() {
set_env("ANDROID_NDK", self.ndk_path.canonicalize()?)
}

if std::env::var("ANDROID_NDK_HOME").is_err() {
set_env("ANDROID_NDK_HOME", self.ndk_path.canonicalize()?)
}


Ok(())
}
Expand Down

0 comments on commit 329efdb

Please sign in to comment.