Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC build environment. #2085

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9567b29
Fixes MSVC build environment
kdschlosser Jan 17, 2022
d4041c3
Adds additional bash.exe source.
kdschlosser Jan 17, 2022
16d65de
Adds dependency link for comtypes.
kdschlosser Jan 18, 2022
fb47e01
Fixes issue with BSTR not being the proper size on x86
kdschlosser Jan 18, 2022
6151ae0
moves comtypes install to devel.txt
kdschlosser Jan 18, 2022
72bd325
Trying to solve issue with BSTR
kdschlosser Jan 18, 2022
1933e23
fixes exception catching for GetDisplayName
kdschlosser Jan 18, 2022
4fa55bb
fixes GetDescription and GetDisplayName
kdschlosser Jan 18, 2022
087c2d4
Removes dependence on comtypes
kdschlosser Jan 25, 2022
cb7eb70
Fixes some environment settings
kdschlosser Jan 25, 2022
8c637d8
adds debugging output for msvc environment
kdschlosser Jan 26, 2022
938cc84
fixes path in msvc environment
kdschlosser Jan 26, 2022
868f158
Speeds up Windows build
kdschlosser Jan 26, 2022
dc6edc1
fixes msvc environment path so the already stet path is added to the …
kdschlosser Jan 26, 2022
e88f175
See if this fixes the missing include folder.
kdschlosser Jan 26, 2022
c4c805b
sets the msvc environment into a global so it doesn't get run more th…
kdschlosser Jan 26, 2022
519196e
Hopefully I have it fixed now!!
kdschlosser Jan 26, 2022
ad4aa60
Fixes formatting error
kdschlosser Jan 26, 2022
a61ef61
Fixes Windows ninja compilation
kdschlosser Jan 29, 2022
0be5301
Fixes issue with WSL and removes use of CMAKE and Ninja
kdschlosser Aug 1, 2022
af5ecbe
adds doing a complete build in setup.py
kdschlosser Aug 1, 2022
a5e4390
adds pyproject.toml
kdschlosser Aug 1, 2022
cfe21f9
removes msvc from buildtools and grabs pyMSVC from pypi
kdschlosser Aug 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
wingdbstub.py*
mydbstub.py*

# temporary storage location for modules
# that are needed when setting up a build
# environment in Windows
.eggs

.idea
.cache
.vagrant
Expand Down
95 changes: 65 additions & 30 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,37 +785,47 @@ def uploadTree(srcPath, destPath, options, days=30):

def checkCompiler(quiet=False):
if isWindows:
# Make sure that the compiler that Python wants to use can be found.
# It will terminate if the compiler is not found or other exceptions
# are raised.
cmd = "import setuptools, distutils.msvc9compiler as msvc; " \
"mc = msvc.MSVCCompiler(); " \
"mc.initialize(); " \
"print(mc.cc)"
CC = runcmd('"%s" -c "%s"' % (PYTHON, cmd), getOutput=True, echoCmd=False)
from buildtools import msvc

# setup the build environment making the minimum conpiler version 14.2
# A user does not need to have a full blown Visual Studio installation
# in order to build wxPython. They can use Visual Studio Build Tools
# as well. Build Tools doe not include any of the GUI replated
# components of Visual Studio.
# If the msvc script isunable to locate an MSVC compiler that is of
# version >= 14.2 the msvc script will raise RuntimeError.

# the msvc script works in a manner where no part of either setuptools
# or distutils is overriden. It uses mechanics that can alter what
# setuptools and distutils sees and uses for the build environment
# without tampering with any of the original code in those libraries.

# the msvc script does not use the problematic vcvars*.bat files that
# come with an MSVC compiler. It builds the environment from the ground
# up by reading the registry and using the COM interfaces. The
# subprocess module is only used for Visual Studio installatons that
# are older then 2017 which wouldn't be an issue because the wxPython
# build system needs the MSVC compiler to be at least 14.2 (VS 2019)

# If the environment variable "DISTUTILS_DEBUG=1" is set There is
# going to be a HUGE dump of information from the msvc module to
# stdout by way of distutils.log.debug(). If the logging level is set
# to DEBUG by using distutils.log.set_threshold(distutils.log.DEBUG)
# or any other mechanics to set the logging level to DEBUG here will
# be a heap of information dumped to stdout by the msvc module.

# Just so this is on record and can be used at a later date if needs
# be the MSVC compiler defaults to c++11. If you need to change this
# extra compiler arguments will have to be added, "/std:cpp_version"
# where cpp_version is the version of cpp to be used ie: "c++20".
# The __cplusplus macro does not change when using the /std compiler
# switch. You have to specifically tell the compuler to update the
# value for the __cplusplus macro using "/Zc:__cplusplus"
environment = msvc.setup_environment(minimum_c_version=14.2)

if not quiet:
msg("MSVC: %s" % CC)

# Now get the environment variables which that compiler needs from
# its vcvarsall.bat command and load them into this process's
# environment.
cmd = "import setuptools, distutils.msvc9compiler as msvc; " \
"arch = msvc.PLAT_TO_VCVARS[msvc.get_platform()]; " \
"env = msvc.query_vcvarsall(msvc.VERSION, arch); " \
"print(env)"
env = eval(runcmd('"%s" -c "%s"' % (PYTHON, cmd), getOutput=True, echoCmd=False))

def _b(v):
return str(v)
#if PY2:
# return bytes(v)
#else:
# return bytes(v, 'utf8')

os.environ['PATH'] = _b(env['path'])
os.environ['INCLUDE'] = _b(env['include'])
os.environ['LIB'] = _b(env['lib'])
os.environ['LIBPATH'] = _b(env['libpath'])
# this gives a simple output of the build environment.
print(environment)

# NOTE: SIP is now generating code with scoped-enums. Older linux
# platforms like what we're using for builds, and also TravisCI for
Expand Down Expand Up @@ -849,6 +859,31 @@ def getWafBuildBase():
def getBashPath():
"""Check if there is a bash.exe on the PATH"""
bash = which('bash.exe')

if not bash and isWindows:
import winreg

try:
handle = winreg.OpenKeyEx(
winreg.HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1'
)
except winreg.error:
pass
else:
try:
path = winreg.QueryValueEx(handle, "InstallLocation")[0]
winreg.CloseKey(handle)
path = os.path.join(path, 'bin', 'bash.exe')

if os.path.exists(path):
bash = path

except winreg.error:
pass

winreg.CloseKey(handle)

return bash


Expand Down
28 changes: 24 additions & 4 deletions buildtools/build_wxwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,24 @@ def main(wxDir, args):
"CPPFLAGS=/I%s" %
os.path.join(os.environ.get("CAIRO_ROOT", ""), 'include\\cairo'))

if options.jom:
nmakeCommand = 'jom.exe'

if options.no_dpi_aware:
args.append("USE_DPI_AWARE_MANIFEST=0")

if options.jom:
nmakeCommand = 'jom.exe'
else:
from . import msvc
environment = msvc.setup_environment(minimum_c_version=14.2)

if (
environment.visual_c.has_cmake and
environment.visual_c.has_ninja
):
args.pop(0)
for i, arg in enumerate(args[:]):
args[i] = '-D' + arg
buildDir = wxRootDir
nmakeCommand = 'cmake.exe'

wxBuilder = builder.MSVCBuilder(commandName=nmakeCommand)

Expand Down Expand Up @@ -511,10 +523,18 @@ def main(wxDir, args):
if options.extra_make:
args.append(options.extra_make)

if not sys.platform.startswith("win"):
if sys.platform.startswith("win"):
if nmakeCommand.startswith('cmake'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do:

if sys.platform.startswith("win") and nmakeCommand.startswith('cmake'):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I cannot.

    if sys.platform.startswith("win"):
        if nmakeCommand.startswith('cmake'):
            args.insert(0, '-GNinja')
    else:
        args.append("--jobs=" + options.jobs)

because if cmake or ninja is not available then cmake.exe doesn't get set to the nmake command so if the platform is windows we do not want to ad a --jobs to the nmake.exe command bcause it doesn't support this switch.

args.insert(0, '-GNinja')
else:
args.append("--jobs=" + options.jobs)

exitIfError(wxBuilder.build(dir=buildDir, options=args), "Error building")

if sys.platform.startswith("win") and nmakeCommand.startswith('cmake'):
wxBuilder = builder.MSVCBuilder(commandName='ninja.exe')
exitIfError(wxBuilder.build(dir=buildDir, options=['-j ' + options.jobs]), "Error building")

if options.install:
extra=None
if installDir:
Expand Down
Loading