Skip to content

Commit 735db1c

Browse files
authored
feat(cli/mobile/init): add --skip-targets-install, ref #7044 #7058 (#7062)
1 parent 7fee3d3 commit 735db1c

File tree

6 files changed

+72
-31
lines changed

6 files changed

+72
-31
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'cli.rs': 'patch:enhance'
3+
'cli.js': 'patch:enhance'
4+
---
5+
6+
Add `--skip-targets-install` flag for `tauri android init` and `tauri ios init` to skip installing needed rust targets vie rustup.

tooling/cli/src/mobile/android.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ pub struct InitOptions {
6262
/// Skip prompting for values
6363
#[clap(long)]
6464
ci: bool,
65+
/// Skips installing rust toolchains via rustup
66+
#[clap(long)]
67+
skip_targets_install: bool,
6568
}
6669

6770
#[derive(Subcommand)]
@@ -78,7 +81,12 @@ enum Commands {
7881
pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
7982
let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
8083
match cli.command {
81-
Commands::Init(options) => init_command(MobileTarget::Android, options.ci, false)?,
84+
Commands::Init(options) => init_command(
85+
MobileTarget::Android,
86+
options.ci,
87+
false,
88+
options.skip_targets_install,
89+
)?,
8290
Commands::Open => open::command()?,
8391
Commands::Dev(options) => dev::command(options, noise_level)?,
8492
Commands::Build(options) => build::command(options, noise_level)?,

tooling/cli/src/mobile/android/project.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,25 @@ pub fn gen(
3434
metadata: &Metadata,
3535
(handlebars, mut map): (Handlebars, template::JsonMap),
3636
wrapper: &TextWrapper,
37+
skip_targets_install: bool,
3738
) -> Result<()> {
38-
let installed_targets =
39-
crate::interface::rust::installation::installed_targets().unwrap_or_default();
40-
let missing_targets = Target::all()
41-
.values()
42-
.filter(|t| !installed_targets.contains(&t.triple().into()))
43-
.collect::<Vec<&Target>>();
44-
45-
if !missing_targets.is_empty() {
46-
println!("Installing Android Rust toolchains...");
47-
for target in missing_targets {
48-
target
49-
.install()
50-
.context("failed to install target with rustup")?;
39+
if !skip_targets_install {
40+
let installed_targets =
41+
crate::interface::rust::installation::installed_targets().unwrap_or_default();
42+
let missing_targets = Target::all()
43+
.values()
44+
.filter(|t| !installed_targets.contains(&t.triple().into()))
45+
.collect::<Vec<&Target>>();
46+
47+
if !missing_targets.is_empty() {
48+
println!("Installing Android Rust toolchains...");
49+
for target in missing_targets {
50+
target
51+
.install()
52+
.context("failed to install target with rustup")?;
53+
}
5154
}
5255
}
53-
5456
println!("Generating Android Studio project...");
5557
let dest = config.project_dir();
5658
let asset_packs = metadata.asset_packs().unwrap_or_default();

tooling/cli/src/mobile/init.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ use std::{
2424
path::PathBuf,
2525
};
2626

27-
pub fn command(target: Target, ci: bool, reinstall_deps: bool) -> Result<()> {
27+
pub fn command(
28+
target: Target,
29+
ci: bool,
30+
reinstall_deps: bool,
31+
skip_targets_install: bool,
32+
) -> Result<()> {
2833
let wrapper = TextWrapper::with_splitter(textwrap::termwidth(), textwrap::NoHyphenation);
2934
exec(
3035
target,
3136
&wrapper,
3237
ci || var_os("CI").is_some(),
3338
reinstall_deps,
39+
skip_targets_install,
3440
)
3541
.map_err(|e| anyhow::anyhow!("{:#}", e))?;
3642
Ok(())
@@ -78,6 +84,7 @@ pub fn exec(
7884
wrapper: &TextWrapper,
7985
#[allow(unused_variables)] non_interactive: bool,
8086
#[allow(unused_variables)] reinstall_deps: bool,
87+
skip_targets_install: bool,
8188
) -> Result<App> {
8289
let tauri_config = get_tauri_config(None)?;
8390
let tauri_config_guard = tauri_config.lock().unwrap();
@@ -154,7 +161,13 @@ pub fn exec(
154161
let (app, config, metadata) =
155162
super::android::get_config(Some(app), tauri_config_, &Default::default());
156163
map.insert("android", &config);
157-
super::android::project::gen(&config, &metadata, (handlebars, map), wrapper)?;
164+
super::android::project::gen(
165+
&config,
166+
&metadata,
167+
(handlebars, map),
168+
wrapper,
169+
skip_targets_install,
170+
)?;
158171
app
159172
}
160173
Err(err) => {
@@ -183,6 +196,7 @@ pub fn exec(
183196
wrapper,
184197
non_interactive,
185198
reinstall_deps,
199+
skip_targets_install,
186200
)?;
187201
app
188202
}

tooling/cli/src/mobile/ios.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub struct InitOptions {
6666
/// Reinstall dependencies
6767
#[clap(short, long)]
6868
reinstall_deps: bool,
69+
/// Skips installing rust toolchains via rustup
70+
#[clap(long)]
71+
skip_targets_install: bool,
6972
}
7073

7174
#[derive(Subcommand)]
@@ -82,7 +85,12 @@ enum Commands {
8285
pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
8386
let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
8487
match cli.command {
85-
Commands::Init(options) => init_command(MobileTarget::Ios, options.ci, options.reinstall_deps)?,
88+
Commands::Init(options) => init_command(
89+
MobileTarget::Ios,
90+
options.ci,
91+
options.reinstall_deps,
92+
options.skip_targets_install,
93+
)?,
8694
Commands::Open => open::command()?,
8795
Commands::Dev(options) => dev::command(options, noise_level)?,
8896
Commands::Build(options) => build::command(options, noise_level)?,

tooling/cli/src/mobile/ios/project.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ pub fn gen(
3333
wrapper: &TextWrapper,
3434
non_interactive: bool,
3535
reinstall_deps: bool,
36+
skip_targets_install: bool,
3637
) -> Result<()> {
37-
let installed_targets =
38-
crate::interface::rust::installation::installed_targets().unwrap_or_default();
39-
let missing_targets = Target::all()
40-
.values()
41-
.filter(|t| !installed_targets.contains(&t.triple().into()))
42-
.collect::<Vec<&Target>>();
43-
44-
if !missing_targets.is_empty() {
45-
println!("Installing iOS Rust toolchains...");
46-
for target in missing_targets {
47-
target
48-
.install()
49-
.context("failed to install target with rustup")?;
38+
if !skip_targets_install {
39+
let installed_targets =
40+
crate::interface::rust::installation::installed_targets().unwrap_or_default();
41+
let missing_targets = Target::all()
42+
.values()
43+
.filter(|t| !installed_targets.contains(&t.triple().into()))
44+
.collect::<Vec<&Target>>();
45+
46+
if !missing_targets.is_empty() {
47+
println!("Installing iOS Rust toolchains...");
48+
for target in missing_targets {
49+
target
50+
.install()
51+
.context("failed to install target with rustup")?;
52+
}
5053
}
5154
}
5255

0 commit comments

Comments
 (0)