Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/kits.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ CMake Tools automatically sets up the environment for working with Visual C++. I
{
"name": "A Visual Studio",
"visualStudio": "Visual Studio Build Tools 2017",
"visualStudioArchitecture": "amd64"
"visualStudioArchitecture": "amd64",
"visualStudioArguments": ["uwp", "10.0.10240.0"]
}
]
```

Keys:
> `visualStudio` : the name of a Visual Studio installation obtained by `VSWhere`.\
> `visualStudioArchitecture`: the Visual Studio target architecture that would be passed to the `vcvarsall.bat` file when entering the VS dev environment.
> `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]`

> **Note:**
> To use Visual C++, both `visualStudio` and `visualStudioArchitecture` must be specified. Omitting either one won't work.
Expand Down
7 changes: 7 additions & 0 deletions schemas/kits-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
"type": "string",
"description": "Architecture to target"
},
"visualStudioArguments": {
"type": "array",
"description": "Arguments to vcvarsall.bat",
"items": {
"type": "string"
}
},
"environmentSetupScript": {
"type": "string",
"description": "The absolute path to a script that modifies the environment for the Kit"
Expand Down
9 changes: 8 additions & 1 deletion src/drivers/cmakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,11 @@ export abstract class CMakeDriver implements vscode.Disposable {
return;
}

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

const oldBinaryDir = this.binaryDir;
const needsCleanIfKitChange = kitChangeNeedsClean(kit, this._kit);
Expand Down Expand Up @@ -1603,6 +1607,9 @@ export abstract class CMakeDriver implements vscode.Disposable {
telemetryProperties.VisualStudioArchitecture =
this._kit?.visualStudioArchitecture;
}
if (Array.isArray(this._kit?.visualStudioArguments)) {
telemetryProperties.VisualStudioArguments = JSON.stringify(this._kit?.visualStudioArguments);
}
}

const telemetryMeasures: telemetry.Measures = {
Expand Down
10 changes: 7 additions & 3 deletions src/installs/visualStudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ async function collectDevBatVars(hostArch: string, devBat: string, args: string[
} catch (err) {
log.error(`Parse '${WindowsSDKVersion}' failed`);
}
if (majorVersion === 14 && util.compareVersion(WindowsSDKVersionParsed, { major: 10, minor: 0, patch: 14393 }) >= 0) {
if (majorVersion === 14 && util.compareVersion(WindowsSDKVersionParsed, { major: 10, minor: 0, patch: 14393 }) > 0) {
const WindowsSdkDir = vars['WindowsSdkDir'] ?? '';
const existPath = vars['PATH'] ?? '';
const oldWinSdkBinPath = path.join(WindowsSdkDir, 'bin', hostArch);
Expand Down Expand Up @@ -463,9 +463,10 @@ export async function getVcVarsBatScript(vsInstall: VSInstallation, hostArch: st
* @param hostArch The toolset host architecture
* @param targetArch The toolset target architecture. If unspecified this defaults to `hostArch`
* @param toolsetVersion The toolset version. If specified `inst` is assumed to have this toolset installed.
* @param extraArguments The extra arguments passed to `vcvarsall.bat`.
*/
export async function varsForVSInstallation(inst: VSInstallation, hostArch: string, targetArch?: string, toolsetVersion?: string): Promise<Environment | null> {
log.trace(`varsForVSInstallation path:'${inst.installationPath}' version:${inst.installationVersion} host arch:${hostArch} - target arch:${targetArch}`);
export async function varsForVSInstallation(inst: VSInstallation, hostArch: string, targetArch?: string, toolsetVersion?: string, extraArguments?: string[]): Promise<Environment | null> {
log.trace(`varsForVSInstallation path:'${inst.installationPath}' version:${inst.installationVersion} host arch:${hostArch} - target arch:${targetArch} extraArguments:${JSON.stringify(extraArguments)}`);
const commonDir = path.join(inst.installationPath, 'Common7', 'Tools');
const majorVersion = parseInt(inst.installationVersion);
const devbat = await getVcVarsBatScript(inst, hostArch, targetArch);
Expand All @@ -474,6 +475,9 @@ export async function varsForVSInstallation(inst: VSInstallation, hostArch: stri
}

const devBatArgs = [getHostTargetArchString(hostArch, targetArch, majorVersion < 15, true)];
if (Array.isArray(extraArguments)) {
devBatArgs.push(...extraArguments);
}
if (toolsetVersion && majorVersion >= 15) {
devBatArgs.push(`-vcvars_ver=${toolsetVersion}`);
}
Expand Down
18 changes: 17 additions & 1 deletion src/kits/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ export interface Kit extends KitDetect {
*/
visualStudioArchitecture?: string;

/**
* Arguments to vcvarsall.bat.
* This is used for:
* [platform_type]: {empty} | store | uwp
* [winsdk_version] : full Windows 10 SDK number (e.g. 10.0.10240.0) or "8.1" to use the Windows 8.1 SDK.
* [vc_version] : {none} for latest installed VC++ compiler toolset |
* "14.0" for VC++ 2015 Compiler Toolset |
* "14.xx" for the latest 14.xx.yyyyy toolset installed (e.g. "14.11") |
* "14.xx.yyyyy" for a specific full version number (e.g. "14.11.25503")
* [spectre_mode] : {none} for libraries without spectre mitigations |
* "spectre" for libraries with spectre mitigations
*
*/
visualStudioArguments?: string[];

/**
* Filename of a shell script which sets environment variables for the kit
*/
Expand Down Expand Up @@ -981,7 +996,7 @@ export async function getVSKitEnvironment(kit: Kit): Promise<Environment | null>
return null;
}

return varsForVSInstallation(requested, kit.visualStudioArchitecture!, kit.preferredGenerator?.platform);
return varsForVSInstallation(requested, kit.visualStudioArchitecture!, kit.preferredGenerator?.platform, undefined, kit.visualStudioArguments);
}

/**
Expand Down Expand Up @@ -1397,6 +1412,7 @@ export function kitChangeNeedsClean(newKit: Kit, oldKit: Kit | null): boolean {
compilers: k.compilers,
vs: k.visualStudio,
vsArch: k.visualStudioArchitecture,
vsArgs: k.visualStudioArguments,
tc: k.toolchainFile,
preferredGeneratorName: k.preferredGenerator ? k.preferredGenerator.name : null,
preferredGeneratorPlatform: k.preferredGenerator && k.preferredGenerator.platform ? k.preferredGenerator.platform : null,
Expand Down