Skip to content

Commit a28fdf7

Browse files
authored
feat(cli/mobile/init): skip installing already installed targets, closes #7044 (#7058)
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio> closes #7044
1 parent e0f0dce commit a28fdf7

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed

.changes/cli-skip-targets-install.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'cli.rs': 'patch'
3+
'cli.js': 'patch'
4+
---
5+
6+
Skip Rust target installation if they are already installed.

.github/workflows/check-license-header.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
# SPDX-License-Identifier: MIT
44

5-
name: Check generated files
5+
name: check license header
66

77
on:
88
pull_request:

tooling/cli/src/interface/rust.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use tauri_utils::display_path;
3636

3737
mod cargo_config;
3838
mod desktop;
39+
pub mod installation;
3940
pub mod manifest;
4041
use cargo_config::Config as CargoConfig;
4142
use manifest::{rewrite_manifest, Manifest};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use crate::Result;
6+
7+
use std::{fs::read_dir, path::PathBuf, process::Command};
8+
9+
pub fn installed_targets() -> Result<Vec<String>> {
10+
let output = Command::new("rustc")
11+
.args(["--print", "sysroot"])
12+
.output()?;
13+
let sysroot_path = PathBuf::from(String::from_utf8_lossy(&output.stdout).trim().to_string());
14+
15+
let mut targets = Vec::new();
16+
for entry in read_dir(sysroot_path.join("lib").join("rustlib"))?.flatten() {
17+
if entry.file_type().map(|t| t.is_dir()).unwrap_or_default() {
18+
let name = entry.file_name();
19+
if name != "etc" && name != "src" {
20+
targets.push(name.to_string_lossy().into_owned());
21+
}
22+
}
23+
}
24+
25+
Ok(targets)
26+
}

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,22 @@ pub fn gen(
3535
(handlebars, mut map): (Handlebars, template::JsonMap),
3636
wrapper: &TextWrapper,
3737
) -> Result<()> {
38-
println!("Installing Android toolchains...");
39-
Target::install_all().with_context(|| "failed to run rustup")?;
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")?;
51+
}
52+
}
53+
4054
println!("Generating Android Studio project...");
4155
let dest = config.project_dir();
4256
let asset_packs = metadata.asset_packs().unwrap_or_default();

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,22 @@ pub fn gen(
3434
non_interactive: bool,
3535
reinstall_deps: bool,
3636
) -> Result<()> {
37-
println!("Installing iOS toolchains...");
38-
Target::install_all()?;
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")?;
50+
}
51+
}
52+
3953
rust_version_check(wrapper)?;
4054

4155
deps::install_all(wrapper, non_interactive, true, reinstall_deps)

0 commit comments

Comments
 (0)