feat(cli/mobile/init): skip installing already installed targets, closes #7044 (#7058)

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio>
closes #7044
This commit is contained in:
Amr Bashir 2023-05-26 05:36:06 +03:00 committed by GitHub
parent e0f0dce220
commit a28fdf7ec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 5 deletions

View File

@ -0,0 +1,6 @@
---
'cli.rs': 'patch'
'cli.js': 'patch'
---
Skip Rust target installation if they are already installed.

View File

@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT
name: Check generated files
name: check license header
on:
pull_request:

View File

@ -36,6 +36,7 @@ use tauri_utils::display_path;
mod cargo_config;
mod desktop;
pub mod installation;
pub mod manifest;
use cargo_config::Config as CargoConfig;
use manifest::{rewrite_manifest, Manifest};

View File

@ -0,0 +1,26 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use crate::Result;
use std::{fs::read_dir, path::PathBuf, process::Command};
pub fn installed_targets() -> Result<Vec<String>> {
let output = Command::new("rustc")
.args(["--print", "sysroot"])
.output()?;
let sysroot_path = PathBuf::from(String::from_utf8_lossy(&output.stdout).trim().to_string());
let mut targets = Vec::new();
for entry in read_dir(sysroot_path.join("lib").join("rustlib"))?.flatten() {
if entry.file_type().map(|t| t.is_dir()).unwrap_or_default() {
let name = entry.file_name();
if name != "etc" && name != "src" {
targets.push(name.to_string_lossy().into_owned());
}
}
}
Ok(targets)
}

View File

@ -35,8 +35,22 @@ pub fn gen(
(handlebars, mut map): (Handlebars, template::JsonMap),
wrapper: &TextWrapper,
) -> Result<()> {
println!("Installing Android toolchains...");
Target::install_all().with_context(|| "failed to run rustup")?;
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
let missing_targets = Target::all()
.values()
.filter(|t| !installed_targets.contains(&t.triple().into()))
.collect::<Vec<&Target>>();
if !missing_targets.is_empty() {
println!("Installing Android Rust toolchains...");
for target in missing_targets {
target
.install()
.context("failed to install target with rustup")?;
}
}
println!("Generating Android Studio project...");
let dest = config.project_dir();
let asset_packs = metadata.asset_packs().unwrap_or_default();

View File

@ -34,8 +34,22 @@ pub fn gen(
non_interactive: bool,
reinstall_deps: bool,
) -> Result<()> {
println!("Installing iOS toolchains...");
Target::install_all()?;
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
let missing_targets = Target::all()
.values()
.filter(|t| !installed_targets.contains(&t.triple().into()))
.collect::<Vec<&Target>>();
if !missing_targets.is_empty() {
println!("Installing iOS Rust toolchains...");
for target in missing_targets {
target
.install()
.context("failed to install target with rustup")?;
}
}
rust_version_check(wrapper)?;
deps::install_all(wrapper, non_interactive, true, reinstall_deps)