Skip to content

Commit

Permalink
feat: add --skip-targets-install (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Sep 6, 2023
1 parent a82bf57 commit a26988a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/skip-targets-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-mobile": "patch"
---

Add `--skip-targets-install` option for `cargo mobile new` and `cargo mobile init`
7 changes: 5 additions & 2 deletions src/android/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ pub fn gen(
wrapper: &TextWrapper,
filter: &templating::Filter,
dot_cargo: &mut dot_cargo::DotCargo,
skip_targets_install: bool,
) -> Result<(), Error> {
println!("Installing Android toolchains...");
Target::install_all().map_err(Error::RustupFailed)?;
if !skip_targets_install {
println!("Installing Android toolchains...");
Target::install_all().map_err(Error::RustupFailed)?;
}
println!("Generating Android Studio project...");
let src = Pack::lookup_platform(TEMPLATE_PACK)
.map_err(Error::MissingPack)?
Expand Down
7 changes: 5 additions & 2 deletions src/apple/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ pub fn gen(
skip_dev_tools: bool,
reinstall_deps: bool,
filter: &templating::Filter,
skip_targets_install: bool,
) -> Result<(), Error> {
println!("Installing iOS toolchains...");
Target::install_all().map_err(Error::RustupFailed)?;
if !skip_targets_install {
println!("Installing iOS toolchains...");
Target::install_all().map_err(Error::RustupFailed)?;
}
rust_version_check(wrapper).map_err(Error::RustVersionCheckFailed)?;

deps::install_all(wrapper, non_interactive, skip_dev_tools, reinstall_deps)
Expand Down
15 changes: 15 additions & 0 deletions src/bin/cargo-mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub enum Command {
#[structopt(flatten)]
skip_dev_tools: cli::SkipDevTools,
#[structopt(flatten)]
skip_targets_install: cli::SkipTargetsInstall,
#[structopt(flatten)]
reinstall_deps: cli::ReinstallDeps,
#[structopt(long = "open", help = "Open in default code editor")]
open_in_editor: bool,
Expand All @@ -50,6 +52,8 @@ pub enum Command {
#[structopt(flatten)]
skip_dev_tools: cli::SkipDevTools,
#[structopt(flatten)]
skip_targets_install: cli::SkipTargetsInstall,
#[structopt(flatten)]
reinstall_deps: cli::ReinstallDeps,
#[structopt(long = "open", help = "Open in default code editor")]
open_in_editor: bool,
Expand Down Expand Up @@ -148,13 +152,18 @@ impl Exec for Input {
match command {
Command::Init {
skip_dev_tools: cli::SkipDevTools { skip_dev_tools },
skip_targets_install:
cli::SkipTargetsInstall {
skip_targets_install,
},
reinstall_deps: cli::ReinstallDeps { reinstall_deps },
open_in_editor,
submodule_commit,
} => init::exec(
wrapper,
non_interactive,
skip_dev_tools,
skip_targets_install,
reinstall_deps,
open_in_editor,
submodule_commit,
Expand All @@ -164,6 +173,10 @@ impl Exec for Input {
.map_err(|e| Error::InitFailed(*e)),
Command::New {
skip_dev_tools: cli::SkipDevTools { skip_dev_tools },
skip_targets_install:
cli::SkipTargetsInstall {
skip_targets_install,
},
reinstall_deps: cli::ReinstallDeps { reinstall_deps },
open_in_editor,
submodule_commit,
Expand All @@ -181,6 +194,7 @@ impl Exec for Input {
wrapper,
non_interactive,
skip_dev_tools,
skip_targets_install,
reinstall_deps,
open_in_editor,
submodule_commit,
Expand All @@ -200,6 +214,7 @@ impl Exec for Input {
Default::default(),
Default::default(),
Default::default(),
Default::default(),
".",
)
.map_err(|e| Error::InitFailed(*e))?;
Expand Down
3 changes: 3 additions & 0 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub fn exec(
wrapper: &TextWrapper,
non_interactive: bool,
skip_dev_tools: bool,
skip_targets_install: bool,
#[cfg_attr(not(target_os = "macos"), allow(unused))] reinstall_deps: bool,
open_in_editor: bool,
submodule_commit: Option<String>,
Expand Down Expand Up @@ -176,6 +177,7 @@ pub fn exec(
skip_dev_tools,
reinstall_deps,
&filter,
skip_targets_install,
)
.map_err(Error::AppleInitFailed)?;
} else {
Expand All @@ -193,6 +195,7 @@ pub fn exec(
wrapper,
&filter,
&mut dot_cargo,
skip_targets_install,
)
.map_err(Error::AndroidInitFailed)?,
Err(err) => {
Expand Down
9 changes: 9 additions & 0 deletions src/util/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ mod interface {
pub skip_dev_tools: bool,
}

#[derive(Clone, Copy, Debug, StructOpt)]
pub struct SkipTargetsInstall {
#[structopt(
long = "skip-targets-install",
help = "Skip installing andriod/ios targets for rust through rustup "
)]
pub skip_targets_install: bool,
}

#[derive(Clone, Copy, Debug, StructOpt)]
pub struct ReinstallDeps {
#[structopt(long = "reinstall-deps", help = "Reinstall dependencies")]
Expand Down

0 comments on commit a26988a

Please sign in to comment.