Skip to content

Commit 6f8e1d2

Browse files
fix: detect and install Visual Studio Build Tools for Rust on Windows
The real issue on Windows was missing MSVC linker (link.exe) required by Rust. Added detection of linker errors and automatic installation of Visual Studio Build Tools via winget. Changes: - Detect link.exe errors and offer to install VS Build Tools - Use winget to install Microsoft.VisualStudio.2022.BuildTools - Update manual instructions to highlight build tools prerequisite - Provide direct link to VS Build Tools download page This addresses the cargo compilation failures on Windows 11.
1 parent 828a24c commit 6f8e1d2

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
### Features
1212

1313
- add winget support to automatically install Rust/Cargo on Windows when missing ([just-lsp-installer.ts:259](https://github.com/elasticdotventures/just-vscode-extension/blob/main/src/just-lsp-installer.ts#L259))
14-
- improve manual installation instructions with platform-specific guidance including winget commands
14+
- detect missing Visual Studio Build Tools and offer automatic installation via winget
15+
- improve manual installation instructions with platform-specific guidance including build tools prerequisites
1516

1617
### Bug Fixes
1718

src/just-lsp-installer.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,58 @@ export class JustLspInstaller {
385385
} catch (error) {
386386
const errorMsg = error instanceof Error ? error.message : String(error);
387387
logger.errorFromException(error, 'Cargo installation failed', 'JustLspInstaller');
388+
389+
// Check if this is a linker error indicating missing Visual Studio Build Tools
390+
if (errorMsg.includes('link.exe') && errorMsg.includes('Visual Studio build tools')) {
391+
if (process.platform === 'win32') {
392+
const choice = await vscode.window.showErrorMessage(
393+
'Rust compilation requires Visual Studio Build Tools with C++ support. Would you like to install them?',
394+
'Install Build Tools',
395+
'Manual Instructions',
396+
'Cancel'
397+
);
398+
399+
if (choice === 'Install Build Tools') {
400+
try {
401+
// Try using winget to install Visual Studio Build Tools
402+
await asyncExec('winget install --id Microsoft.VisualStudio.2022.BuildTools --accept-source-agreements --accept-package-agreements', {
403+
timeout: 600000 // 10 minutes
404+
});
405+
406+
vscode.window.showInformationMessage(
407+
'Visual Studio Build Tools installed. Please restart VS Code and try installing just-lsp again.',
408+
'Reload Window'
409+
).then(choice => {
410+
if (choice === 'Reload Window') {
411+
vscode.commands.executeCommand('workbench.action.reloadWindow');
412+
}
413+
});
414+
415+
return {
416+
success: false,
417+
error: 'Visual Studio Build Tools installed. Please reload VS Code and retry installation.'
418+
};
419+
} catch (installError) {
420+
vscode.window.showErrorMessage(
421+
'Failed to install Build Tools automatically. Please install manually.',
422+
'Open Instructions'
423+
).then(choice => {
424+
if (choice === 'Open Instructions') {
425+
vscode.env.openExternal(vscode.Uri.parse('https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022'));
426+
}
427+
});
428+
}
429+
} else if (choice === 'Manual Instructions') {
430+
vscode.env.openExternal(vscode.Uri.parse('https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022'));
431+
}
432+
}
433+
434+
return {
435+
success: false,
436+
error: 'Missing Visual Studio Build Tools with C++ support. Required for compiling Rust programs on Windows.'
437+
};
438+
}
439+
388440
return {
389441
success: false,
390442
error: `Cargo installation failed: ${errorMsg}`
@@ -419,6 +471,19 @@ export class JustLspInstaller {
419471
instructions += `
420472
## Windows Installation
421473
474+
### Prerequisites
475+
**IMPORTANT**: Rust on Windows requires Visual Studio Build Tools with C++ support.
476+
477+
Install build tools:
478+
\`\`\`powershell
479+
# Option A: Install via winget
480+
winget install Microsoft.VisualStudio.2022.BuildTools
481+
482+
# Option B: Download manually from:
483+
# https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
484+
# Make sure to select "Desktop development with C++" workload
485+
\`\`\`
486+
422487
### Option 1: Install with Cargo (Recommended)
423488
\`\`\`powershell
424489
# If you don't have Rust/Cargo installed:

0 commit comments

Comments
 (0)