blob: 018bdf0e50c034d30c2052fd3fd2621b12165399 [file] [log] [blame]
Tim Golden7d052362013-10-25 08:58:16 +01001Building Python using Microsoft Visual C++
2------------------------------------------
Christian Heimes57dddfb2008-01-02 18:30:52 +00003
Tim Golden7d052362013-10-25 08:58:16 +01004This directory is used to build CPython for Microsoft Windows NT version
55.1 or higher (Windows XP, Windows Server 2003, or later) on 32 and 64
6bit platforms. Using this directory requires an installation of
7Microsoft Visual C++ 2010 (MSVC 10.0) of any edition. The specific
8requirements are as follows:
Zachary Ware5f3e3c32014-03-19 14:46:25 -05009
Tim Golden7d052362013-10-25 08:58:16 +010010Visual C++ 2010 Express Edition
11 Required for building 32-bit Debug and Release configuration builds.
Zachary Wareef035652014-07-07 14:33:24 -050012 The Python build solution pcbuild.sln makes use of Solution Folders,
13 which this edition does not support. Any time pcbuild.sln is opened
14 or reloaded by Visual C++, a warning about Solution Folders will be
15 displayed which can be safely dismissed with no impact on your
16 ability to build Python.
Tim Golden7d052362013-10-25 08:58:16 +010017Visual Studio 2010 Professional Edition
Zachary Ware5f3e3c32014-03-19 14:46:25 -050018 Required for building 64-bit Debug and Release configuration builds
19Visual Studio 2010 Premium Edition
Tim Golden7d052362013-10-25 08:58:16 +010020 Required for building Release configuration builds that make use of
Zachary Ware5f3e3c32014-03-19 14:46:25 -050021 Profile Guided Optimization (PGO), on either platform.
22
Zachary Ware4856a6a2014-06-13 09:38:50 -050023Installing Service Pack 1 for Visual Studio 2010 is highly recommended
24to avoid LNK1123 errors.
25
Tim Golden7d052362013-10-25 08:58:16 +010026All you need to do to build is open the solution "pcbuild.sln" in Visual
27Studio, select the desired combination of configuration and platform,
28then build with "Build Solution" or the F7 keyboard shortcut. You can
29also build from the command line using the "build.bat" script in this
30directory. The solution is configured to build the projects in the
31correct order.
Guido van Rossum15b239f1998-05-26 14:16:23 +000032
Tim Golden7d052362013-10-25 08:58:16 +010033The solution currently supports two platforms. The Win32 platform is
34used to build standard x86-compatible 32-bit binaries, output into this
35directory. The x64 platform is used for building 64-bit AMD64 (aka
36x86_64 or EM64T) binaries, output into the amd64 sub-directory which
37will be created if it doesn't already exist. The Itanium (IA-64)
38platform is no longer supported. See the "Building for AMD64" section
39below for more information about 64-bit builds.
Guido van Rossum15b239f1998-05-26 14:16:23 +000040
Tim Golden7d052362013-10-25 08:58:16 +010041Four configuration options are supported by the solution:
42Debug
43 Used to build Python with extra debugging capabilities, equivalent
44 to using ./configure --with-pydebug on UNIX. All binaries built
45 using this configuration have "_d" added to their name:
46 python34_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
47 build and rt (run test) batch files in this directory accept a -d
48 option for debug builds. If you are building Python to help with
49 development of CPython, you will most likely use this configuration.
50PGInstrument, PGUpdate
51 Used to build Python in Release configuration using PGO, which
Zachary Ware2170b142014-07-07 14:31:34 -050052 requires Premium Edition of Visual Studio. See the "Profile
Tim Golden7d052362013-10-25 08:58:16 +010053 Guided Optimization" section below for more information. Build
54 output from each of these configurations lands in its own
55 sub-directory of this directory. The official Python releases are
56 built using these configurations.
57Release
58 Used to build Python as it is meant to be used in production
59 settings, though without PGO.
Guido van Rossum15b239f1998-05-26 14:16:23 +000060
Christian Heimes5b5e81c2007-12-31 16:14:33 +000061
Christian Heimes57dddfb2008-01-02 18:30:52 +000062Legacy support
63--------------
64
Tim Golden7d052362013-10-25 08:58:16 +010065You can find build directories for older versions of Visual Studio and
66Visual C++ in the PC directory. The legacy build directories are no
67longer actively maintained and may not work out of the box.
Christian Heimes57dddfb2008-01-02 18:30:52 +000068
Tim Golden7d052362013-10-25 08:58:16 +010069Currently, the only legacy build directory is PC\VS9.0, for Visual
70Studio 2008 (9.0).
Christian Heimes57dddfb2008-01-02 18:30:52 +000071
72
Tim Golden7d052362013-10-25 08:58:16 +010073C Runtime
Christian Heimes57dddfb2008-01-02 18:30:52 +000074---------
75
Tim Golden7d052362013-10-25 08:58:16 +010076Visual Studio 2010 uses version 10 of the C runtime (MSVCRT10). The
77executables no longer use the "Side by Side" assemblies used in previous
78versions of the compiler. This simplifies distribution of applications.
Christian Heimes57dddfb2008-01-02 18:30:52 +000079
Tim Golden7d052362013-10-25 08:58:16 +010080The run time libraries are available under the VC/Redist folder of your
81Visual Studio distribution. For more info, see the Readme in the
82VC/Redist folder.
Guido van Rossume79cf321998-07-07 22:35:03 +000083
Tim Golden7d052362013-10-25 08:58:16 +010084
85Sub-Projects
86------------
87
88The CPython project is split up into several smaller sub-projects which
89are managed by the pcbuild.sln solution file. Each sub-project is
90represented by a .vcxproj and a .vcxproj.filters file starting with the
91name of the sub-project. These sub-projects fall into a few general
92categories:
93
94The following sub-projects represent the bare minimum required to build
95a functioning CPython interpreter. If nothing else builds but these,
96you'll have a very limited but usable python.exe:
Tim Peters97c96402001-01-17 23:23:13 +000097pythoncore
Tim Peters4b5fb072000-07-01 00:03:43 +000098 .dll and .lib
99python
100 .exe
Tim Golden7d052362013-10-25 08:58:16 +0100101kill_python
102 kill_python.exe, a small program designed to kill any instances of
103 python(_d).exe that are running and live in the build output
104 directory; this is meant to avoid build issues due to locked files
105make_buildinfo, make_versioninfo
106 helpers to provide necessary information to the build process
107
108These sub-projects provide extra executables that are useful for running
109CPython in different ways:
Tim Peters4b5fb072000-07-01 00:03:43 +0000110pythonw
Tim Golden7d052362013-10-25 08:58:16 +0100111 pythonw.exe, a variant of python.exe that doesn't open a Command
112 Prompt window
113pylauncher
114 py.exe, the Python Launcher for Windows, see
115 http://docs.python.org/3/using/windows.html#launcher
116pywlauncher
117 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
118 window
Zachary Waree0881f42013-11-05 21:55:46 -0600119_testembed
120 _testembed.exe, a small program that embeds Python for testing
121 purposes, used by test_capi.py
Tim Golden7d052362013-10-25 08:58:16 +0100122
123These are miscellaneous sub-projects that don't really fit the other
124categories. By default, these projects do not build in Debug
125configuration:
126_freeze_importlib
127 _freeze_importlib.exe, used to regenerate Python\importlib.h after
128 changes have been made to Lib\importlib\_bootstrap.py
129bdist_wininst
130 ..\Lib\distutils\command\wininst-10.0[-amd64].exe, the base
131 executable used by the distutils bdist_wininst command
132python3dll
133 python3.dll, the PEP 384 Stable ABI dll
134xxlimited
135 builds an example module that makes use of the PEP 384 Stable ABI,
136 see Modules\xxlimited.c
137
138The following sub-projects are for individual modules of the standard
139library which are implemented in C; each one builds a DLL (renamed to
140.pyd) of the same name as the project:
141_ctypes
142_ctypes_test
143_decimal
144_elementtree
145_hashlib
146_msi
147_multiprocessing
148_overlapped
Tim Peters4b5fb072000-07-01 00:03:43 +0000149_socket
Tim Petersd66595f2001-02-04 03:09:53 +0000150_testcapi
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100151_testbuffer
Tim Golden7d052362013-10-25 08:58:16 +0100152_testimportmultiple
Tim Petersb012a152002-02-13 23:56:46 +0000153pyexpat
Tim Peters4b5fb072000-07-01 00:03:43 +0000154select
Tim Peters19f52c22001-01-24 10:07:22 +0000155unicodedata
Tim Peters4b5fb072000-07-01 00:03:43 +0000156winsound
Tim Peters4b5fb072000-07-01 00:03:43 +0000157
Tim Golden7d052362013-10-25 08:58:16 +0100158The following Python-controlled sub-projects wrap external projects.
159Note that these external libraries are not necessary for a working
160interpreter, but they do implement several major features. See the
161"Getting External Sources" section below for additional information
162about getting the source for building these libraries. The sub-projects
163are:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200164_bz2
Tim Golden7d052362013-10-25 08:58:16 +0100165 Python wrapper for version 1.0.6 of the libbzip2 compression library
166 Homepage:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200167 http://www.bzip.org/
Nadeem Vawda3ff069e2011-11-30 00:25:06 +0200168_lzma
Tim Golden7d052362013-10-25 08:58:16 +0100169 Python wrapper for the liblzma compression library, using pre-built
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100170 binaries of XZ Utils version 5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100171 Homepage:
172 http://tukaani.org/xz/
Mark Hammondf229f9f2002-12-03 05:47:26 +0000173_ssl
Zachary Ware16e7f972014-10-25 23:05:06 -0500174 Python wrapper for version 1.0.1j of the OpenSSL secure sockets
Tim Golden7d052362013-10-25 08:58:16 +0100175 library, which is built by ssl.vcxproj
176 Homepage:
177 http://www.openssl.org/
Tim Peters4b5fb072000-07-01 00:03:43 +0000178
Tim Golden7d052362013-10-25 08:58:16 +0100179 Building OpenSSL requires nasm.exe (the Netwide Assembler), version
180 2.10 or newer from
181 http://www.nasm.us/
182 to be somewhere on your PATH. More recent versions of OpenSSL may
183 need a later version of NASM. If OpenSSL's self tests don't pass,
184 you should first try to update NASM and do a full rebuild of
Zachary Wareaa3ea7e2014-11-01 17:11:08 -0500185 OpenSSL. If you use the Tools\buildbot\external(-amd64).bat method
186 for getting sources, it also downloads a version of NASM which the
187 ssl build script will add to PATH.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000188
Tim Golden7d052362013-10-25 08:58:16 +0100189 If you like to use the official sources instead of the files from
190 python.org's subversion repository, Perl is required to build the
191 necessary makefiles and assembly files. ActivePerl is available
192 from
Hirokazu Yamamoto7c3d7092010-10-28 17:57:25 +0000193 http://www.activestate.com/activeperl/
Tim Golden7d052362013-10-25 08:58:16 +0100194 The svn.python.org version contains pre-built makefiles and assembly
195 files.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000196
Tim Golden7d052362013-10-25 08:58:16 +0100197 The build process makes sure that no patented algorithms are
198 included. For now RC5, MDC2 and IDEA are excluded from the build.
199 You may have to manually remove $(OBJ_D)\i_*.obj from ms\nt.mak if
200 using official sources; the svn.python.org-hosted version is already
201 fixed.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000202
Tim Golden7d052362013-10-25 08:58:16 +0100203 The ssl.vcxproj sub-project simply invokes PCbuild/build_ssl.py,
204 which locates and builds OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000205
206 build_ssl.py attempts to catch the most common errors (such as not
207 being able to find OpenSSL sources, or not being able to find a Perl
Tim Golden7d052362013-10-25 08:58:16 +0100208 that works with OpenSSL) and give a reasonable error message. If
209 you have a problem that doesn't seem to be handled correctly (e.g.,
210 you know you have ActivePerl but we can't find it), please take a
211 peek at build_ssl.py and suggest patches. Note that build_ssl.py
Mark Hammondf229f9f2002-12-03 05:47:26 +0000212 should be able to be run directly from the command-line.
213
Tim Golden7d052362013-10-25 08:58:16 +0100214 The ssl sub-project does not have the ability to clean the OpenSSL
215 build; if you need to rebuild, you'll have to clean it by hand.
216_sqlite3
Martin v. Löwisa6630692014-03-02 19:42:50 +0100217 Wraps SQLite 3.8.3.1, which is itself built by sqlite3.vcxproj
Tim Golden7d052362013-10-25 08:58:16 +0100218 Homepage:
219 http://www.sqlite.org/
220_tkinter
Martin v. Löwis8d0d3692013-11-23 23:05:27 +0100221 Wraps version 8.6.1 of the Tk windowing system.
Tim Golden7d052362013-10-25 08:58:16 +0100222 Homepage:
223 http://www.tcl.tk/
Tim Peters4b5fb072000-07-01 00:03:43 +0000224
Tim Golden7d052362013-10-25 08:58:16 +0100225 Unlike the other external libraries listed above, Tk must be built
226 separately before the _tkinter module can be built. This means that
Zachary Ware4b2b1de2014-11-01 22:39:21 -0500227 a pre-built Tcl/Tk installation is expected in ..\externals\tcltk
228 (tcltk64 for 64-bit) relative to this directory. See "Getting
229 External Sources" below for the easiest method to ensure Tcl/Tk is
230 built.
Trent Nelson52037272008-04-02 15:06:49 +0000231
Trent Nelson52037272008-04-02 15:06:49 +0000232
Tim Golden7d052362013-10-25 08:58:16 +0100233Getting External Sources
234------------------------
235
236The last category of sub-projects listed above wrap external projects
237Python doesn't control, and as such a little more work is required in
238order to download the relevant source files for each project before they
239can be built. The buildbots must ensure that all libraries are present
240before building, so the easiest approach is to run either external.bat
241or external-amd64.bat (depending on platform) in the ..\Tools\buildbot
242directory from ..\, i.e.:
243
244 C:\python\cpython\PCbuild>cd ..
245 C:\python\cpython>Tools\buildbot\external.bat
246
247This extracts all the external sub-projects from
248 http://svn.python.org/projects/external
249via Subversion (so you'll need an svn.exe on your PATH) and places them
Zachary Ware4b2b1de2014-11-01 22:39:21 -0500250in ..\externals (relative to this directory).
Tim Golden7d052362013-10-25 08:58:16 +0100251
252It is also possible to download sources from each project's homepage,
253though you may have to change the names of some folders in order to make
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100254things work. For instance, if you were to download a version 5.0.7 of
Zachary Ware4b2b1de2014-11-01 22:39:21 -0500255XZ Utils, you would need to extract the archive into ..\externals\xz-5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100256anyway, since that is where the solution is set to look for xz. The
257same is true for all other external projects.
258
259The external(-amd64).bat scripts will also build a debug build of
260Tcl/Tk, but there aren't any equivalent batch files for building release
261versions of Tcl/Tk currently available. If you need to build a release
262version of Tcl/Tk, just take a look at the relevant external(-amd64).bat
263file and find the two nmake lines, then call each one without the
264'DEBUG=1' parameter, i.e.:
Trent Nelson52037272008-04-02 15:06:49 +0000265
266The external-amd64.bat file contains this for tcl:
Tim Golden7d052362013-10-25 08:58:16 +0100267 nmake -f makefile.vc DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000268
269So for a release build, you'd call it as:
Tim Golden7d052362013-10-25 08:58:16 +0100270 nmake -f makefile.vc MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000271
Zachary Ware4b2b1de2014-11-01 22:39:21 -0500272Note that the above command is called from within ..\externals\tcl-8.6.1.0\win
Tim Golden7d052362013-10-25 08:58:16 +0100273(relative to this directory); don't forget to build Tk as well as Tcl!
Trent Nelson52037272008-04-02 15:06:49 +0000274
Tim Golden7d052362013-10-25 08:58:16 +0100275This will be cleaned up in the future; http://bugs.python.org/issue15968
276tracks adding a new tcltk.vcxproj file that will build Tcl/Tk and Tix
277the same way the other external projects listed above are built.
Trent Nelson52037272008-04-02 15:06:49 +0000278
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000279
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000280Building for AMD64
281------------------
282
Tim Golden7d052362013-10-25 08:58:16 +0100283The build process for AMD64 / x64 is very similar to standard builds,
284you just have to set x64 as platform. In addition, the HOST_PYTHON
285environment variable must point to a Python interpreter (at least 2.4),
286to support cross-compilation from Win32. Note that Visual Studio
Zachary Waree08f3762014-03-28 23:31:04 -0500287requires Professional Edition or better in order to build 64-bit
Tim Golden7d052362013-10-25 08:58:16 +0100288binaries.
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000289
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000290
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000291Profile Guided Optimization
292---------------------------
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000293
Christian Heimes25bb7832008-01-11 16:17:00 +0000294The solution has two configurations for PGO. The PGInstrument
Tim Golden7d052362013-10-25 08:58:16 +0100295configuration must be built first. The PGInstrument binaries are linked
296against a profiling library and contain extra debug information. The
297PGUpdate configuration takes the profiling data and generates optimized
298binaries.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000299
Tim Golden7d052362013-10-25 08:58:16 +0100300The build_pgo.bat script automates the creation of optimized binaries.
301It creates the PGI files, runs the unit test suite or PyBench with the
302PGI python, and finally creates the optimized files.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000303
Tim Golden7d052362013-10-25 08:58:16 +0100304See
305 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.100).aspx
306for more on this topic.
307
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000308
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000309Static library
310--------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000311
Tim Golden7d052362013-10-25 08:58:16 +0100312The solution has no configuration for static libraries. However it is
313easy to build a static library instead of a DLL. You simply have to set
314the "Configuration Type" to "Static Library (.lib)" and alter the
315preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
316also have to change the "Runtime Library" from "Multi-threaded DLL
317(/MD)" to "Multi-threaded (/MT)".
318
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000319
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000320Visual Studio properties
321------------------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000322
Tim Golden7d052362013-10-25 08:58:16 +0100323The PCbuild solution makes heavy use of Visual Studio property files
324(*.props). The properties can be viewed and altered in the Property
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000325Manager (View -> Other Windows -> Property Manager).
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000326
Tim Golden7d052362013-10-25 08:58:16 +0100327The property files used are (+-- = "also imports"):
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000328 * debug (debug macro: _DEBUG)
329 * pginstrument (PGO)
330 * pgupdate (PGO)
331 +-- pginstrument
332 * pyd (python extension, release build)
333 +-- release
334 +-- pyproject
335 * pyd_d (python extension, debug build)
336 +-- debug
337 +-- pyproject
338 * pyproject (base settings for all projects, user macros like PyDllName)
339 * release (release macro: NDEBUG)
Tim Golden7d052362013-10-25 08:58:16 +0100340 * sqlite3 (used only by sqlite3.vcxproj)
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000341 * x64 (AMD64 / x64 platform specific settings)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000342
Tim Golden7d052362013-10-25 08:58:16 +0100343The pyproject property file defines _WIN32 and x64 defines _WIN64 and
344_M_X64 although the macros are set by the compiler, too. The GUI doesn't
345always know about the macros and confuse the user with false
346information.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000347
Tim Golden7d052362013-10-25 08:58:16 +0100348
349Your Own Extension DLLs
Tim Peters4b5fb072000-07-01 00:03:43 +0000350-----------------------
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000351
Tim Golden7d052362013-10-25 08:58:16 +0100352If you want to create your own extension module DLL (.pyd), there's an
353example with easy-to-follow instructions in ..\PC\example\; read the
354file readme.txt there first.