blob: 26739a3f5f38c9b7543791425b357e2463751927 [file] [log] [blame]
Zachary Ware50ebf032015-04-13 12:30:53 -05001Quick Start Guide
2-----------------
3
41. Install Microsoft Visual Studio 2015, any edition.
52. Install Subversion, and make sure 'svn.exe' is on your PATH.
63. Run "build.bat -e" to build Python in 32-bit Release configuration.
74. (Optional, but recommended) Run the test suite with "rt.bat -q".
8
9
Zachary Ware30cc6fa2015-04-13 12:28:11 -050010Building Python using Microsoft Visual C++
11------------------------------------------
12
13This directory is used to build CPython for Microsoft Windows NT version
Zachary Ware50ebf032015-04-13 12:30:53 -0500146.0 or higher (Windows Vista, Windows Server 2008, or later) on 32 and 64
Zachary Ware30cc6fa2015-04-13 12:28:11 -050015bit platforms. Using this directory requires an installation of
Zachary Ware50ebf032015-04-13 12:30:53 -050016Microsoft Visual C++ 2015 (MSVC 14.0) of any edition. The specific
Zachary Ware30cc6fa2015-04-13 12:28:11 -050017requirements are as follows:
18
Zachary Ware50ebf032015-04-13 12:30:53 -050019Visual Studio Express 2015 for Desktop
20Visual Studio Professional 2015
21 Either edition is sufficient for building all configurations except
22 for Profile Guided Optimization.
Zachary Ware30cc6fa2015-04-13 12:28:11 -050023 The Python build solution pcbuild.sln makes use of Solution Folders,
24 which this edition does not support. Any time pcbuild.sln is opened
Zachary Ware50ebf032015-04-13 12:30:53 -050025 or reloaded by Visual Studio, a warning about Solution Folders will
26 be displayed, which can be safely dismissed with no impact on your
Zachary Ware30cc6fa2015-04-13 12:28:11 -050027 ability to build Python.
Zachary Ware30cc6fa2015-04-13 12:28:11 -050028 Required for building 64-bit Debug and Release configuration builds
Zachary Ware50ebf032015-04-13 12:30:53 -050029Visual Studio Premium 2015
Zachary Ware30cc6fa2015-04-13 12:28:11 -050030 Required for building Release configuration builds that make use of
31 Profile Guided Optimization (PGO), on either platform.
32
Zachary Ware30cc6fa2015-04-13 12:28:11 -050033All you need to do to build is open the solution "pcbuild.sln" in Visual
34Studio, select the desired combination of configuration and platform,
Zachary Ware50ebf032015-04-13 12:30:53 -050035then build with "Build Solution". You can also build from the command
36line using the "build.bat" script in this directory; see below for
37details. The solution is configured to build the projects in the correct
38order.
Zachary Ware30cc6fa2015-04-13 12:28:11 -050039
40The solution currently supports two platforms. The Win32 platform is
Zachary Ware50ebf032015-04-13 12:30:53 -050041used to build standard x86-compatible 32-bit binaries, output into the
42win32 sub-directory. The x64 platform is used for building 64-bit AMD64
43(aka x86_64 or EM64T) binaries, output into the amd64 sub-directory.
44The Itanium (IA-64) platform is no longer supported. See the "Building
45for AMD64" section below for more information about 64-bit builds.
Zachary Ware30cc6fa2015-04-13 12:28:11 -050046
47Four configuration options are supported by the solution:
48Debug
49 Used to build Python with extra debugging capabilities, equivalent
50 to using ./configure --with-pydebug on UNIX. All binaries built
51 using this configuration have "_d" added to their name:
Zachary Ware50ebf032015-04-13 12:30:53 -050052 python35_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
Zachary Ware30cc6fa2015-04-13 12:28:11 -050053 build and rt (run test) batch files in this directory accept a -d
54 option for debug builds. If you are building Python to help with
55 development of CPython, you will most likely use this configuration.
56PGInstrument, PGUpdate
57 Used to build Python in Release configuration using PGO, which
58 requires Premium Edition of Visual Studio. See the "Profile
59 Guided Optimization" section below for more information. Build
60 output from each of these configurations lands in its own
Zachary Ware50ebf032015-04-13 12:30:53 -050061 sub-directory of this directory. The official Python releases may
62 be built using these configurations.
Zachary Ware30cc6fa2015-04-13 12:28:11 -050063Release
64 Used to build Python as it is meant to be used in production
65 settings, though without PGO.
66
67
Zachary Ware50ebf032015-04-13 12:30:53 -050068Building Python using the build.bat script
69----------------------------------------------
Zachary Ware30cc6fa2015-04-13 12:28:11 -050070
Zachary Ware50ebf032015-04-13 12:30:53 -050071In this directory you can find build.bat, a script designed to make
72building Python on Windows simpler. This script will use the env.bat
73script to detect one of Visual Studio 2015, 2013, 2012, or 2010, any of
74which may be used to build Python, though only Visual Studio 2015 is
75officially supported.
Zachary Ware30cc6fa2015-04-13 12:28:11 -050076
Zachary Ware50ebf032015-04-13 12:30:53 -050077By default, build.bat will build Python in Release configuration for
78the 32-bit Win32 platform. It accepts several arguments to change
79this behavior:
80
81 -c <configuration> Set the configuration (see above)
82 -d Shortcut for "-c Debug"
83 -p <platform> Set the platform to build for ("Win32" or "x64")
84 -r Rebuild instead of just building
85 -t <target> Set the target (Build, Rebuild, Clean or CleanAll)
86 -e Use get_externals.bat to fetch external sources
87 -M Don't build in parallel
88 -v Increased output messages
89
90Up to 9 MSBuild switches can also be passed, though they must be passed
91after specifying any of the above switches. For example, use:
92
93 build.bat -e -d /fl
94
95to do a debug build with externals fetched as needed and write detailed
96build logs to a file. If the MSBuild switch requires an equal sign
97("="), the entire switch must be quoted:
98
99 build.bat -e -d "/p:ExternalsDir=P:\cpython-externals"
100
101There may also be other situations where quotes are necessary.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500102
103
104C Runtime
105---------
106
Zachary Ware50ebf032015-04-13 12:30:53 -0500107Visual Studio 2015 uses version 14 of the C runtime (MSVCRT14). The
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500108executables no longer use the "Side by Side" assemblies used in previous
109versions of the compiler. This simplifies distribution of applications.
110
111The run time libraries are available under the VC/Redist folder of your
112Visual Studio distribution. For more info, see the Readme in the
113VC/Redist folder.
114
115
116Sub-Projects
117------------
118
119The CPython project is split up into several smaller sub-projects which
120are managed by the pcbuild.sln solution file. Each sub-project is
121represented by a .vcxproj and a .vcxproj.filters file starting with the
122name of the sub-project. These sub-projects fall into a few general
123categories:
124
125The following sub-projects represent the bare minimum required to build
126a functioning CPython interpreter. If nothing else builds but these,
127you'll have a very limited but usable python.exe:
128pythoncore
129 .dll and .lib
130python
131 .exe
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500132make_buildinfo, make_versioninfo
133 helpers to provide necessary information to the build process
134
135These sub-projects provide extra executables that are useful for running
136CPython in different ways:
137pythonw
138 pythonw.exe, a variant of python.exe that doesn't open a Command
139 Prompt window
140pylauncher
141 py.exe, the Python Launcher for Windows, see
142 http://docs.python.org/3/using/windows.html#launcher
143pywlauncher
144 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
145 window
146_testembed
147 _testembed.exe, a small program that embeds Python for testing
148 purposes, used by test_capi.py
149
150These are miscellaneous sub-projects that don't really fit the other
Zachary Ware50ebf032015-04-13 12:30:53 -0500151categories:
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500152_freeze_importlib
153 _freeze_importlib.exe, used to regenerate Python\importlib.h after
154 changes have been made to Lib\importlib\_bootstrap.py
155bdist_wininst
Zachary Ware50ebf032015-04-13 12:30:53 -0500156 ..\Lib\distutils\command\wininst-14.0[-amd64].exe, the base
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500157 executable used by the distutils bdist_wininst command
158python3dll
159 python3.dll, the PEP 384 Stable ABI dll
160xxlimited
161 builds an example module that makes use of the PEP 384 Stable ABI,
162 see Modules\xxlimited.c
163
164The following sub-projects are for individual modules of the standard
165library which are implemented in C; each one builds a DLL (renamed to
166.pyd) of the same name as the project:
167_ctypes
168_ctypes_test
169_decimal
170_elementtree
171_hashlib
172_msi
173_multiprocessing
174_overlapped
175_socket
176_testcapi
177_testbuffer
178_testimportmultiple
179pyexpat
180select
181unicodedata
182winsound
183
184The following Python-controlled sub-projects wrap external projects.
185Note that these external libraries are not necessary for a working
186interpreter, but they do implement several major features. See the
187"Getting External Sources" section below for additional information
188about getting the source for building these libraries. The sub-projects
189are:
190_bz2
191 Python wrapper for version 1.0.6 of the libbzip2 compression library
192 Homepage:
193 http://www.bzip.org/
194_lzma
195 Python wrapper for the liblzma compression library, using pre-built
196 binaries of XZ Utils version 5.0.5
197 Homepage:
198 http://tukaani.org/xz/
199_ssl
Zachary Ware50ebf032015-04-13 12:30:53 -0500200 Python wrapper for version 1.0.1j of the OpenSSL secure sockets
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500201 library, which is built by ssl.vcxproj
202 Homepage:
203 http://www.openssl.org/
204
205 Building OpenSSL requires nasm.exe (the Netwide Assembler), version
206 2.10 or newer from
207 http://www.nasm.us/
208 to be somewhere on your PATH. More recent versions of OpenSSL may
209 need a later version of NASM. If OpenSSL's self tests don't pass,
210 you should first try to update NASM and do a full rebuild of
Zachary Ware50ebf032015-04-13 12:30:53 -0500211 OpenSSL. get_externals.py also downloads a snapshot of NASM, and the
212 libeay and ssleay sub-projects use that version of nasm.exe.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500213
Zachary Ware50ebf032015-04-13 12:30:53 -0500214 The libeay/ssleay sub-projects expect your OpenSSL sources to have
215 already been configured and be ready to build. If you get your sources
216 from svn.python.org as suggested in the "Getting External Sources"
217 section below, the OpenSSL source will already be ready to go. If
218 you want to build a different version, you will need to run
219
220 PCbuild\prepare_ssl.py path\to\openssl-source-dir
221
222 That script will prepare your OpenSSL sources in the same way that
223 those available on svn.python.org have been prepared. Note that
224 Perl must be installed and available on your PATH to configure
225 OpenSSL. ActivePerl is recommended and is available from
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500226 http://www.activestate.com/activeperl/
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500227
Zachary Ware50ebf032015-04-13 12:30:53 -0500228 The libeay and ssleay sub-projects will build the modules of OpenSSL
229 required by _ssl and _hashlib and may need to be manually updated when
230 upgrading to a newer version of OpenSSL or when adding new
231 functionality to _ssl or _hashlib. They will not clean up their output
232 with the normal Clean target; CleanAll should be used instead.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500233_sqlite3
234 Wraps SQLite 3.8.3.1, which is itself built by sqlite3.vcxproj
235 Homepage:
236 http://www.sqlite.org/
237_tkinter
238 Wraps version 8.6.1 of the Tk windowing system.
239 Homepage:
240 http://www.tcl.tk/
241
Zachary Ware50ebf032015-04-13 12:30:53 -0500242 Tkinter's dependencies are built by the tcl.vcxproj and tk.vcxproj
243 projects. The tix.vcxproj project also builds the Tix extended
244 widget set for use with Tkinter.
245
246 Those three projects install their respective components in a
247 directory alongside the source directories called "tcltk" on
248 Win32 and "tcltk64" on x64. They also copy the Tcl and Tk DLLs
249 into the current output directory, which should ensure that Tkinter
250 is able to load Tcl/Tk without having to change your PATH.
251
252 The tcl, tk, and tix sub-projects do not clean their builds with
253 the normal Clean target; if you need to rebuild, you should use the
254 CleanAll target or manually delete their builds.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500255
256
257Getting External Sources
258------------------------
259
260The last category of sub-projects listed above wrap external projects
261Python doesn't control, and as such a little more work is required in
262order to download the relevant source files for each project before they
Zachary Ware50ebf032015-04-13 12:30:53 -0500263can be built. However, a simple script is provided to make this as
264painless as possible, called "get_externals.bat" and located in this
265directory. This script extracts all the external sub-projects from
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500266 http://svn.python.org/projects/external
Zachary Ware50ebf032015-04-13 12:30:53 -0500267via Subversion (so you'll need svn.exe on your PATH) and places them
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500268in ..\externals (relative to this directory).
269
270It is also possible to download sources from each project's homepage,
Zachary Ware50ebf032015-04-13 12:30:53 -0500271though you may have to change folder names or pass the names to MSBuild
272as the values of certain properties in order for the build solution to
273find them. This is an advanced topic and not necessarily fully
274supported.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500275
276
277Building for AMD64
278------------------
279
280The build process for AMD64 / x64 is very similar to standard builds,
281you just have to set x64 as platform. In addition, the HOST_PYTHON
282environment variable must point to a Python interpreter (at least 2.4),
Zachary Ware50ebf032015-04-13 12:30:53 -0500283to support cross-compilation from Win32.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500284
285
286Profile Guided Optimization
287---------------------------
288
289The solution has two configurations for PGO. The PGInstrument
290configuration must be built first. The PGInstrument binaries are linked
291against a profiling library and contain extra debug information. The
292PGUpdate configuration takes the profiling data and generates optimized
293binaries.
294
295The build_pgo.bat script automates the creation of optimized binaries.
296It creates the PGI files, runs the unit test suite or PyBench with the
297PGI python, and finally creates the optimized files.
298
299See
300 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.100).aspx
301for more on this topic.
302
303
304Static library
305--------------
306
307The solution has no configuration for static libraries. However it is
308easy to build a static library instead of a DLL. You simply have to set
309the "Configuration Type" to "Static Library (.lib)" and alter the
310preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
311also have to change the "Runtime Library" from "Multi-threaded DLL
312(/MD)" to "Multi-threaded (/MT)".
313
314
315Visual Studio properties
316------------------------
317
Zachary Ware50ebf032015-04-13 12:30:53 -0500318The PCbuild solution makes use of Visual Studio property files (*.props)
319to simplify each project. The properties can be viewed in the Property
320Manager (View -> Other Windows -> Property Manager) but should be
321carefully modified by hand.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500322
Zachary Ware50ebf032015-04-13 12:30:53 -0500323The property files used are:
324 * python (versions, directories and build names)
325 * pyproject (base settings for all projects)
326 * openssl (used by libeay and ssleay projects)
327 * tcltk (used by _tkinter, tcl, tk and tix projects)
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500328
Zachary Ware50ebf032015-04-13 12:30:53 -0500329The pyproject property file defines all of the build settings for each
330project, with some projects overriding certain specific values. The GUI
331doesn't always reflect the correct settings and may confuse the user
332with false information, especially for settings that automatically adapt
333for diffirent configurations.
Zachary Ware30cc6fa2015-04-13 12:28:11 -0500334
335
336Your Own Extension DLLs
337-----------------------
338
339If you want to create your own extension module DLL (.pyd), there's an
340example with easy-to-follow instructions in ..\PC\example\; read the
341file readme.txt there first.