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 2c10b0c commit d2d866e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 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
22 changes: 16 additions & 6 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 @@ -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() {
Expand All @@ -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()?;
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 d2d866e

Please sign in to comment.