Skip to content

Commit eb30c49

Browse files
authored
More kits and archs fixes (#1253)
1 parent 425bcf8 commit eb30c49

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/kit.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ export function vsDisplayName(inst: VSInstallation): string {
434434
*
435435
* @param inst The VSInstallation to use
436436
* @param hostArch The architecture of the toolset host (e.g. x86, x64|amd64)
437-
* @param targetArch The architecture of the toolset target (e.g. x86, x64|amd64, arm, arm64)
437+
* @param targetArch The architecture of the toolset target (e.g. win32|x86, x64|amd64, arm, arm64)
438438
*/
439-
function kitName(inst: VSInstallation, hostArch: string, targetArch?: string): string {
439+
function vsKitName(inst: VSInstallation, hostArch: string, targetArch?: string): string {
440440
// We still keep the amd64 alias for x64, only in the name of the detected VS kits,
441441
// for compatibility reasons. Switching to 'x64' means leaving
442442
// orphaned 'amd64' kits around ("Scan for kits" does not delete them yet)
@@ -467,10 +467,20 @@ function kitHostTargetArch(hostArch: string, targetArch?: string, amd64Alias: bo
467467
}
468468
}
469469

470-
if (targetArch) {
471-
return hostArch === targetArch ? hostArch : `${hostArch}_${targetArch}`;
470+
if (!targetArch) {
471+
targetArch = hostArch;
472472
}
473-
return hostArch;
473+
474+
// CMake preferred generator platform requires 'win32', while vcvars are still using 'x86'.
475+
// This function is called only for VS generators, so it is safe to overwrite
476+
// targetArch with the vcvars naming.
477+
// In case of any future new mismatches, use the vsArchFromGeneratorPlatform table
478+
// instead of hard coding for win32 and x86.
479+
// Currently, there is no need of a similar overwrite operation on hostArch,
480+
// because CMake host target does not have the same name mismatch with VS.
481+
targetArch = vsArchFromGeneratorPlatform[targetArch] || targetArch;
482+
483+
return (hostArch === targetArch) ? hostArch : `${hostArch}_${targetArch}`;
474484
}
475485

476486
/**
@@ -626,10 +636,15 @@ export async function getShellScriptEnvironment(kit: Kit): Promise<Map<string, s
626636
* Currently, there is a mismatch only between x86 and win32.
627637
* For example, VS kits x86 and amd64_x86 will generate -A win32
628638
*/
629-
const genPlatformFromVsHostTargetArchs: {[key: string]: string} = {
639+
const generatorPlatformFromVSArch: {[key: string]: string} = {
630640
x86: 'win32'
631641
};
632642

643+
// The reverse of generatorPlatformFromVSArch
644+
const vsArchFromGeneratorPlatform: {[key: string]: string} = {
645+
win32: 'x86'
646+
};
647+
633648
/**
634649
* Preferred CMake VS generators by VS version
635650
*/
@@ -707,10 +722,11 @@ async function varsForVSInstallation(inst: VSInstallation, hostArch: string, tar
707722
/**
708723
* Try to get a VSKit from a VS installation and architecture
709724
* @param inst A VS installation from vswhere
710-
* @param hostTargetArch The host-target architecture combination to try
725+
* @param hostArch The host architecture
726+
* @param targetArch The target architecture
711727
*/
712728
async function tryCreateNewVCEnvironment(inst: VSInstallation, hostArch: string, targetArch: string, pr?: ProgressReporter): Promise<Kit|null> {
713-
const name = kitName(inst, hostArch, targetArch);
729+
const name = vsKitName(inst, hostArch, targetArch);
714730
log.debug(localize('checking.for.kit', 'Checking for kit: {0}', name));
715731
if (pr) {
716732
pr.report({message: localize('checking', 'Checking {0}', name)});
@@ -737,7 +753,7 @@ async function tryCreateNewVCEnvironment(inst: VSInstallation, hostArch: string,
737753
log.debug(` ${localize('generator.present', 'Generator Present: {0}', generatorName)}`);
738754
kit.preferredGenerator = {
739755
name: generatorName,
740-
platform: genPlatformFromVsHostTargetArchs[targetArch] as string || targetArch,
756+
platform: generatorPlatformFromVSArch[targetArch] as string || targetArch,
741757
// CMake generator toolsets support also different versions (via -T version=).
742758
toolset: "host=" + hostArch
743759
};

0 commit comments

Comments
 (0)