feat(cli): ensure mobile Rust targets are installed (#14093)

currently we only install Rust targets for mobile when initializing the projects.

Users can commit the Android/iOS projects, so running the init command is not a requirement to develop mobile apps. This change ensures the Rust targets are installed before trying to compile them.
This commit is contained in:
Lucas Fernandes Nogueira 2025-08-27 18:05:24 -03:00 committed by GitHub
parent c23bec62d6
commit f70b28529d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 52 additions and 3 deletions

View File

@ -0,0 +1,6 @@
---
"@tauri-apps/cli": patch:enhance
"tauri-cli": patch:enhance
---
Ensure Rust targets for mobile are installed when running the dev and build commands (previously only checked on init).

View File

@ -132,11 +132,21 @@ pub fn command(options: Options) -> Result<()> {
let mut validated_lib = false;
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
call_for_targets_with_fallback(
options.targets.unwrap_or_default().iter(),
&detect_target_ok,
&env,
|target: &Target| {
if !installed_targets.contains(&target.triple().into()) {
log::info!("Installing target {}", target.triple());
target
.install()
.context("failed to install target with rustup")?;
}
target.build(
&config,
&metadata,

View File

@ -167,6 +167,15 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
crate::build::setup(&interface, &mut build_options, tauri_config.clone(), true)?;
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
if !installed_targets.contains(&first_target.triple().into()) {
log::info!("Installing target {}", first_target.triple());
first_target
.install()
.context("failed to install target with rustup")?;
}
// run an initial build to initialize plugins
first_target.build(&config, &metadata, &env, noise_level, true, profile)?;

View File

@ -252,12 +252,22 @@ fn run_dev(
configure_cargo(&mut env, config)?;
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
// run an initial build to initialize plugins
let target_triple = dev_options.target.as_ref().unwrap();
let target = Target::all()
.values()
.find(|t| t.triple == target_triple)
.unwrap_or_else(|| Target::all().values().next().unwrap());
if !installed_targets.contains(&target.triple().into()) {
log::info!("Installing target {}", target.triple());
target
.install()
.context("failed to install target with rustup")?;
}
target.build(
config,
metadata,

View File

@ -45,8 +45,9 @@ pub fn gen(
.collect::<Vec<&Target>>();
if !missing_targets.is_empty() {
println!("Installing Android Rust toolchains...");
log::info!("Installing Android Rust targets...");
for target in missing_targets {
log::info!("Installing target {}", target.triple());
target
.install()
.context("failed to install target with rustup")?;

View File

@ -50,8 +50,9 @@ pub fn gen(
.collect::<Vec<&Target>>();
if !missing_targets.is_empty() {
println!("Installing iOS Rust toolchains...");
log::info!("Installing iOS Rust targets...");
for target in missing_targets {
log::info!("Installing target {}", target.triple());
target
.install()
.context("failed to install target with rustup")?;

View File

@ -11,7 +11,7 @@ use crate::{
};
use anyhow::Context;
use cargo_mobile2::{apple::target::Target, opts::Profile};
use cargo_mobile2::{apple::target::Target, opts::Profile, target::TargetTrait};
use clap::{ArgAction, Parser};
use object::{Object, ObjectSymbol};
@ -209,6 +209,10 @@ pub fn command(options: Options) -> Result<()> {
} else {
options.arches
};
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
for arch in arches {
// Set target-specific flags
let (env_triple, rust_triple) = match arch.as_str() {
@ -251,6 +255,14 @@ pub fn command(options: Options) -> Result<()> {
)
})?
};
if !installed_targets.contains(&rust_triple.into()) {
log::info!("Installing target {}", target.triple());
target
.install()
.context("failed to install target with rustup")?;
}
target.compile_lib(
&config,
&metadata,