Skip to content

Commit 909fe13

Browse files
committed
Support building APKs from Android host
1 parent 6caae75 commit 909fe13

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

xbuild/src/command/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pub fn build(env: &BuildEnv) -> Result<()> {
1919
let mut runner = TaskRunner::new(3, env.verbose());
2020

2121
runner.start_task("Fetch precompiled artifacts");
22-
let manager = DownloadManager::new(env)?;
22+
let manager = DownloadManager::new(env).context("Creating DownloadManager")?;
2323
if !env.offline() {
24-
manager.prefetch()?;
24+
manager.prefetch().context("prefetch")?;
2525
runner.end_verbose_task();
2626
}
2727

xbuild/src/download.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{BuildEnv, Platform};
2-
use anyhow::Result;
2+
use anyhow::{Context, Result};
33
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
4+
use log::info;
45
use mvn::Download;
56
use reqwest::blocking::Client;
67
use std::fs::File;
@@ -37,7 +38,10 @@ impl<'a> Download for DownloadManager<'a> {
3738
let len = resp.content_length().unwrap_or_default();
3839
pb.set_length(len);
3940

40-
let dest = BufWriter::new(File::create(dest)?);
41+
let dest = BufWriter::new(
42+
File::create(dest)
43+
.with_context(|| format!("While creating download output file `{dest:?}`"))?,
44+
);
4145
std::io::copy(&mut resp, &mut pb.wrap_write(dest))?;
4246
pb.finish_with_message("📥 downloaded");
4347

@@ -138,9 +142,14 @@ impl<'a> DownloadManager<'a> {
138142
self.macos_sdk()?;
139143
}
140144
Platform::Android => {
141-
self.rustup_target("aarch64-linux-android")?;
142-
self.android_ndk()?;
143-
self.android_jar()?;
145+
if Platform::host()? != Platform::Android {
146+
self.rustup_target("aarch64-linux-android")
147+
.context("rustup_target")?;
148+
} else {
149+
info!("Skipping `rustup` for Android target");
150+
}
151+
self.android_ndk().context("ndk")?;
152+
self.android_jar().context("jar")?;
144153
}
145154
Platform::Ios => {
146155
self.rustup_target("aarch64-apple-ios")?;

xbuild/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ pub enum Platform {
5151

5252
impl Platform {
5353
pub fn host() -> Result<Self> {
54-
Ok(if cfg!(target_os = "linux") {
54+
Ok(if cfg!(target_os = "android") {
55+
Platform::Android
56+
} else if cfg!(target_os = "linux") {
5557
Platform::Linux
5658
} else if cfg!(target_os = "macos") {
5759
Platform::Macos

0 commit comments

Comments
 (0)