Added documentation and explanatory comments to vccexe
This commit is contained in:
parent
24f07d9b71
commit
3d21e2ab66
4 changed files with 117 additions and 36 deletions
|
|
@ -1,33 +1,53 @@
|
|||
## VCC Developer Command Prompt Loader
|
||||
##
|
||||
## In order for the VCC compiler backend to work properly, it requires numerous
|
||||
## environment variables to be set properly for the desired architecture and compile target.
|
||||
## For that purpose the VCC compiler ships with the vcvarsall utility which is an executable
|
||||
## batch script that can be used to properly set up an Command Prompt environment.
|
||||
|
||||
import strtabs, strutils, os, osproc
|
||||
|
||||
const
|
||||
comSpecEnvKey = "ComSpec" # Environment Variable that specifies the command-line application path in Windows
|
||||
# Usually set to cmd.exe
|
||||
comSpecEnvKey = "ComSpec" ## Environment Variable that specifies the command-line application path in Windows
|
||||
## Usually set to cmd.exe
|
||||
vcvarsallDefaultPath = "vcvarsall.bat"
|
||||
|
||||
type
|
||||
VccArch* = enum
|
||||
VccArch* = enum ## The VCC compile target architectures
|
||||
vccarchUnspecified = "",
|
||||
vccarchX86 = "x86",
|
||||
vccarchAmd64 = "amd64",
|
||||
vccarchX86Amd64 = "x86_amd64",
|
||||
vccarchX86Arm = "x86_arm",
|
||||
vccarchX86Arm64 = "x86_arm64",
|
||||
vccarchAmd64X86 = "amd64_x86",
|
||||
vccarchAmd64Arm = "amd64_arm",
|
||||
vccarchAmd64Arm64 = "amd64_arm64",
|
||||
vccarchX64 = "x64",
|
||||
vccarchX64X86 = "x64_x86",
|
||||
vccarchX64Arm = "x64_arm",
|
||||
vccarchX64Arm64 = "x64_arm64"
|
||||
vccarchX86 = "x86", ## VCC for compilation against the x86 architecture.
|
||||
vccarchAmd64 = "amd64", ## VCC for compilation against the amd64 architecture.
|
||||
vccarchX86Amd64 = "x86_amd64", ## VCC cross-compilation tools using x86 VCC for compilation against the amd64 architecture.
|
||||
vccarchX86Arm = "x86_arm", ## VCC cross-compilation tools using x86 VCC for compilation against the ARM architecture.
|
||||
vccarchX86Arm64 = "x86_arm64", ## VCC cross-compilation tools using x86 VCC for compilation against the ARM (64-bit) architecture.
|
||||
vccarchAmd64X86 = "amd64_x86", ## VCC cross-compilation tools using amd64 VCC for compilation against the x86 architecture.
|
||||
vccarchAmd64Arm = "amd64_arm", ## VCC cross-compilation tools using amd64 VCC for compilation against the ARM architecture.
|
||||
vccarchAmd64Arm64 = "amd64_arm64", ## VCC cross-compilation tools using amd64 VCC for compilation against the ARM (64-bit) architecture.
|
||||
vccarchX64 = "x64", ## VCC for compilation against the x64 architecture.
|
||||
vccarchX64X86 = "x64_x86", ## VCC cross-compilation tools using x64 VCC for compilation against the x86 architecture.
|
||||
vccarchX64Arm = "x64_arm", ## VCC cross-compilation tools using x64 VCC for compilation against the ARM architecture.
|
||||
vccarchX64Arm64 = "x64_arm64" ## VCC cross-compilation tools using x64 VCC for compilation against the ARM (64-bit) architecture.
|
||||
|
||||
VccPlatformType* = enum
|
||||
vccplatEmpty = "",
|
||||
vccplatStore = "store",
|
||||
vccplatUWP = "uwp",
|
||||
vccplatOneCore = "onecore"
|
||||
VccPlatformType* = enum ## The VCC platform type of the compile target
|
||||
vccplatEmpty = "", ## Default (i.e. Desktop) Platfor Type
|
||||
vccplatStore = "store", ## Windows Store Application
|
||||
vccplatUWP = "uwp", ## Universal Windows Platform (UWP) Application
|
||||
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 = nil, 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.
|
||||
##
|
||||
## path
|
||||
## The path to the vcvarsall utility for VCC compiler backend.
|
||||
## arch
|
||||
## The compile target CPU architecture. Starting with Visual Studio 2017, this value must be specified and must not be set to `vccarchUnspecified`.
|
||||
## platform_type
|
||||
## The compile target Platform Type. Defaults to the Windows Desktop platform, i.e. a regular Windows executable binary.
|
||||
## sdk_version
|
||||
## The Windows SDK version to use.
|
||||
## verbose
|
||||
## Echo the command-line passed on to the system to load the VCC environment. Defaults to `false`.
|
||||
|
||||
var vccvarsallpath = path
|
||||
# Assume that default executable is in current directory or in PATH
|
||||
if path == nil or path.len < 1:
|
||||
|
|
@ -58,12 +78,19 @@ proc vccVarsAll*(path: string, arch: VccArch = vccarchUnspecified, platform_type
|
|||
if comSpecCmd.len < 1:
|
||||
comSpecCmd = "cmd"
|
||||
|
||||
# Run the Windows Command Prompt with the /C argument
|
||||
# Execute vcvarsall with its command-line arguments
|
||||
# and then execute the SET command to list all environment variables
|
||||
let comSpecExec = "\"$1\" /C \"$2 && SET\"" % [comSpecCmd, vcvarsExec]
|
||||
var comSpecOpts = {poEvalCommand, poDemon, poStdErrToStdOut}
|
||||
if verbose:
|
||||
comSpecOpts.incl poEchoCmd
|
||||
let comSpecOut = execProcess(comSpecExec, options = comSpecOpts)
|
||||
|
||||
result = newStringTable(modeCaseInsensitive)
|
||||
|
||||
# Parse the output of the final SET command to construct a String Table
|
||||
# with the appropiate environment variables
|
||||
for line in comSpecOut.splitLines:
|
||||
let idx = line.find('=')
|
||||
if idx > 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue