Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building APKs from Android host #138

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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
Loading