From 633170a3c9de86b6d6fe56ad45ee6c0bf94cfeaa Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 14 Sep 2023 11:16:50 +0200 Subject: [PATCH] Support building APKs from Android host --- xbuild/src/command/build.rs | 4 ++-- xbuild/src/download.rs | 22 ++++++++++++++++------ xbuild/src/lib.rs | 4 +++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/xbuild/src/command/build.rs b/xbuild/src/command/build.rs index 9e7020f7..5e749855 100644 --- a/xbuild/src/command/build.rs +++ b/xbuild/src/command/build.rs @@ -19,9 +19,9 @@ pub fn build(env: &BuildEnv) -> Result<()> { let mut runner = TaskRunner::new(3, env.verbose()); runner.start_task("Fetch precompiled artifacts"); - let manager = DownloadManager::new(env)?; + let manager = DownloadManager::new(env).context("Creating DownloadManager")?; if !env.offline() { - manager.prefetch()?; + manager.prefetch().context("prefetch")?; runner.end_verbose_task(); } diff --git a/xbuild/src/download.rs b/xbuild/src/download.rs index 9de7d0b6..ceb25454 100644 --- a/xbuild/src/download.rs +++ b/xbuild/src/download.rs @@ -1,6 +1,7 @@ use crate::{BuildEnv, Platform}; -use anyhow::Result; +use anyhow::{Context, Result}; use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; +use log::info; use mvn::Download; use reqwest::blocking::Client; use std::fs::File; @@ -37,7 +38,10 @@ impl<'a> Download for DownloadManager<'a> { let len = resp.content_length().unwrap_or_default(); pb.set_length(len); - let dest = BufWriter::new(File::create(dest)?); + let dest = BufWriter::new( + File::create(dest) + .with_context(|| format!("While creating download output file `{dest:?}`"))?, + ); std::io::copy(&mut resp, &mut pb.wrap_write(dest))?; pb.finish_with_message("📥 downloaded"); @@ -125,8 +129,14 @@ impl<'a> DownloadManager<'a> { } pub fn prefetch(&self) -> Result<()> { - for target in self.env().target().compile_targets() { - self.rustup_target(target.rust_triple()?)?; + // TODO: We might want to compare the targets instead, in case the user is not building for + // the host but specified exactly the same triple after all. + if !self.env().target().is_host() { + for target in self.env().target().compile_targets() { + self.rustup_target(target.rust_triple()?)?; + } + } else { + info!("Building for host, assuming everything is available"); } match self.env().target().platform() { @@ -140,8 +150,8 @@ impl<'a> DownloadManager<'a> { self.macos_sdk()?; } Platform::Android => { - self.android_ndk()?; - self.android_jar()?; + self.android_ndk().context("ndk")?; + self.android_jar().context("jar")?; } Platform::Ios => { self.ios_sdk()?; diff --git a/xbuild/src/lib.rs b/xbuild/src/lib.rs index 34e501a1..e4eb0033 100644 --- a/xbuild/src/lib.rs +++ b/xbuild/src/lib.rs @@ -51,7 +51,9 @@ pub enum Platform { impl Platform { pub fn host() -> Result { - Ok(if cfg!(target_os = "linux") { + Ok(if cfg!(target_os = "android") { + Platform::Android + } else if cfg!(target_os = "linux") { Platform::Linux } else if cfg!(target_os = "macos") { Platform::Macos