gdabah / distorm

Powerful Disassembler Library For x86/AMD64
Other
1.26k stars 238 forks source link

Use any installed VC compiler to build the Python package. #112

Closed kankri closed 7 years ago

kankri commented 7 years ago

Trying to build the Python package of distorm3, I get this:

>python setup.py build
running build
running custom_build
running build_py
running build_clib
running custom_build_clib
building 'distorm3' library
error: Unable to find vcvarsall.bat

However, I do have several Visual Studios available:

>set vs
VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\
VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\

The problem is that setup.py uses distutils to compile the distorm3 DLL. However, distutils is designed for building Python extensions and on Windows they need to be built with the same compiler the Python executable was built with:

>python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Version MSC v.1500 is Visual Studio 2008 a.k.a MSVC++ 9.0.

I don't have that over 9 years old compiler installed any more, so setup.py fails. However, any of my newer compilers is capable of building the distorm3 DLL and there already is make\win32\distorm.sln to do exactly that.

This PR modifies setup.py to automatically pick the latest installed Visual Studio and use msbuild to build distorm.sln. This makes it much easier to build the Python package and removes the duplication of DLL build configuration in setup.py and the solution file.

gdabah commented 7 years ago

It seems to me you did more than just this: https://github.com/gdabah/distorm/wiki/DistutilsBuild