File: install.rst

package info (click to toggle)
llvmlite 0.46.0-0.1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,140 kB
  • sloc: python: 13,605; cpp: 3,192; makefile: 185; sh: 168
file content (338 lines) | stat: -rw-r--r-- 13,974 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
==============
Installation
==============

The Numba/llvmlite stack consists of the following major components:

* *Numba* is the compiler package, this depends on llvmlite.
* *llvmlite* is a lightweight binding package to the LLVM APIs, it depends on LLVM.
* *LLVM*  is the JIT compiler framework for producing executable code from various
  inputs.

All components must be compiled in order to be used. And, since each component
on the stack depends on the previous one, you need to compile LLVM in order to
compile llvmlite in order to compile Numba. The LLVM package is a significant
size and may take significant time (magnitude, roughly an hour) and skill to
compile depending on the platform.

Pre-built binaries
==================

As mentioned above, building LLVM for llvmlite is challenging. Installing a
binary package that has been built and tested is *strongly* recommend.

Official Conda packages are available in the Anaconda_ distribution::

    conda install llvmlite

Development releases are built from the Git main branch and uploaded to
the Numba_ development channel on `Anaconda Cloud <https://anaconda.org/numba>`_::

    conda install -c numba/label/dev llvmlite

Binary wheels are also available for installation from PyPI_::

    pip install llvmlite

Development releases of binary wheels are not made available.

Contrary to what might be expected, the llvmlite packages built by the Numba
maintainers do *not* use any LLVM shared libraries that may be present on the
system, and/or in the Conda environment. The parts of LLVM required by llvmlite
are statically linked at build time.  As a result, installing llvmlite from a
binary package from the Numba channel does not also require the end user to
install LLVM.  (For more
details on the reasoning behind this, see: :ref:`faq_why_static`). Note however
also that llvmlite packages compiled by other parties, e.g. conda-forge may
split this into and ``llvmlite`` and ``llvm`` package and link dynamically.

Conda packages:
---------------

The Numba maintainers ship to the Numba channel:

  * Numba packages
  * llvmlite packages
  * llvmdev packages (this contains a build of LLVM)

The llvmdev packages are not needed at runtime by llvmlite packages as
llvmlite's dynamic libraries are statically linked (see above) at compile time
against LLVM through the dependency on the ``llvmdev`` package.

The Anaconda distribution and conda-forge channels ship:

  * Numba packages
  * llvmlite packages
  * LLVM split into runtime libraries (package called ``llvm``) and compile time
    libraries/headers etc this contains a build of LLVM (package called
    ``llvmdev``)

At compile time the ``llvmdev`` and ``llvm`` packages are used to build llvmlite and
llvmlite's dynamic libraries are dynamically linked against the libraries in the
``llvm`` meta-package. This means at runtime ``llvmlite`` depends on the ``llvm``
package which has the LLVM shared libraries in it (it's actually a package
called ``libllvm`` that contains the DSOs, but the ``llvm`` package is referred to
so as to get the ``run_exports``).

Using ``pip``
-------------

The Numba maintainers ship binary wheels:

  * Numba wheels (``x86*`` architectures)
  * llvmlite wheels (``x86*`` architectures)

Note that the llvmlite wheels are statically linked against LLVM, as per the
conda packages on the Numba channel. This mitigates the need for a LLVM based
binary wheel. Note also that this, as of version 0.36, does not include the
``aarch64`` architectures, for example installation on a Raspberry Pi is not
supported.

The Numba maintainers ship an ``sdist`` for:

  * Numba
  * llvmlite

Note that there is no ``sdist`` provided for LLVM. If you try and build ``llvmlite``
from ``sdist`` you will need to bootstrap the package with your own appropriate
LLVM.

How this ends up being a problem.
.................................

1. If you are on an unsupported architecture (i.e. not ``x86*``) or unsupported
   Python version for binary wheels (e.g. Python alphas) then ``pip`` will try and
   build Numba from ``sdist`` which in turn will try and build ``llvmlite`` from
   ``sdist``. This will inevitably fail as the ``llvmlite`` source distribution
   needs an appropriate LLVM installation to build.
2. If you are using ``pip < 19.0`` then ``manylinux2010`` wheels will not
   install and you end up in the situation in 1. i.e. something unsupported so
   building from ``sdist``.

Historically, this issues has manifested itself as the following error
message, which included here verbatim for future reference::

    FileNotFoundError: [Errno 2] No such file or directory: 'llvm-config'

Things to "fix" it...
.....................

1. If you are using ``pip < 19.0`` and on ``x86*``, then update it if you can, this will
   let you use the ``manylinux2010`` binary wheels.

2. If you are on an unsupported architecture, for example Raspberry Pi, please
   use ``conda`` if you have that available.

3. Otherwise: you will probably need to build from source, this means providing
   an LLVM. If you have conda available you could use this to bootstrap the
   installation with a working ``llvm``/``llvmdev`` package. Learn more about
   compiling from source in the section on `Building manually`_ below.
   and in particular note the use of the ``CMAKE_PREFIX_PATH`` environment
   variable for specifying the location of your LLVM installation.

What to be aware of when using a system provided LLVM package.
..............................................................

When using a system provided LLVM package, there are a number of things that
could go wrong:

1. The LLVM package may not work with Numba/llvmlite at all.
2. If it does work to some degree it is unlikely the carry the correct patches
   for Numba/llvmlite to work entirely correctly.
3. Since the Numba/llvmlite maintainers may not know how the package was
   compiled it may be more difficult to get help when things do go wrong.

Building manually
=================

Building llvmlite requires first building LLVM.  Do not use prebuilt LLVM
binaries from your OS distribution or the LLVM website!  There will likely be
a mismatch in version or build options, and LLVM will be missing certain patches
that are critical for llvmlite operation.

Prerequisites
-------------

Before building, you must have the following:

* On Windows:

  * Visual Studio 2015 (Update 3) or later, to compile LLVM and llvmlite.
    The free Express edition is acceptable.

  * CMake_ installed.

* On Linux:

  * g++ (>= 4.8), CMake_ and ``make``

  * If building LLVM on Ubuntu, the linker may report an error
    if the development version of ``libedit`` is not installed. If
    you run into this problem, install ``libedit-dev``.

* On Mac:

  * Xcode for the compiler tools, and CMake_


Compiling LLVM
--------------

If you can build llvmlite inside a conda environment, you can install a
prebuilt LLVM binary package and skip this step::

    conda install -c numba llvmdev

The LLVM build process is fully scripted by conda-build_, and the `llvmdev recipe <https://github.com/numba/llvmlite/tree/main/conda-recipes/llvmdev>`_ is the canonical reference for building LLVM for llvmlite.  Please use it if at all possible!

The manual instructions below describe the main steps, but refer to the recipe
for details:

#. Download the `LLVM source code <https://github.com/llvm/llvm-project/releases/download/>`_.
   You can download the complete "project" package, or llvm, ldd, and libunwind.

#. Download or git checkout the `llvmlite source code <https://github.com/numba/llvmlite>`_.

#. Decompress the LLVM tar files and apply the appropriate patches from the
   ``llvmlite/conda-recipes/`` directory.  You can apply each patch using the
   Linux ``patch -p1 -i {patch-file}`` command. Patches are prefixed with the
   LLVM version they apply cleanly to.

#. For Linux/macOS:

    #. ``export PREFIX=desired_install_location CPU_COUNT=N``
       ( ``N`` is number of parallel compile tasks)
    #. Run the `build.sh <https://github.com/numba/llvmlite/blob/main/conda-recipes/llvmdev/build.sh>`_
       script in the llvmdev conda recipe from the LLVM source directory.

#. For Windows:

    #. ``set PREFIX=desired_install_location``
    #. Run the `bld.bat <https://github.com/numba/llvmlite/blob/main/conda-recipes/llvmdev/bld.bat>`_
       script in the llvmdev conda recipe from the LLVM source directory.


Compiling llvmlite
------------------

llvmlite uses CMake to build the library through which it interacts with LLVM.
Below are some key points on how to configure and build llvmlite.

.. note::
   Historically llvmlite had two build systems, one based on using
   ``llvm-config`` and ``make``, the other using ``CMake``. If you were
   using the ``llvm-config`` and ``make`` based system you may have been
   setting the environment variable ``LLVM_CONFIG`` to indicate the location
   of the LLVM installation via the ``llvm-config`` binary. The ``CMake`` system
   does not use ``llvm-config`` or ``LLVM_CONFIG``, it uses the ``CMake``
   configuration that is exported by LLVM. To migrate, if the environment
   variable ``LLVM_CONFIG`` was set it should be replaced with an appropriately
   set ``CMAKE_PREFIX_PATH`` environment variable, see below for details.

#. To build the llvmlite C wrapper, which embeds a statically
   linked copy of the required subset of LLVM, run the following from the
   llvmlite source directory::

     python setup.py build

#. If your LLVM is installed in a non-standard location, set the
   ``CMAKE_PREFIX_PATH`` environment variable to the location of the
   ``cmake`` directory corresponding to your LLVM installation. This directory
   is typically called ``cmake`` and contains a directory named ``llvm`` which
   in turn contains the file ``LLVMConfig.cmake``.

   EXAMPLE: If LLVM is installed in ``/opt/llvm/`` with the
   ``LLVMConfig.cmake`` file located at
   ``/opt/llvm/lib/cmake/llvm/LLVMConfig.cmake``, set
   ``CMAKE_PREFIX_PATH=/opt/llvm/lib/cmake``.

   If ``CMake`` cannot find the configuration, it will tell you.

#. By default llvmlite will link statically against LLVM
   (see :ref:`faq_why_static`). To override this and request linkage
   against the LLVM dynamic library (typically named ``libLLVM``) set the
   environment variable ``LLVMLITE_SHARED`` to non-zero.

#. By default llvmlite will use link-time optimisation. It is known that there
   are bugs in some GCC variants on some platforms in relation to this option.
   To prevent the use of link-time optimisation set the environment
   variable ``LLVMLITE_LTO`` to zero.

#. If you wish to build against an unsupported LLVM version, set the environment
   variable ``LLVMLITE_SKIP_LLVM_VERSION_CHECK`` to non-zero. Note that this is
   useful for e.g. testing new versions of llvmlite, but support for llvmlite
   built in this manner is limited/it's entirely possible that llvmlite will not
   work as expected. See also:
   :ref:`why llvmlite doesn’t always support the latest release(s) of LLVM<faq_supported_versions>`.

#. Linux/GNU GCC toolchain only: If you wish to statically link ``libstdc++``
   into your library, then set the environment variable
   ``LLVMLITE_CXX_STATIC_LINK`` to non-zero.

#. Unix only: By default llvmlite will enforce the use of the same RTTI flags as
   the LLVM build against which it is linking. This can be overridden by setting
   the environment variable ``LLVMLITE_USE_RTTI`` to either ``ON`` to use RTTI,
   or ``OFF`` to not use RTTI. This is not a boolean flag as there are 3 states,
   ``ON``, ``OFF`` and not set, which is the default so as to inherit from LLVM.

#. Numba maintainers only: As part of QA for the packages shipped to PyPI and
   on the Anaconda Numba channel, the environment variable
   ``LLVMLITE_PACKAGE_FORMAT`` can be set to one of ``"conda"`` or ``"wheel"``
   as appropriate depending on the output package type. This is baked into the
   binary as a runtime discoverable value such that specific testing of e.g.
   linkage can be performed with the knowledge of the package type. If the
   llvmlite unit tests are failing in your package and you are not a Numba
   maintainer, it might be worth checking that this environment variable hasn't
   been copied in from e.g. llvmlite's public CI scripts by accident.


Installing
----------

#. To validate your build, run the test suite by running::

     python runtests.py

   or::

     python -m llvmlite.tests

#. If the validation is successful, install by running::

     python setup.py install

Installing from sdist
---------------------

If you don't want to do any modifications to llvmlite itself,
it's also possible to use ``pip`` to compile and install llvmlite
from the latest released sdist package.
You'll still need to set the environment variable ``CMAKE_PREFIX_PATH`` to
point to the directory containing your LLVM CMake configuration (see above
notes on the environment variable):

``CMAKE_PREFIX_PATH=/path/to/LLVM/cmake/directory pip3 install llvmlite``

This should work on any platform that runs Python and llvm.
It has been observed to work on ``arm``, ``ppc64le``,
and also ``pypy3`` on ``arm``.

x86 users will need to pass an extra flag (see
`issue \#522 <https://github.com/numba/llvmlite/issues/522>`_):

``CMAKE_PREFIX_PATH=/path/to/LLVM/cmake/directory CXXFLAGS=-fPIC pip3 install llvmlite``

This is known to work with ``pypy3`` on ``Linux x64``.

It's also possible to force ``pip`` to rebuild ``llvmlite`` locally with
a custom version of ``llvm`` :

``CMAKE_PREFIX_PATH=/path/to/LLVM/cmake/directory CXXFLAGS=-fPIC pip3 install --no-binary :all: llvmlite``


.. _CMake: http://www.cmake.org/
.. _Numba: http://numba.pydata.org/
.. _PyPI: https://pypi.org/project/llvmlite/
.. _Conda: https://conda.io/docs/
.. _conda-build: https://conda.io/docs/user-guide/tasks/build-packages/index.html
.. _Anaconda: http://docs.continuum.io/anaconda/index.html