From e65178a93d944acd73527f6beca3a378dd928c93 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 10 Jun 2022 18:04:58 +0200 Subject: [PATCH] cargo-apk: Append `--target` to blanket `cargo apk --` calls when not provided When the user doesn't provide a `--target` we default the triple to the currently connected device over `adb`, or otherwise fall back to `aarch64`. While this triple is always used to determine what NDK environment to provide, it's never added to the arguments passed after `--`; for example a `cargo apk -- test --no-run` will try to build tests for the host unless explicitly called with `--target`. --- cargo-apk/CHANGELOG.md | 1 + cargo-apk/src/apk.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cargo-apk/CHANGELOG.md b/cargo-apk/CHANGELOG.md index 594a7005..1f99770d 100644 --- a/cargo-apk/CHANGELOG.md +++ b/cargo-apk/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - Move NDK r23 `-lgcc` workaround to `ndk-build::cargo::cargo_ndk`, to also apply to our `cargo apk --` invocations. ([#286](https://github.com/rust-windowing/android-ndk-rs/pull/286)) +- Append `--target` to blanket `cargo apk --` calls when not provided by the user. ([#287](https://github.com/rust-windowing/android-ndk-rs/pull/287)) # 0.9.1 (2022-05-12) diff --git a/cargo-apk/src/apk.rs b/cargo-apk/src/apk.rs index 892ba01d..ae8e997f 100644 --- a/cargo-apk/src/apk.rs +++ b/cargo-apk/src/apk.rs @@ -98,7 +98,6 @@ impl<'a> ApkBuilder<'a> { pub fn check(&self) -> Result<(), Error> { for target in &self.build_targets { - let triple = target.rust_triple(); let mut cargo = cargo_ndk( &self.ndk, *target, @@ -107,6 +106,7 @@ impl<'a> ApkBuilder<'a> { )?; cargo.arg("check"); if self.cmd.target().is_none() { + let triple = target.rust_triple(); cargo.arg("--target").arg(triple); } cargo.args(self.cmd.args()); @@ -246,6 +246,12 @@ impl<'a> ApkBuilder<'a> { self.cmd.target_dir(), )?; cargo.args(self.cmd.args()); + + if self.cmd.target().is_none() { + let triple = target.rust_triple(); + cargo.arg("--target").arg(triple); + } + if !cargo.status()?.success() { return Err(NdkError::CmdFailed(cargo).into()); }