Debian Codegraph @

pypy/doc/windows.rst

raw
1 .. _translating-on-windows:
2
3 Translating on Windows
4 ======================
5
6 RPython is supported on Windows platforms, starting with Windows 2000.
7 The following text gives some hints about how to translate a interpreter
8 written in RPython, using PyPy as an example.
9
10 To build pypy-c you need a working python environment, and a C compiler.
11 It is possible to translate with a CPython 2.6 or 2.7, but this is not
12 the preferred way, because it will take a lot longer to run – depending
13 on your architecture, between two and three times as long. So head to
14 `our downloads`_ and get the latest stable version.
15
16 Microsoft Visual Studio is preferred as a compiler, but there are reports
17 of success with the mingw32 port of gcc.
18
19 .. _our downloads: https://www.pypy.org/download.html
20
21
22 What Compiler to use and How to find it?
23 ----------------------------------------
24 The first stumbling block when building something for Python on windows is
25 how to discover the path to the compiler, headers, and libraries. One can
26 install many versions of the MSVC compiler tools, from stand-alone build
27 tools to full blown Visual Studio IDE installations. Each of these use cases
28 put the compiler at different locations, and the layout changes from time to
29 time.
30
31 The ``distutils`` package, located in the stdlib, is the natural place to put
32 this discovery code, but it is frozen by the python version. The pip-
33 installable ``setuptools`` can move faster to adapt to new tools. So the first
34 thing that will happen after building PyPy is it will install pip and download
35 ``setuptools``, then it will build the cffi modules used in stdlib.
36 PyPy has a chicken and egg problem: in order to compile something we need
37 ``setuptools``, but in order to get ``setuptools`` we need pip which requires
38 ``_ssl``, and ``_ssl`` must be compiled. So PyPy vendors in a copy of
39 ``msvc.py`` in ``rpython/tools/setuptools_msvc.py``.
40
41 PyPy will prefer to compile with the latest MSVC compiler it can find, which is
42 a departure from CPython's desire to compile with the compiler used to compile
43 the exe in use.
44
45 Translating PyPy with Visual Studio
46 -----------------------------------
47
48 We routinely test translation of PyPy using Visual Studio 2019, MSVC160.
49 Other configurations may work as well. You must use at least Visual Studio
50 2012.
51
52 The translation scripts will set up the appropriate environment variables
53 for the compiler, so you do not need to run vcvars before translation.
54 They will pick the most recent Visual Studio
55 compiler they can find. In addition, the target architecture
56 (32 bits, 64 bits) is automatically selected. A 32 bit build can only be built
57 using a 32 bit Python and vice versa. By default the interpreter is built using
58 the Multi-threaded DLL (/MD) runtime environment.
59
60 If you wish to override this detection method to use a different compiler
61 (mingw or a different version of MSVC):
62
63 * set up the PATH and other environment variables as needed
64 * set the `CC` environment variable to compiler exe to be used,
65 for a different version of MSVC `SET CC=cl.exe`.
66
67 **Note:** The RPython translator requires a special 64 bit Python, see below
68
69 Python and a C compiler are all you need to build pypy, but it will miss some
70 modules that relies on third-party libraries. See below how to get
71 and build them.
72
73 Please see the :doc:`non-windows instructions <build>` for more information, especially note
74 that translation is RAM-hungry. A standard translation requires around 4GB, so
75 special preparations are necessary, or you may want to use the following method
76 to reduce memory usage at the price of a slower translation::
77
78 set PYPY_GC_MAX_DELTA=200MB
79 pypy --jit loop_longevity=300 ../../rpython/bin/rpython -Ojit targetpypystandalone
80 set PYPY_GC_MAX_DELTA=
81 # This is done as part of translation
82 PYTHONPATH=../.. ./pypy-c ../../lib_pypy/pypy_tools/build_cffi_imports.py
83
84 Preparing Windows for the large build
85 -------------------------------------
86
87 Normally 32bit programs are limited to 2GB of memory on Windows. It is
88 possible to raise this limit to almost 4GB on Windows 64bit.
89
90 You need to execute::
91
92 <path-to-visual>\vc\vcvars.bat
93 editbin /largeaddressaware translator.exe
94
95 where ``translator.exe`` is the pypy.exe or cpython.exe you will use to
96 translate with. This is done by default during PyPy translation, so it should
97 Just Work.
98
99
100 Installing external packages
101 ----------------------------
102
103 We uses a mercurial repository_ inside pypy to hold binary compiled versions of
104 the build dependencies for windows. As part of the `rpython` setup stage,
105 environment variables will be set to use these dependencies. The repository has a README
106 file on how to replicate, and a branch for each supported platform. You may run
107 the `get_externals.py` utility to checkout the proper branch for your platform
108 and PyPy version. If you miss this step, you will get errors like ``cannot open
109 include file: 'ffi.h'``.
110
111 .. _repository: https://foss.heptapod.net/pypy/externals
112
113 Using the mingw compiler
114 ------------------------
115
116 You can compile an RPython program with the mingw compiler, using the
117 --cc=mingw32 option; gcc.exe must be on the PATH. If the -cc flag does not
118 begin with "ming", it should be the name of a valid gcc-derivative compiler,
119 i.e. x86_64-w64-mingw32-gcc for the 64 bit compiler creating a 64 bit target.
120
121 You probably want to set the CPATH, LIBRARY_PATH, and PATH environment
122 variables to the header files, lib or dlls, and dlls respectively of the
123 locally installed packages if they are not in the mingw directory hierarchy.
124
125
126 libffi for the mingw compiler
127 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128
129 To enable the _rawffi (and ctypes) module, you need to compile a mingw
130 version of libffi. Here is one way to do this, which should allow you to try
131 to build for win64 or win32:
132
133 #. Download and unzip a `mingw32 build`_ or `mingw64 build`_, say into c:\mingw
134 #. If you do not use cygwin, you will need msys to provide make,
135 autoconf tools and other goodies.
136
137 #. Download and unzip a `msys for mingw`_, say into c:\msys
138 #. Edit the c:\msys\etc\fstab file to mount c:\mingw
139
140 #. Download and unzip the `libffi source files`_, and extract
141 them in the base directory.
142 #. Run c:\msys\msys.bat or a cygwin shell which should make you
143 feel better since it is a shell prompt with shell tools.
144 #. From inside the shell, cd to the libffi directory and do::
145
146 sh ./configure
147 make
148 cp .libs/libffi-5.dll <somewhere on the PATH>
149
150 If you can't find the dll, and the libtool issued a warning about
151 "undefined symbols not allowed", you will need to edit the libffi
152 Makefile in the toplevel directory. Add the flag -no-undefined to
153 the definition of libffi_la_LDFLAGS
154
155 If you wish to experiment with win64, you must run configure with flags::
156
157 sh ./configure --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32
158
159 or such, depending on your mingw64 download.
160
161
162 Hacking on PyPy with the mingw compiler
163 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164 Since hacking on PyPy means running tests, you will need a way to specify
165 the mingw compiler when hacking (as opposed to translating). As of
166 March 2012, --cc is not a valid option for pytest.py. However if you set an
167 environment variable CC to the compiler exe, testing will use it.
168
169 .. _mingw32 build: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Automated%20Builds
170 .. _mingw64 build: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds
171 .. _msys for mingw: https://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20(Win64%20hosted)/MSYS%20(32-bit)/
172 .. _libffi source files: https://sourceware.org/libffi/
173
174
175 What is missing for a full 64-bit translation
176 ---------------------------------------------
177
178 This is a placeholder for old links to this topic. We have :ref:`solved the
179 64-bit translation problems <windows64>` and there are nightly builds of 64-bit windows.
180