Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xbuild/src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn build(env: &BuildEnv) -> Result<()> {
let cargo_dir = arch_dir.join("cargo");
let lib = env.cargo_artefact(&cargo_dir, target, CrateType::Cdylib)?;

let ndk = env.android_ndk();
let ndk = env.android_ndk_sysroot();

let deps_dir = {
let arch_dir = if target.is_host()? {
Expand Down
13 changes: 9 additions & 4 deletions xbuild/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl WorkItem {
impl WorkItem {
const ORG: &'static str = "rust-mobile";
const REPO: &'static str = "xbuild";
const VERSION: &'static str = "v0.1.0+3";
const VERSION: &'static str = "v0.2.1-alpha";

pub fn xbuild_release(output: PathBuf, artifact: &str) -> Self {
Self::github_release(output, Self::ORG, Self::REPO, Self::VERSION, artifact)
Expand Down Expand Up @@ -260,9 +260,14 @@ impl DownloadManager<'_> {
}

pub fn android_ndk(&self) -> Result<()> {
let output = self.env.android_ndk();
let item = WorkItem::xbuild_release(output, "Android.ndk.tar.zst");
self.fetch(item)
if self.env.android_ndk().is_none() {
let output = self.env.android_ndk_sysroot();
let item = WorkItem::xbuild_release(output, "Android.ndk.tar.zst");
self.fetch(item)
} else {
// The ndk path is set so we don't need to download anything
Ok(())
}
}

pub fn ios_sdk(&self) -> Result<()> {
Expand Down
31 changes: 26 additions & 5 deletions xbuild/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::config::Config;
use crate::devices::Device;
use anyhow::{ensure, Result};
use clap::{Parser, ValueEnum};
use std::env;
use std::path::{Path, PathBuf};
use xcommon::Signer;

Expand Down Expand Up @@ -635,12 +636,32 @@ impl BuildEnv {
self.cache_dir().join("MacOSX.sdk")
}

pub fn android_home(&self) -> Option<PathBuf> {
env::var("ANDROID_HOME").ok().map(|p| PathBuf::from(p))
}

pub fn android_sdk(&self) -> PathBuf {
self.cache_dir().join("Android.sdk")
if let Some(p) = self.android_home() {
PathBuf::from(p)
} else {
self.cache_dir().join("Android.sdk")
}
}

pub fn android_ndk(&self) -> Option<PathBuf> {
env::var("ANDROID_NDK_ROOT").ok().map(|p| PathBuf::from(p))
}

pub fn android_ndk(&self) -> PathBuf {
self.cache_dir().join("Android.ndk")
pub fn android_ndk_sysroot(&self) -> PathBuf {
if self.android_ndk().is_some() {
if let Ok(p) = env::var("ANDROID_NDK_SYSROOT") {
PathBuf::from(p)
} else {
panic!("Android ndk path is set so not cached ndk will be used, but 'ANDROID_NDK_SYSROOT' is not set. Please set the environment variable 'ANDROID_NDK_SYSROOT'. It is probably in $ANDROID_NDK_ROOT/toolchains/llvm/prebuild/<arch>/sysroot")
}
} else {
self.cache_dir().join("Android.ndk")
}
}

pub fn ios_sdk(&self) -> PathBuf {
Expand All @@ -658,7 +679,7 @@ impl BuildEnv {
pub fn lldb_server(&self, target: CompileTarget) -> Result<PathBuf> {
match target.platform() {
Platform::Android => {
let ndk = self.android_ndk();
let ndk = self.android_ndk_sysroot();
let lib_dir = ndk.join("usr").join("lib").join(target.ndk_triple());
Ok(lib_dir.join("lldb-server"))
}
Expand All @@ -676,7 +697,7 @@ impl BuildEnv {
cargo.add_link_arg("-Wl,$ORIGIN/lib");
}
if target.platform() == Platform::Android {
let ndk = self.android_ndk();
let ndk = self.android_ndk_sysroot();
let target_sdk_version = self
.config()
.android()
Expand Down
Loading