Skip to content

Commit

Permalink
Support building APKs from Android host
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Sep 14, 2023
1 parent 6caae75 commit 909fe13
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions xbuild/src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
19 changes: 14 additions & 5 deletions xbuild/src/download.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -138,9 +142,14 @@ impl<'a> DownloadManager<'a> {
self.macos_sdk()?;
}
Platform::Android => {
self.rustup_target("aarch64-linux-android")?;
self.android_ndk()?;
self.android_jar()?;
if Platform::host()? != Platform::Android {
self.rustup_target("aarch64-linux-android")
.context("rustup_target")?;
} else {
info!("Skipping `rustup` for Android target");
}
self.android_ndk().context("ndk")?;
self.android_jar().context("jar")?;
}
Platform::Ios => {
self.rustup_target("aarch64-apple-ios")?;
Expand Down
4 changes: 3 additions & 1 deletion xbuild/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ pub enum Platform {

impl Platform {
pub fn host() -> Result<Self> {
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
Expand Down

0 comments on commit 909fe13

Please sign in to comment.