Skip to content

Commit a9f2c7f

Browse files
authored
Add visualStudioArguments for MSVC kit and handle it properly (#4619)
* There is no need patch Windows Kit 10.0.14393.0, it's support by MSVC 2015 directly Signed-off-by: Yonggang Luo <[email protected]> * Add visualStudioArguments and handle it properly This is support for specify custom Windows SDK Kit. Signed-off-by: Yonggang Luo <[email protected]> * docs: Add new feature Select SDK under Windows Signed-off-by: Yonggang Luo <[email protected]> --------- Signed-off-by: Yonggang Luo <[email protected]>
1 parent cabbba5 commit a9f2c7f

6 files changed

Lines changed: 43 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Features:
2121
- Relax `intelliSenseMode` validation in CMake Presets. [#4815](https://github.com/microsoft/vscode-cmake-tools/issues/4815) [@halflifefan](https://github.com/halflifefan)
2222
- Support string arrays in kit `cmakeSettings` to pass CMake lists without escaping semicolons (e.g., `"LLVM_ENABLE_PROJECTS": ["clang", "lld"]`). [#4503](https://github.com/microsoft/vscode-cmake-tools/issues/4503)
2323
- Add `cmake.outlineViewType` setting to toggle the Project Outline between a flat list view and the prior hierarchical tree view that shows each CMake project separately. [#3799](https://github.com/microsoft/vscode-cmake-tools/issues/3799) [#4538](https://github.com/microsoft/vscode-cmake-tools/pull/4538) [@ar1m4n](https://github.com/ar1m4n)
24+
- Add `kit.visualStudioArguments` property, this is the extra arguments that would be passed to the `vcvarsall.bat` file when entering the VS dev environment, those arguments are `[platform_type] [winsdk_version] [-vcvars_ver=vc_version] [-vcvars_spectre_libs=spectre_mode]`. [#125](https://github.com/microsoft/vscode-cmake-tools/issues/125) [#4538](https://github.com/microsoft/vscode-cmake-tools/pull/4619) [@lygstate](https://github.com/lygstate)
2425

2526
Improvements:
2627
- Clarify variable substitution scope in docs for `settings.json` vs generic VS Code `tasks.json`/`launch.json`, including when to use `${command:cmake.*}` and why `${buildKit}`, `${generator}`, and `${config:cmake.configureArgs}` may not expand as expected in tasks. [#4010](https://github.com/microsoft/vscode-cmake-tools/issues/4010)

docs/kits.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,16 @@ CMake Tools automatically sets up the environment for working with Visual C++. I
112112
{
113113
"name": "A Visual Studio",
114114
"visualStudio": "Visual Studio Build Tools 2017",
115-
"visualStudioArchitecture": "amd64"
115+
"visualStudioArchitecture": "amd64",
116+
"visualStudioArguments": ["uwp", "10.0.10240.0"]
116117
}
117118
]
118119
```
119120

120121
Keys:
121122
> `visualStudio` : the name of a Visual Studio installation obtained by `VSWhere`.\
122123
> `visualStudioArchitecture`: the Visual Studio target architecture that would be passed to the `vcvarsall.bat` file when entering the VS dev environment.
124+
> `visualStudioArguments`: the extra arguments that would be passed to the `vcvarsall.bat` file when entering the VS dev environment, those arguments are `[platform_type] [winsdk_version] [-vcvars_ver=vc_version] [-vcvars_spectre_libs=spectre_mode]`
123125
124126
> **Note:**
125127
> To use Visual C++, both `visualStudio` and `visualStudioArchitecture` must be specified. Omitting either one won't work.

schemas/kits-schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
"type": "string",
5656
"description": "Architecture to target"
5757
},
58+
"visualStudioArguments": {
59+
"type": "array",
60+
"description": "Arguments to vcvarsall.bat",
61+
"items": {
62+
"type": "string"
63+
}
64+
},
5865
"environmentSetupScript": {
5966
"type": "string",
6067
"description": "The absolute path to a script that modifies the environment for the Kit"

src/drivers/cmakeDriver.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,11 @@ export abstract class CMakeDriver implements vscode.Disposable {
786786
return;
787787
}
788788

789-
log.info(localize('switching.to.kit', 'Switching to kit: {0}', kit.name));
789+
let switch_to_kit_info = localize('switching.to.kit', 'Switching to kit: {0}', kit.name);
790+
if (Array.isArray(kit.visualStudioArguments)) {
791+
switch_to_kit_info += ` visualStudioArguments: ${JSON.stringify(kit.visualStudioArguments)}`;
792+
}
793+
log.info(switch_to_kit_info);
790794

791795
const oldBinaryDir = this.binaryDir;
792796
const needsCleanIfKitChange = kitChangeNeedsClean(kit, this._kit);
@@ -1707,6 +1711,9 @@ export abstract class CMakeDriver implements vscode.Disposable {
17071711
telemetryProperties.VisualStudioArchitecture =
17081712
this._kit?.visualStudioArchitecture;
17091713
}
1714+
if (Array.isArray(this._kit?.visualStudioArguments)) {
1715+
telemetryProperties.VisualStudioArguments = JSON.stringify(this._kit?.visualStudioArguments);
1716+
}
17101717
}
17111718

17121719
const telemetryMeasures: telemetry.Measures = {

src/installs/visualStudio.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ async function collectDevBatVars(hostArch: string, devBat: string, args: string[
410410
} catch (err) {
411411
log.error(`Parse '${WindowsSDKVersion}' failed`);
412412
}
413-
if (majorVersion === 14 && util.compareVersion(WindowsSDKVersionParsed, { major: 10, minor: 0, patch: 14393 }) >= 0) {
413+
if (majorVersion === 14 && util.compareVersion(WindowsSDKVersionParsed, { major: 10, minor: 0, patch: 14393 }) > 0) {
414414
const WindowsSdkDir = vars['WindowsSdkDir'] ?? '';
415415
const existPath = vars['PATH'] ?? '';
416416
const oldWinSdkBinPath = path.join(WindowsSdkDir, 'bin', hostArch);
@@ -465,9 +465,10 @@ export async function getVcVarsBatScript(vsInstall: VSInstallation, hostArch: st
465465
* @param hostArch The toolset host architecture
466466
* @param targetArch The toolset target architecture. If unspecified this defaults to `hostArch`
467467
* @param toolsetVersion The toolset version. If specified `inst` is assumed to have this toolset installed.
468+
* @param extraArguments The extra arguments passed to `vcvarsall.bat`.
468469
*/
469-
export async function varsForVSInstallation(inst: VSInstallation, hostArch: string, targetArch?: string, toolsetVersion?: string): Promise<Environment | null> {
470-
log.trace(`varsForVSInstallation path:'${inst.installationPath}' version:${inst.installationVersion} host arch:${hostArch} - target arch:${targetArch}`);
470+
export async function varsForVSInstallation(inst: VSInstallation, hostArch: string, targetArch?: string, toolsetVersion?: string, extraArguments?: string[]): Promise<Environment | null> {
471+
log.trace(`varsForVSInstallation path:'${inst.installationPath}' version:${inst.installationVersion} host arch:${hostArch} - target arch:${targetArch} extraArguments:${JSON.stringify(extraArguments)}`);
471472
const commonDir = path.join(inst.installationPath, 'Common7', 'Tools');
472473
const majorVersion = parseInt(inst.installationVersion);
473474
const devbat = await getVcVarsBatScript(inst, hostArch, targetArch);
@@ -476,6 +477,9 @@ export async function varsForVSInstallation(inst: VSInstallation, hostArch: stri
476477
}
477478

478479
const devBatArgs = [getHostTargetArchString(hostArch, targetArch, majorVersion < 15, true)];
480+
if (Array.isArray(extraArguments)) {
481+
devBatArgs.push(...extraArguments);
482+
}
479483
if (toolsetVersion && majorVersion >= 15) {
480484
devBatArgs.push(`-vcvars_ver=${toolsetVersion}`);
481485
}

src/kits/kit.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ export interface Kit extends KitDetect {
135135
*/
136136
visualStudioArchitecture?: string;
137137

138+
/**
139+
* Arguments to vcvarsall.bat.
140+
* This is used for:
141+
* [platform_type]: {empty} | store | uwp
142+
* [winsdk_version] : full Windows 10 SDK number (e.g. 10.0.10240.0) or "8.1" to use the Windows 8.1 SDK.
143+
* [vc_version] : {none} for latest installed VC++ compiler toolset |
144+
* "14.0" for VC++ 2015 Compiler Toolset |
145+
* "14.xx" for the latest 14.xx.yyyyy toolset installed (e.g. "14.11") |
146+
* "14.xx.yyyyy" for a specific full version number (e.g. "14.11.25503")
147+
* [spectre_mode] : {none} for libraries without spectre mitigations |
148+
* "spectre" for libraries with spectre mitigations
149+
*
150+
*/
151+
visualStudioArguments?: string[];
152+
138153
/**
139154
* Filename of a shell script which sets environment variables for the kit
140155
*/
@@ -1052,7 +1067,7 @@ export async function getVSKitEnvironment(kit: Kit): Promise<Environment | null>
10521067
return null;
10531068
}
10541069

1055-
return varsForVSInstallation(requested, kit.visualStudioArchitecture!, kit.preferredGenerator?.platform);
1070+
return varsForVSInstallation(requested, kit.visualStudioArchitecture!, kit.preferredGenerator?.platform, undefined, kit.visualStudioArguments);
10561071
}
10571072

10581073
/**
@@ -1529,6 +1544,7 @@ export function kitChangeNeedsClean(newKit: Kit, oldKit: Kit | null): boolean {
15291544
compilers: k.compilers,
15301545
vs: k.visualStudio,
15311546
vsArch: k.visualStudioArchitecture,
1547+
vsArgs: k.visualStudioArguments,
15321548
tc: k.toolchainFile,
15331549
preferredGeneratorName: k.preferredGenerator ? k.preferredGenerator.name : null,
15341550
preferredGeneratorPlatform: k.preferredGenerator && k.preferredGenerator.platform ? k.preferredGenerator.platform : null,

0 commit comments

Comments
 (0)