FWIW, Python has logic in distutils
to extract envvars from VS build prompt scripts that it uses to build extensions in Windows. So you can set the envvars necessary for building (namely, INCLUDE
, LIB
, LIBPATH
and PATH
) with the following code:
eval "$(python2 -c '
import sys, os, subprocess
import distutils.msvc9compiler as msvc
msvc.find_vcvarsall=lambda _: sys.argv[1]
envs=msvc.query_vcvarsall(sys.argv[2])
for k,v in envs.items():
k = k.upper()
v = ":".join(subprocess.check_output(["cygpath","-u",p]).rstrip() for p in v.split(";"))
v = v.replace("'\''",r"'\'\\\'\''")
print "export %(k)s='\''%(v)s'\''" % locals()
' 'c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat' '-arch=amd64'
)"