Skip to content

Commit af543d6

Browse files
Copilotsnehara99
andauthored
Add support for Visual Studio 18 2026 generator (#4688)
* Initial plan * Add support for Visual Studio 18 2026 generator Co-authored-by: snehara99 <[email protected]> * Add unit tests for VS generator version mapping Co-authored-by: snehara99 <[email protected]> * Fix issue number in changelog (#4637 instead of #4668) Co-authored-by: snehara99 <[email protected]> * Add runtime derivation of preferredGenerator for VS kits missing it Co-authored-by: snehara99 <[email protected]> * Restore .npmrc file that was accidentally removed Co-authored-by: snehara99 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: snehara99 <[email protected]>
1 parent ca28e03 commit af543d6

4 files changed

Lines changed: 89 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Bug Fixes:
1818
- Fix `cmake.compileFile` failing to find compilation info when using presets without `CMAKE_EXPORT_COMPILE_COMMANDS`. [#4484](https://github.com/microsoft/vscode-cmake-tools/issues/4484)
1919
- Fix "Copy Value" in CMake debugger copying variable name instead of value. [#4551](https://github.com/microsoft/vscode-cmake-tools/issues/4551)
2020
- cmakeDriver: Fixes getCompilerVersion by using compilerPath instead of compilerName. [#4647](https://github.com/microsoft/vscode-cmake-tools/pull/4647) [@lygstate](https://github.com/lygstate)
21+
- Add support for Visual Studio 2026 generator. [#4637](https://github.com/microsoft/vscode-cmake-tools/issues/4637)
2122
- Fix `$comment` not being accepted inside a cacheVariable object in CMake presets. [#4600](https://github.com/microsoft/vscode-cmake-tools/issues/4600)
2223
- Fix kits from `cmake.additionalKits` not being shown when `cmake.showSystemKits` is `false`. [#4651](https://github.com/microsoft/vscode-cmake-tools/issues/4651)
2324

src/drivers/cmakeDriver.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { CMakeOutputConsumer } from '@cmt/diagnostics/cmake';
1616
import { RawDiagnosticParser } from '@cmt/diagnostics/util';
1717
import { ProgressMessage } from '@cmt/drivers/drivers';
1818
import * as expand from '@cmt/expand';
19-
import { CMakeGenerator, effectiveKitEnvironment, Kit, kitChangeNeedsClean, KitDetect, getKitDetect, getVSKitEnvironment } from '@cmt/kits/kit';
19+
import { CMakeGenerator, effectiveKitEnvironment, Kit, kitChangeNeedsClean, KitDetect, getKitDetect, getVSKitEnvironment, getVsKitPreferredGenerator } from '@cmt/kits/kit';
2020
import * as logging from '@cmt/logging';
2121
import paths from '@cmt/paths';
2222
import { fs } from '@cmt/pr';
@@ -752,8 +752,14 @@ export abstract class CMakeDriver implements vscode.Disposable {
752752
this._kitEnvironmentVariables = await effectiveKitEnvironment(kit, this.expansionOptions);
753753

754754
// Place a kit preferred generator at the front of the list
755-
if (kit.preferredGenerator) {
756-
preferredGenerators.unshift(kit.preferredGenerator);
755+
// For VS kits that don't have preferredGenerator (e.g., scanned before a VS version was added),
756+
// try to derive it from the VS installation.
757+
let kitPreferredGenerator = kit.preferredGenerator;
758+
if (!kitPreferredGenerator && kit.visualStudio) {
759+
kitPreferredGenerator = await getVsKitPreferredGenerator(kit);
760+
}
761+
if (kitPreferredGenerator) {
762+
preferredGenerators.unshift(kitPreferredGenerator);
757763
}
758764

759765
// If no preferred generator is defined by the current kit or the user settings,
@@ -1368,6 +1374,7 @@ export abstract class CMakeDriver implements vscode.Disposable {
13681374
* The list of generators CMake supports as of 3.21
13691375
*/
13701376
private readonly cmakeGenerators = [
1377+
"Visual Studio 18 2026",
13711378
"Visual Studio 17 2022",
13721379
"Visual Studio 16 2019",
13731380
"Visual Studio 15 2017",

src/kits/kit.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,64 @@ const VsGenerators: { [key: string]: string } = {
764764
14: 'Visual Studio 14 2015',
765765
15: 'Visual Studio 15 2017',
766766
16: 'Visual Studio 16 2019',
767-
17: 'Visual Studio 17 2022'
767+
17: 'Visual Studio 17 2022',
768+
18: 'Visual Studio 18 2026'
768769
};
769770

771+
/**
772+
* Get the CMake generator name for a given Visual Studio version
773+
* @param version The major version of Visual Studio (e.g., '17' for VS 2022, '18' for VS 2026)
774+
* @returns The CMake generator name, or undefined if the version is not recognized
775+
*/
776+
export function vsGeneratorForVersion(version: string): string | undefined {
777+
return VsGenerators[version];
778+
}
779+
780+
/**
781+
* Get the preferred CMake generator for a Visual Studio kit.
782+
* This is useful for kits that were scanned before a VS version was added to the VsGenerators mapping.
783+
* @param kit The Visual Studio kit
784+
* @returns The preferred generator, or undefined if the kit is not a VS kit or the VS version is not recognized
785+
*/
786+
export async function getVsKitPreferredGenerator(kit: Kit): Promise<CMakeGenerator | undefined> {
787+
if (!kit.visualStudio || !kit.visualStudioArchitecture) {
788+
return undefined;
789+
}
790+
791+
// If the kit already has a preferredGenerator, return it
792+
if (kit.preferredGenerator) {
793+
return kit.preferredGenerator;
794+
}
795+
796+
// Try to derive the preferredGenerator from the VS installation
797+
const vsInstall = await getVSInstallForKit(kit);
798+
if (!vsInstall) {
799+
return undefined;
800+
}
801+
802+
const version = /^(\d+)+./.exec(vsInstall.installationVersion);
803+
if (!version) {
804+
return undefined;
805+
}
806+
807+
const generatorName = VsGenerators[version[1]];
808+
if (!generatorName) {
809+
return undefined;
810+
}
811+
812+
const majorVersion = parseInt(vsInstall.installationVersion);
813+
const hostArch = kit.visualStudioArchitecture;
814+
const host: string = hostArch.toLowerCase().replace(/ /g, "").startsWith("host=") ? hostArch : "host=" + hostArch;
815+
// For VS kits, use the hostArch as the target platform (x64 -> x64)
816+
const targetArch = hostArch;
817+
818+
return {
819+
name: generatorName,
820+
platform: generatorPlatformFromVSArch[targetArch] as string || targetArch,
821+
toolset: majorVersion < 15 ? undefined : host
822+
};
823+
}
824+
770825
/**
771826
* Try to get a VSKit from a VS installation and architecture
772827
* @param inst A VS installation from vswhere

test/unit-tests/kit-scan.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,26 @@ suite('Kits scan test', () => {
234234
]);
235235
}).timeout(10000);
236236
});
237+
238+
suite('VS Generator mapping', () => {
239+
test('returns correct generator for VS 2022', () => {
240+
expect(kit.vsGeneratorForVersion('17')).to.eq('Visual Studio 17 2022');
241+
});
242+
243+
test('returns correct generator for VS 2026', () => {
244+
expect(kit.vsGeneratorForVersion('18')).to.eq('Visual Studio 18 2026');
245+
});
246+
247+
test('returns correct generator for VS 2019', () => {
248+
expect(kit.vsGeneratorForVersion('16')).to.eq('Visual Studio 16 2019');
249+
});
250+
251+
test('returns undefined for unknown version', () => {
252+
expect(kit.vsGeneratorForVersion('99')).to.be.undefined;
253+
});
254+
255+
test('returns correct generator for legacy VS120COMNTOOLS', () => {
256+
expect(kit.vsGeneratorForVersion('VS120COMNTOOLS')).to.eq('Visual Studio 12 2013');
257+
});
258+
});
237259
});

0 commit comments

Comments
 (0)