Explorar o código

feat(cli.rs): build tools info (#2618)

Lucas Fernandes Nogueira %!s(int64=3) %!d(string=hai) anos
pai
achega
d5f07d14f3

+ 5 - 0
.changes/cli.rs-build-tools-info.md

@@ -0,0 +1,5 @@
+---
+"cli.rs": patch
+---
+
+Add `Visual Studio Build Tools` installed versions to the `info` command output.

+ 1 - 13
core/tauri-runtime/src/lib.rs

@@ -37,7 +37,7 @@ use crate::http::{
 
 #[cfg(feature = "system-tray")]
 #[non_exhaustive]
-#[derive(Debug)]
+#[derive(Debug, Default)]
 pub struct SystemTray {
   pub icon: Option<Icon>,
   pub menu: Option<menu::SystemTrayMenu>,
@@ -45,18 +45,6 @@ pub struct SystemTray {
   pub icon_as_template: bool,
 }
 
-#[cfg(feature = "system-tray")]
-impl Default for SystemTray {
-  fn default() -> Self {
-    Self {
-      icon: None,
-      menu: None,
-      #[cfg(target_os = "macos")]
-      icon_as_template: false,
-    }
-  }
-}
-
 #[cfg(feature = "system-tray")]
 impl SystemTray {
   /// Creates a new system tray that only renders an icon.

+ 2 - 14
core/tauri-runtime/src/menu.rs

@@ -154,7 +154,7 @@ pub trait TrayHandle: fmt::Debug {
 }
 
 /// A window menu.
-#[derive(Debug, Clone)]
+#[derive(Debug, Default, Clone)]
 #[non_exhaustive]
 pub struct Menu {
   pub items: Vec<MenuEntry>,
@@ -179,12 +179,6 @@ impl Submenu {
   }
 }
 
-impl Default for Menu {
-  fn default() -> Self {
-    Self { items: Vec::new() }
-  }
-}
-
 impl Menu {
   /// Creates a new window menu.
   pub fn new() -> Self {
@@ -274,18 +268,12 @@ impl CustomMenuItem {
 }
 
 /// A system tray menu.
-#[derive(Debug, Clone)]
+#[derive(Debug, Default, Clone)]
 #[non_exhaustive]
 pub struct SystemTrayMenu {
   pub items: Vec<SystemTrayMenuEntry>,
 }
 
-impl Default for SystemTrayMenu {
-  fn default() -> Self {
-    Self { items: Vec::new() }
-  }
-}
-
 #[derive(Debug, Clone)]
 #[non_exhaustive]
 pub struct SystemTraySubmenu {

+ 2 - 4
core/tauri/src/endpoints/dialog.rs

@@ -3,8 +3,6 @@
 // SPDX-License-Identifier: MIT
 
 use super::InvokeResponse;
-#[cfg(any(windows, target_os = "macos"))]
-use crate::api::dialog::window_parent;
 #[cfg(any(dialog_open, dialog_save))]
 use crate::api::dialog::FileDialogBuilder;
 use crate::{
@@ -145,7 +143,7 @@ pub fn open<R: Runtime>(
   let mut dialog_builder = FileDialogBuilder::new();
   #[cfg(any(windows, target_os = "macos"))]
   {
-    dialog_builder = dialog_builder.set_parent(&window_parent(window)?);
+    dialog_builder = dialog_builder.set_parent(&crate::api::dialog::window_parent(window)?);
   }
   if let Some(default_path) = options.default_path {
     if !default_path.exists() {
@@ -181,7 +179,7 @@ pub fn save<R: Runtime>(
   let mut dialog_builder = FileDialogBuilder::new();
   #[cfg(any(windows, target_os = "macos"))]
   {
-    dialog_builder = dialog_builder.set_parent(&window_parent(&window)?);
+    dialog_builder = dialog_builder.set_parent(&crate::api::dialog::window_parent(&window)?);
   }
   if let Some(default_path) = options.default_path {
     dialog_builder = set_default_path(dialog_builder, default_path);

+ 1 - 0
core/tauri/src/updater/core.rs

@@ -389,6 +389,7 @@ pub struct Update {
   /// Update publish date
   pub date: String,
   /// Target
+  #[allow(dead_code)]
   target: String,
   /// Extract path
   extract_path: PathBuf,

+ 2 - 0
examples/commands/src-tauri/src/main.rs

@@ -16,7 +16,9 @@ use tauri::{command, State, Window};
 
 #[derive(Debug)]
 pub struct MyState {
+  #[allow(dead_code)]
   value: u64,
+  #[allow(dead_code)]
   label: String,
 }
 

+ 57 - 2
tooling/cli.rs/src/info.rs

@@ -50,8 +50,6 @@ struct VersionMetadata {
 struct CargoManifestDependencyPackage {
   version: Option<String>,
   path: Option<PathBuf>,
-  #[serde(default)]
-  features: Vec<String>,
 }
 
 #[derive(Clone, Deserialize)]
@@ -291,6 +289,45 @@ fn webview2_version() -> crate::Result<Option<String>> {
   Ok(version)
 }
 
+#[cfg(windows)]
+fn run_vs_setup_instance() -> std::io::Result<std::process::Output> {
+  Command::new("powershell")
+    .args(&["-NoProfile", "-Command"])
+    .arg("Get-VSSetupInstance")
+    .output()
+}
+
+#[cfg(windows)]
+fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
+  let mut output = run_vs_setup_instance();
+  if output.is_err() {
+    Command::new("powershell")
+      .args(&["-NoProfile", "-Command"])
+      .arg("Install-Module VSSetup -Scope CurrentUser")
+      .output()?;
+    output = run_vs_setup_instance();
+  }
+  let output = output?;
+  let versions = if output.status.success() {
+    let stdout = String::from_utf8_lossy(&output.stdout);
+    let mut versions = Vec::new();
+
+    let regex = regex::Regex::new(r"Visual Studio Build Tools (?P<version>\d+)").unwrap();
+    for caps in regex.captures_iter(&stdout) {
+      versions.push(caps["version"].to_string());
+    }
+
+    if versions.is_empty() {
+      None
+    } else {
+      Some(versions)
+    }
+  } else {
+    None
+  };
+  Ok(versions)
+}
+
 struct InfoBlock {
   section: bool,
   key: &'static str,
@@ -403,6 +440,24 @@ impl Info {
 
     #[cfg(windows)]
     VersionBlock::new("Webview2", webview2_version().unwrap_or_default()).display();
+    #[cfg(windows)]
+    VersionBlock::new(
+      "Visual Studio Build Tools",
+      build_tools_version()
+        .map(|r| {
+          let required_string = "(>= 2019 required)";
+          let multiple_string =
+            "(multiple versions might conflict; keep only 2019 if build errors occur)";
+          r.map(|v| match v.len() {
+            1 if v[0].as_str() < "2019" => format!("{} {}", v[0], required_string),
+            1 if v[0].as_str() >= "2019" => v[0].clone(),
+            _ if v.contains(&"2019".into()) => format!("{} {}", v.join(", "), multiple_string),
+            _ => format!("{} {} {}", v.join(", "), required_string, multiple_string),
+          })
+        })
+        .unwrap_or_default(),
+    )
+    .display();
 
     let hook = panic::take_hook();
     panic::set_hook(Box::new(|_info| {