blob: 316475f5a9c4e87ad77f0722284f6ee7f773e3b8 [file] [log] [blame]
Zachary Ware6b6e6872017-06-10 14:58:42 -05001Quick Start Guide
2-----------------
3
41. Install Microsoft Visual Studio 2015, any edition.
Zachary Ware51599e22017-06-15 22:08:51 -050051a. Optionally install Python 3.6 or later. If not installed,
6 get_externals.bat (build.bat -e) will download and use Python via
7 NuGet.
82. Run "build.bat -e" to build Python in 32-bit Release configuration.
93. (Optional, but recommended) Run the test suite with "rt.bat -q".
Zachary Ware6b6e6872017-06-10 14:58:42 -050010
11
12Building Python using Microsoft Visual C++
13------------------------------------------
14
15This directory is used to build CPython for Microsoft Windows NT version
166.0 or higher (Windows Vista, Windows Server 2008, or later) on 32 and 64
17bit platforms. Using this directory requires an installation of
18Microsoft Visual C++ 2015 (MSVC 14.0) of any edition. The specific
19requirements are as follows:
20
21Visual Studio Express 2015 for Desktop
22Visual Studio Professional 2015
23 Either edition is sufficient for building all configurations except
24 for Profile Guided Optimization.
25 The Python build solution pcbuild.sln makes use of Solution Folders,
26 which this edition does not support. Any time pcbuild.sln is opened
27 or reloaded by Visual Studio, a warning about Solution Folders will
28 be displayed, which can be safely dismissed with no impact on your
29 ability to build Python.
30 Required for building 64-bit Debug and Release configuration builds
31Visual Studio Premium 2015
32 Required for building Release configuration builds that make use of
33 Profile Guided Optimization (PGO), on either platform.
34
35All you need to do to build is open the solution "pcbuild.sln" in Visual
36Studio, select the desired combination of configuration and platform,
37then build with "Build Solution". You can also build from the command
38line using the "build.bat" script in this directory; see below for
39details. The solution is configured to build the projects in the correct
40order.
41
42The solution currently supports two platforms. The Win32 platform is
43used to build standard x86-compatible 32-bit binaries, output into the
44win32 sub-directory. The x64 platform is used for building 64-bit AMD64
45(aka x86_64 or EM64T) binaries, output into the amd64 sub-directory.
46The Itanium (IA-64) platform is no longer supported.
47
48Four configuration options are supported by the solution:
49Debug
50 Used to build Python with extra debugging capabilities, equivalent
51 to using ./configure --with-pydebug on UNIX. All binaries built
52 using this configuration have "_d" added to their name:
53 python37_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
54 build and rt (run test) batch files in this directory accept a -d
55 option for debug builds. If you are building Python to help with
56 development of CPython, you will most likely use this configuration.
57PGInstrument, PGUpdate
58 Used to build Python in Release configuration using PGO, which
59 requires Premium Edition of Visual Studio. See the "Profile
60 Guided Optimization" section below for more information. Build
61 output from each of these configurations lands in its own
62 sub-directory of this directory. The official Python releases may
63 be built using these configurations.
64Release
65 Used to build Python as it is meant to be used in production
66 settings, though without PGO.
67
68
69Building Python using the build.bat script
70----------------------------------------------
71
72In this directory you can find build.bat, a script designed to make
73building Python on Windows simpler. This script will use the env.bat
74script to detect one of Visual Studio 2015, 2013, 2012, or 2010, any of
75which may be used to build Python, though only Visual Studio 2015 is
76officially supported.
77
78By default, build.bat will build Python in Release configuration for
79the 32-bit Win32 platform. It accepts several arguments to change
80this behavior, try `build.bat -h` to learn more.
81
82
83C Runtime
84---------
85
86Visual Studio 2015 uses version 14 of the C runtime (MSVCRT14). The
87executables no longer use the "Side by Side" assemblies used in previous
88versions of the compiler. This simplifies distribution of applications.
89
90The run time libraries are available under the VC/Redist folder of your
91Visual Studio distribution. For more info, see the Readme in the
92VC/Redist folder.
93
94
95Sub-Projects
96------------
97
98The CPython project is split up into several smaller sub-projects which
99are managed by the pcbuild.sln solution file. Each sub-project is
100represented by a .vcxproj and a .vcxproj.filters file starting with the
101name of the sub-project. These sub-projects fall into a few general
102categories:
103
104The following sub-projects represent the bare minimum required to build
105a functioning CPython interpreter. If nothing else builds but these,
106you'll have a very limited but usable python.exe:
107pythoncore
108 .dll and .lib
109python
110 .exe
111
112These sub-projects provide extra executables that are useful for running
113CPython in different ways:
114pythonw
115 pythonw.exe, a variant of python.exe that doesn't open a Command
116 Prompt window
117pylauncher
118 py.exe, the Python Launcher for Windows, see
119 http://docs.python.org/3/using/windows.html#launcher
120pywlauncher
121 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
122 window
123_testembed
124 _testembed.exe, a small program that embeds Python for testing
125 purposes, used by test_capi.py
126
127These are miscellaneous sub-projects that don't really fit the other
128categories:
129_freeze_importlib
130 _freeze_importlib.exe, used to regenerate Python\importlib.h after
131 changes have been made to Lib\importlib\_bootstrap.py
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
149_socket
150_testcapi
151_testbuffer
152_testimportmultiple
153pyexpat
154select
155unicodedata
156winsound
157
158The 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:
164_bz2
165 Python wrapper for version 1.0.6 of the libbzip2 compression library
166 Homepage:
167 http://www.bzip.org/
168_lzma
Zachary Ware51599e22017-06-15 22:08:51 -0500169 Python wrapper for version 5.2.2 of the liblzma compression library
Zachary Ware6b6e6872017-06-10 14:58:42 -0500170 Homepage:
171 http://tukaani.org/xz/
172_ssl
173 Python wrapper for version 1.0.2k of the OpenSSL secure sockets
174 library, which is built by ssl.vcxproj
175 Homepage:
176 http://www.openssl.org/
177
178 Building OpenSSL requires nasm.exe (the Netwide Assembler), version
179 2.10 or newer from
180 http://www.nasm.us/
181 to be somewhere on your PATH. More recent versions of OpenSSL may
182 need a later version of NASM. If OpenSSL's self tests don't pass,
183 you should first try to update NASM and do a full rebuild of
184 OpenSSL. If you use the PCbuild\get_externals.bat method
185 for getting sources, it also downloads a version of NASM which the
186 libeay/ssleay sub-projects use.
187
188 The libeay/ssleay sub-projects expect your OpenSSL sources to have
189 already been configured and be ready to build. If you get your sources
190 from svn.python.org as suggested in the "Getting External Sources"
191 section below, the OpenSSL source will already be ready to go. If
192 you want to build a different version, you will need to run
193
194 PCbuild\prepare_ssl.py path\to\openssl-source-dir
195
196 That script will prepare your OpenSSL sources in the same way that
197 those available on svn.python.org have been prepared. Note that
198 Perl must be installed and available on your PATH to configure
199 OpenSSL. ActivePerl is recommended and is available from
200 http://www.activestate.com/activeperl/
201
202 The libeay and ssleay sub-projects will build the modules of OpenSSL
203 required by _ssl and _hashlib and may need to be manually updated when
204 upgrading to a newer version of OpenSSL or when adding new
205 functionality to _ssl or _hashlib. They will not clean up their output
206 with the normal Clean target; CleanAll should be used instead.
207_sqlite3
208 Wraps SQLite 3.14.2.0, which is itself built by sqlite3.vcxproj
209 Homepage:
210 http://www.sqlite.org/
211_tkinter
212 Wraps version 8.6.6 of the Tk windowing system.
213 Homepage:
214 http://www.tcl.tk/
215
216 Tkinter's dependencies are built by the tcl.vcxproj and tk.vcxproj
217 projects. The tix.vcxproj project also builds the Tix extended
218 widget set for use with Tkinter.
219
220 Those three projects install their respective components in a
221 directory alongside the source directories called "tcltk" on
222 Win32 and "tcltk64" on x64. They also copy the Tcl and Tk DLLs
223 into the current output directory, which should ensure that Tkinter
224 is able to load Tcl/Tk without having to change your PATH.
225
226 The tcl, tk, and tix sub-projects do not clean their builds with
227 the normal Clean target; if you need to rebuild, you should use the
228 CleanAll target or manually delete their builds.
229
230
231Getting External Sources
232------------------------
233
234The last category of sub-projects listed above wrap external projects
235Python doesn't control, and as such a little more work is required in
236order to download the relevant source files for each project before they
237can be built. However, a simple script is provided to make this as
238painless as possible, called "get_externals.bat" and located in this
239directory. This script extracts all the external sub-projects from
Zachary Ware51599e22017-06-15 22:08:51 -0500240 https://github.com/python/cpython-source-deps
241and
242 https://github.com/python/cpython-bin-deps
243via a Python script called "get_external.py", located in this directory.
244If Python 3.6 or later is not available via the "py.exe" launcher, the
245path or command to use for Python can be provided in the PYTHON_FOR_BUILD
246environment variable, or get_externals.bat will download the latest
247version of NuGet and use it to download the latest "pythonx86" package
248for use with get_external.py. Everything downloaded by these scripts is
249stored in ..\externals (relative to this directory).
Zachary Ware6b6e6872017-06-10 14:58:42 -0500250
251It is also possible to download sources from each project's homepage,
252though you may have to change folder names or pass the names to MSBuild
253as the values of certain properties in order for the build solution to
254find them. This is an advanced topic and not necessarily fully
255supported.
256
257The get_externals.bat script is called automatically by build.bat when
258you pass the '-e' option to it.
259
260
261Profile Guided Optimization
262---------------------------
263
264The solution has two configurations for PGO. The PGInstrument
265configuration must be built first. The PGInstrument binaries are linked
266against a profiling library and contain extra debug information. The
267PGUpdate configuration takes the profiling data and generates optimized
268binaries.
269
270The build_pgo.bat script automates the creation of optimized binaries.
271It creates the PGI files, runs the unit test suite or PyBench with the
272PGI python, and finally creates the optimized files.
273
274See
275 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.140).aspx
276for more on this topic.
277
278
279Static library
280--------------
281
282The solution has no configuration for static libraries. However it is
283easy to build a static library instead of a DLL. You simply have to set
284the "Configuration Type" to "Static Library (.lib)" and alter the
285preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
286also have to change the "Runtime Library" from "Multi-threaded DLL
287(/MD)" to "Multi-threaded (/MT)".
288
289
290Visual Studio properties
291------------------------
292
293The PCbuild solution makes use of Visual Studio property files (*.props)
294to simplify each project. The properties can be viewed in the Property
295Manager (View -> Other Windows -> Property Manager) but should be
296carefully modified by hand.
297
298The property files used are:
299 * python (versions, directories and build names)
300 * pyproject (base settings for all projects)
301 * openssl (used by libeay and ssleay projects)
302 * tcltk (used by _tkinter, tcl, tk and tix projects)
303
304The pyproject property file defines all of the build settings for each
305project, with some projects overriding certain specific values. The GUI
306doesn't always reflect the correct settings and may confuse the user
307with false information, especially for settings that automatically adapt
308for diffirent configurations.