Adds an extra optional argument to vcc: vctoolset Fixes #21335 (#21336)

This commit is contained in:
Juan M Gómez 2023-02-09 21:19:05 +00:00 • committed by GitHub
commit 642136ec4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -41,6 +41,7 @@ const
platformPrefix = "--platform" platformPrefix = "--platform"
sdktypePrefix = "--sdktype" sdktypePrefix = "--sdktype"
sdkversionPrefix = "--sdkversion" sdkversionPrefix = "--sdkversion"
vctoolsetPrefix = "--vctoolset"
verbosePrefix = "--verbose" verbosePrefix = "--verbose"
vccversionSepIdx = vccversionPrefix.len vccversionSepIdx = vccversionPrefix.len
@ -49,6 +50,7 @@ const
platformSepIdx = platformPrefix.len platformSepIdx = platformPrefix.len
sdktypeSepIdx = sdktypePrefix.len sdktypeSepIdx = sdktypePrefix.len
sdkversionSepIdx = sdkversionPrefix.len sdkversionSepIdx = sdkversionPrefix.len
vctoolsetSepIdx = vctoolsetPrefix.len
vcvarsallDefaultPath = "vcvarsall.bat" vcvarsallDefaultPath = "vcvarsall.bat"
@ -97,6 +99,8 @@ Options:
"8.1" to use the windows 8.1 SDK "8.1" to use the windows 8.1 SDK
--verbose Echoes the command line for loading the Developer Command Prompt --verbose Echoes the command line for loading the Developer Command Prompt
and the command line passed on to the secondary command. and the command line passed on to the secondary command.
--vctoolset Optionally specifies the Visual Studio compiler toolset to use.
By default, the environment is set to use the current Visual Studio compiler toolset.
Other command line arguments are passed on to the Other command line arguments are passed on to the
secondary command specified by --command or to the secondary command specified by --command or to the
@ -108,7 +112,7 @@ proc parseVccexeCmdLine(argseq: seq[string],
vccversionArg: var seq[string], printPathArg: var bool, vccversionArg: var seq[string], printPathArg: var bool,
vcvarsallArg: var string, commandArg: var string, noCommandArg: var bool, vcvarsallArg: var string, commandArg: var string, noCommandArg: var bool,
platformArg: var VccArch, sdkTypeArg: var VccPlatformType, platformArg: var VccArch, sdkTypeArg: var VccPlatformType,
sdkVersionArg: var string, verboseArg: var bool, sdkVersionArg: var string, vctoolsetArg: var string, verboseArg: var bool,
clArgs: var seq[string]) = clArgs: var seq[string]) =
## Cannot use usual command-line argument parser here ## Cannot use usual command-line argument parser here
## Since vccexe command-line arguments are intermingled ## Since vccexe command-line arguments are intermingled
@ -125,7 +129,7 @@ proc parseVccexeCmdLine(argseq: seq[string],
responseargs = parseCmdLine(responsecontent) responseargs = parseCmdLine(responsecontent)
parseVccexeCmdLine(responseargs, vccversionArg, printPathArg, parseVccexeCmdLine(responseargs, vccversionArg, printPathArg,
vcvarsallArg, commandArg, noCommandArg, platformArg, sdkTypeArg, vcvarsallArg, commandArg, noCommandArg, platformArg, sdkTypeArg,
sdkVersionArg, verboseArg, clArgs) sdkVersionArg, vctoolsetArg, verboseArg, clArgs)
elif wargv.startsWith(vccversionPrefix): # Check for vccversion elif wargv.startsWith(vccversionPrefix): # Check for vccversion
vccversionArg.add(wargv.substr(vccversionSepIdx + 1)) vccversionArg.add(wargv.substr(vccversionSepIdx + 1))
elif wargv.cmpIgnoreCase(printPathPrefix) == 0: # Check for printPath elif wargv.cmpIgnoreCase(printPathPrefix) == 0: # Check for printPath
@ -142,6 +146,8 @@ proc parseVccexeCmdLine(argseq: seq[string],
sdkTypeArg = parseEnum[VccPlatformType](wargv.substr(sdktypeSepIdx + 1)) sdkTypeArg = parseEnum[VccPlatformType](wargv.substr(sdktypeSepIdx + 1))
elif wargv.startsWith(sdkversionPrefix): # Check for sdkversion elif wargv.startsWith(sdkversionPrefix): # Check for sdkversion
sdkVersionArg = wargv.substr(sdkversionSepIdx + 1) sdkVersionArg = wargv.substr(sdkversionSepIdx + 1)
elif wargv.startsWith(vctoolsetPrefix): # Check for vctoolset
vctoolsetArg = wargv.substr(vctoolsetSepIdx + 1)
elif wargv.startsWith(verbosePrefix): elif wargv.startsWith(verbosePrefix):
verboseArg = true verboseArg = true
else: # Regular cl.exe argument -> store for final cl.exe invocation else: # Regular cl.exe argument -> store for final cl.exe invocation
@ -158,13 +164,14 @@ when isMainModule:
var platformArg: VccArch var platformArg: VccArch
var sdkTypeArg: VccPlatformType var sdkTypeArg: VccPlatformType
var sdkVersionArg: string var sdkVersionArg: string
var vctoolsetArg: string
var verboseArg: bool = false var verboseArg: bool = false
var clArgs: seq[string] = @[] var clArgs: seq[string] = @[]
let wrapperArgs = commandLineParams() let wrapperArgs = commandLineParams()
parseVccexeCmdLine(wrapperArgs, vccversionArg, printPathArg, vcvarsallArg, parseVccexeCmdLine(wrapperArgs, vccversionArg, printPathArg, vcvarsallArg,
commandArg, noCommandArg, platformArg, sdkTypeArg, sdkVersionArg, commandArg, noCommandArg, platformArg, sdkTypeArg, sdkVersionArg, vctoolsetArg,
verboseArg, verboseArg,
clArgs) clArgs)
@ -195,7 +202,7 @@ when isMainModule:
echo "$1: $2" % [head, vcvarsallArg] echo "$1: $2" % [head, vcvarsallArg]
# Call vcvarsall to get the appropriate VCC process environment # Call vcvarsall to get the appropriate VCC process environment
var vcvars = vccVarsAll(vcvarsallArg, platformArg, sdkTypeArg, sdkVersionArg, verboseArg) var vcvars = vccVarsAll(vcvarsallArg, platformArg, sdkTypeArg, sdkVersionArg, vctoolsetArg, verboseArg)
if vcvars != nil: if vcvars != nil:
for vccEnvKey, vccEnvVal in vcvars: for vccEnvKey, vccEnvVal in vcvars:
putEnv(vccEnvKey, vccEnvVal) putEnv(vccEnvKey, vccEnvVal)

View file

@ -33,7 +33,7 @@ type
vccplatUWP = "uwp", ## Universal Windows Platform (UWP) Application vccplatUWP = "uwp", ## Universal Windows Platform (UWP) Application
vccplatOneCore = "onecore" # Undocumented platform type in the Windows SDK, probably XBox One SDK platform type. vccplatOneCore = "onecore" # Undocumented platform type in the Windows SDK, probably XBox One SDK platform type.
proc vccVarsAll*(path: string, arch: VccArch = vccarchUnspecified, platform_type: VccPlatformType = vccplatEmpty, sdk_version: string = "", verbose: bool = false): StringTableRef = proc vccVarsAll*(path: string, arch: VccArch = vccarchUnspecified, platform_type: VccPlatformType = vccplatEmpty, sdk_version, vctoolset: string = "", verbose: bool = false): StringTableRef =
## Returns a string table containing the proper process environment to successfully execute VCC compile commands for the specified SDK version, CPU architecture and platform type. ## Returns a string table containing the proper process environment to successfully execute VCC compile commands for the specified SDK version, CPU architecture and platform type.
## ##
## path ## path
@ -44,6 +44,8 @@ proc vccVarsAll*(path: string, arch: VccArch = vccarchUnspecified, platform_type
## The compile target Platform Type. Defaults to the Windows Desktop platform, i.e. a regular Windows executable binary. ## The compile target Platform Type. Defaults to the Windows Desktop platform, i.e. a regular Windows executable binary.
## sdk_version ## sdk_version
## The Windows SDK version to use. ## The Windows SDK version to use.
## vctoolset
## Visual Studio compiler toolset to use.
## verbose ## verbose
## Echo the command-line passed on to the system to load the VCC environment. Defaults to `false`. ## Echo the command-line passed on to the system to load the VCC environment. Defaults to `false`.
@ -63,6 +65,9 @@ proc vccVarsAll*(path: string, arch: VccArch = vccarchUnspecified, platform_type
if sdk_version.len > 0: if sdk_version.len > 0:
args.add(sdk_version) args.add(sdk_version)
if vctoolset.len > 0:
args.add("-vcvars_ver="&vctoolset)
let argStr = args.join " " let argStr = args.join " "