mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 11:22:04 +00:00
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:
parent
c23bec62d6
commit
f70b28529d
6
.changes/ensure-targets-mobile.md
Normal file
6
.changes/ensure-targets-mobile.md
Normal 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).
|
||||
@ -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,
|
||||
|
||||
@ -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)?;
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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")?;
|
||||
|
||||
@ -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")?;
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user