Skip to content

Commit 633170a

Browse files
committed
Support building APKs from Android host
1 parent 268939a commit 633170a

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

xbuild/src/command/build.rs

+2-2
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

+16-6
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

@@ -125,8 +129,14 @@ impl<'a> DownloadManager<'a> {
125129
}
126130

127131
pub fn prefetch(&self) -> Result<()> {
128-
for target in self.env().target().compile_targets() {
129-
self.rustup_target(target.rust_triple()?)?;
132+
// TODO: We might want to compare the targets instead, in case the user is not building for
133+
// the host but specified exactly the same triple after all.
134+
if !self.env().target().is_host() {
135+
for target in self.env().target().compile_targets() {
136+
self.rustup_target(target.rust_triple()?)?;
137+
}
138+
} else {
139+
info!("Building for host, assuming everything is available");
130140
}
131141

132142
match self.env().target().platform() {
@@ -140,8 +150,8 @@ impl<'a> DownloadManager<'a> {
140150
self.macos_sdk()?;
141151
}
142152
Platform::Android => {
143-
self.android_ndk()?;
144-
self.android_jar()?;
153+
self.android_ndk().context("ndk")?;
154+
self.android_jar().context("jar")?;
145155
}
146156
Platform::Ios => {
147157
self.ios_sdk()?;

xbuild/src/lib.rs

+3-1
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)