Skip to content

Commit d5f07d1

Browse files
authored
feat(cli.rs): build tools info (#2618)
1 parent 84f6e3e commit d5f07d1

File tree

7 files changed

+70
-33
lines changed

7 files changed

+70
-33
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Add `Visual Studio Build Tools` installed versions to the `info` command output.

core/tauri-runtime/src/lib.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,14 @@ use crate::http::{
3737

3838
#[cfg(feature = "system-tray")]
3939
#[non_exhaustive]
40-
#[derive(Debug)]
40+
#[derive(Debug, Default)]
4141
pub struct SystemTray {
4242
pub icon: Option<Icon>,
4343
pub menu: Option<menu::SystemTrayMenu>,
4444
#[cfg(target_os = "macos")]
4545
pub icon_as_template: bool,
4646
}
4747

48-
#[cfg(feature = "system-tray")]
49-
impl Default for SystemTray {
50-
fn default() -> Self {
51-
Self {
52-
icon: None,
53-
menu: None,
54-
#[cfg(target_os = "macos")]
55-
icon_as_template: false,
56-
}
57-
}
58-
}
59-
6048
#[cfg(feature = "system-tray")]
6149
impl SystemTray {
6250
/// Creates a new system tray that only renders an icon.

core/tauri-runtime/src/menu.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub trait TrayHandle: fmt::Debug {
154154
}
155155

156156
/// A window menu.
157-
#[derive(Debug, Clone)]
157+
#[derive(Debug, Default, Clone)]
158158
#[non_exhaustive]
159159
pub struct Menu {
160160
pub items: Vec<MenuEntry>,
@@ -179,12 +179,6 @@ impl Submenu {
179179
}
180180
}
181181

182-
impl Default for Menu {
183-
fn default() -> Self {
184-
Self { items: Vec::new() }
185-
}
186-
}
187-
188182
impl Menu {
189183
/// Creates a new window menu.
190184
pub fn new() -> Self {
@@ -274,18 +268,12 @@ impl CustomMenuItem {
274268
}
275269

276270
/// A system tray menu.
277-
#[derive(Debug, Clone)]
271+
#[derive(Debug, Default, Clone)]
278272
#[non_exhaustive]
279273
pub struct SystemTrayMenu {
280274
pub items: Vec<SystemTrayMenuEntry>,
281275
}
282276

283-
impl Default for SystemTrayMenu {
284-
fn default() -> Self {
285-
Self { items: Vec::new() }
286-
}
287-
}
288-
289277
#[derive(Debug, Clone)]
290278
#[non_exhaustive]
291279
pub struct SystemTraySubmenu {

core/tauri/src/endpoints/dialog.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// SPDX-License-Identifier: MIT
44

55
use super::InvokeResponse;
6-
#[cfg(any(windows, target_os = "macos"))]
7-
use crate::api::dialog::window_parent;
86
#[cfg(any(dialog_open, dialog_save))]
97
use crate::api::dialog::FileDialogBuilder;
108
use crate::{
@@ -145,7 +143,7 @@ pub fn open<R: Runtime>(
145143
let mut dialog_builder = FileDialogBuilder::new();
146144
#[cfg(any(windows, target_os = "macos"))]
147145
{
148-
dialog_builder = dialog_builder.set_parent(&window_parent(window)?);
146+
dialog_builder = dialog_builder.set_parent(&crate::api::dialog::window_parent(window)?);
149147
}
150148
if let Some(default_path) = options.default_path {
151149
if !default_path.exists() {
@@ -181,7 +179,7 @@ pub fn save<R: Runtime>(
181179
let mut dialog_builder = FileDialogBuilder::new();
182180
#[cfg(any(windows, target_os = "macos"))]
183181
{
184-
dialog_builder = dialog_builder.set_parent(&window_parent(&window)?);
182+
dialog_builder = dialog_builder.set_parent(&crate::api::dialog::window_parent(&window)?);
185183
}
186184
if let Some(default_path) = options.default_path {
187185
dialog_builder = set_default_path(dialog_builder, default_path);

core/tauri/src/updater/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ pub struct Update {
389389
/// Update publish date
390390
pub date: String,
391391
/// Target
392+
#[allow(dead_code)]
392393
target: String,
393394
/// Extract path
394395
extract_path: PathBuf,

examples/commands/src-tauri/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use tauri::{command, State, Window};
1616

1717
#[derive(Debug)]
1818
pub struct MyState {
19+
#[allow(dead_code)]
1920
value: u64,
21+
#[allow(dead_code)]
2022
label: String,
2123
}
2224

tooling/cli.rs/src/info.rs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ struct VersionMetadata {
5050
struct CargoManifestDependencyPackage {
5151
version: Option<String>,
5252
path: Option<PathBuf>,
53-
#[serde(default)]
54-
features: Vec<String>,
5553
}
5654

5755
#[derive(Clone, Deserialize)]
@@ -291,6 +289,45 @@ fn webview2_version() -> crate::Result<Option<String>> {
291289
Ok(version)
292290
}
293291

292+
#[cfg(windows)]
293+
fn run_vs_setup_instance() -> std::io::Result<std::process::Output> {
294+
Command::new("powershell")
295+
.args(&["-NoProfile", "-Command"])
296+
.arg("Get-VSSetupInstance")
297+
.output()
298+
}
299+
300+
#[cfg(windows)]
301+
fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
302+
let mut output = run_vs_setup_instance();
303+
if output.is_err() {
304+
Command::new("powershell")
305+
.args(&["-NoProfile", "-Command"])
306+
.arg("Install-Module VSSetup -Scope CurrentUser")
307+
.output()?;
308+
output = run_vs_setup_instance();
309+
}
310+
let output = output?;
311+
let versions = if output.status.success() {
312+
let stdout = String::from_utf8_lossy(&output.stdout);
313+
let mut versions = Vec::new();
314+
315+
let regex = regex::Regex::new(r"Visual Studio Build Tools (?P<version>\d+)").unwrap();
316+
for caps in regex.captures_iter(&stdout) {
317+
versions.push(caps["version"].to_string());
318+
}
319+
320+
if versions.is_empty() {
321+
None
322+
} else {
323+
Some(versions)
324+
}
325+
} else {
326+
None
327+
};
328+
Ok(versions)
329+
}
330+
294331
struct InfoBlock {
295332
section: bool,
296333
key: &'static str,
@@ -403,6 +440,24 @@ impl Info {
403440

404441
#[cfg(windows)]
405442
VersionBlock::new("Webview2", webview2_version().unwrap_or_default()).display();
443+
#[cfg(windows)]
444+
VersionBlock::new(
445+
"Visual Studio Build Tools",
446+
build_tools_version()
447+
.map(|r| {
448+
let required_string = "(>= 2019 required)";
449+
let multiple_string =
450+
"(multiple versions might conflict; keep only 2019 if build errors occur)";
451+
r.map(|v| match v.len() {
452+
1 if v[0].as_str() < "2019" => format!("{} {}", v[0], required_string),
453+
1 if v[0].as_str() >= "2019" => v[0].clone(),
454+
_ if v.contains(&"2019".into()) => format!("{} {}", v.join(", "), multiple_string),
455+
_ => format!("{} {} {}", v.join(", "), required_string, multiple_string),
456+
})
457+
})
458+
.unwrap_or_default(),
459+
)
460+
.display();
406461

407462
let hook = panic::take_hook();
408463
panic::set_hook(Box::new(|_info| {

0 commit comments

Comments
 (0)