Skip to content

Commit c7056d1

Browse files
authored
fix(cli): improve vs build tools detection (#6982)
* fix(cli): improve vs build tools detection * clean up * typos * changefile * patch instead of minor * update vswhere * use vswhere instead of custom logic. update wording * sort and dedup manually
1 parent acc36fe commit c7056d1

5 files changed

Lines changed: 54 additions & 21 deletions

File tree

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+
Improve Visual Studio installation detection in `tauri info` command to check for the necessary components instead of whole workloads. This also fixes the detection of minimal installations and auto-installations done by `rustup`.

tooling/cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ itertools = "0.10"
8484

8585
[target."cfg(windows)".dependencies]
8686
winapi = { version = "0.3", features = [ "handleapi", "processenv", "winbase", "wincon", "winnt" ] }
87+
cc = "1"
8788

8889
[target."cfg(unix)".dependencies]
8990
libc = "0.2"

tooling/cli/scripts/vswhere.exe

-16 Bytes
Binary file not shown.

tooling/cli/src/info/env_system.rs

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct VsInstanceInfo {
2020
const VSWHERE: &[u8] = include_bytes!("../../scripts/vswhere.exe");
2121

2222
#[cfg(windows)]
23-
fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
23+
fn build_tools_version() -> crate::Result<Vec<String>> {
2424
let mut vswhere = std::env::temp_dir();
2525
vswhere.push("vswhere.exe");
2626

@@ -30,32 +30,60 @@ fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
3030
let _ = file.write_all(VSWHERE);
3131
}
3232
}
33-
let output = Command::new(vswhere)
33+
34+
// Check if there are Visual Studio installations that have the "MSVC - C++ Buildtools" and "Windows SDK" components.
35+
// Both the Windows 10 and Windows 11 SDKs work so we need to query it twice.
36+
let output_sdk10 = Command::new(&vswhere)
37+
.args([
38+
"-prerelease",
39+
"-products",
40+
"*",
41+
"-requires",
42+
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
43+
"-requires",
44+
"Microsoft.VisualStudio.Component.Windows10SDK.*",
45+
"-format",
46+
"json",
47+
])
48+
.output()?;
49+
50+
let output_sdk11 = Command::new(vswhere)
3451
.args([
3552
"-prerelease",
3653
"-products",
3754
"*",
38-
"-requiresAny",
3955
"-requires",
40-
"Microsoft.VisualStudio.Workload.NativeDesktop",
56+
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
4157
"-requires",
42-
"Microsoft.VisualStudio.Workload.VCTools",
58+
"Microsoft.VisualStudio.Component.Windows11SDK.*",
4359
"-format",
4460
"json",
4561
])
4662
.output()?;
47-
Ok(if output.status.success() {
48-
let stdout = String::from_utf8_lossy(&output.stdout);
49-
let instances: Vec<VsInstanceInfo> = serde_json::from_str(&stdout)?;
50-
Some(
51-
instances
52-
.iter()
53-
.map(|i| i.display_name.clone())
54-
.collect::<Vec<String>>(),
55-
)
56-
} else {
57-
None
58-
})
63+
64+
let mut instances: Vec<VsInstanceInfo> = Vec::new();
65+
66+
if output_sdk10.status.success() {
67+
let stdout = String::from_utf8_lossy(&output_sdk10.stdout);
68+
let found: Vec<VsInstanceInfo> = serde_json::from_str(&stdout)?;
69+
instances.extend(found);
70+
}
71+
72+
if output_sdk11.status.success() {
73+
let stdout = String::from_utf8_lossy(&output_sdk11.stdout);
74+
let found: Vec<VsInstanceInfo> = serde_json::from_str(&stdout)?;
75+
instances.extend(found);
76+
}
77+
78+
let mut instances: Vec<String> = instances
79+
.iter()
80+
.map(|i| i.display_name.clone())
81+
.collect::<Vec<String>>();
82+
83+
instances.sort_unstable();
84+
instances.dedup();
85+
86+
Ok(instances)
5987
}
6088

6189
#[cfg(windows)]
@@ -190,13 +218,11 @@ pub fn items() -> Vec<SectionItem> {
190218
#[cfg(windows)]
191219
SectionItem::new(
192220
|| {
193-
let build_tools = build_tools_version()
194-
.unwrap_or_default()
195-
.unwrap_or_default();
221+
let build_tools = build_tools_version().unwrap_or_default();
196222
if build_tools.is_empty() {
197223
Some((
198224
format!(
199-
"Couldn't detect Visual Studio or Visual Studio Build Tools. Download from {}",
225+
"Couldn't detect any Visual Studio or VS Build Tools instance with MSVC and SDK components. Download from {}",
200226
"https://aka.ms/vs/17/release/vs_BuildTools.exe".cyan()
201227
),
202228
Status::Error,

0 commit comments

Comments
 (0)