MSVC environment. #5667
kdschlosser
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
One of the things I noticed for Windows users is the Visual Studio build environment needs to be set up prior to running their build. With posix like OS's this is typically a non issue due to the build environment pretty much always existing once the build tools are installed. This is not the case with Windows and using Visual Studio/C++ Build Tools.
I wrote a helper library that sets up a proper build environment when running on Windows. It detects Visual studio installations from 2008 to current and it detects windows SDK's starting from 6.0a to current. It also properly handles locating Ninja and CMake is it has been installed using the Visual Studio Installer.
The library DOES NOT run a subprocess calling one of the
vcvars*.bat
files. Those files have issues and are not an ideal way to set up a build environment.Starting with Visual Studio 2017 Microsoft added a largely undocumented COM interface to access the Visual Studio installer. The library I wrote accesses that COM interface using ctypes so it is able to collect most of the the information that is needed. The rest is gotten from the registry. There is no guessing that is done and all paths get checked as to not use stale registry data from uninstalled software.
I wanted to let the authors of pybind11 know that this exists and it could be added as a convenience so users of pybind11 would not need to specifically set up a build environment. Pybind11 has a reliance on distutils/setuptools as seen in the setup_helpers.py script. This would be where my library could be used...
There is no patching of setuptools or distutils that is done in a direct manner. There is a way to instruct distutils/setuptools to use what is set into
os.environ
without having to monkey patch at all. This is the mechanism I am using to inject the build environment into distutils/setuptools.The problem with distutils/setuptools is it doesn't detect Visual Studio installations. It will ONLY detect the C++ Build tools installations and how it goes about going that is by using assumed installation paths. My Library makes no assumptions about the locations.
I am sure we can also figure out a way to also get it to work when compiling pybind11 as well. It would reveal the path to cmake/ninja if cmake/ninja was installed using visual studio.
https://github.com/kdschlosser/python_msvc
https://pypi.org/project/pyMSVC
Beta Was this translation helpful? Give feedback.
All reactions