Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/cli-skip-targets-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'cli.rs': 'patch'
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
'cli.js': 'patch'
---

Skip Rust target installation if they are already installed.
2 changes: 1 addition & 1 deletion .github/workflows/check-license-header.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
26 changes: 26 additions & 0 deletions tooling/cli/src/interface/rust/installation.rs
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 16 additions & 2 deletions tooling/cli/src/mobile/android/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 16 additions & 2 deletions tooling/cli/src/mobile/ios/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down