xref: /aosp_15_r20/external/mesa3d/docs/install.rst (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1Compiling and Installing
2========================
3
4.. toctree::
5   :maxdepth: 1
6   :hidden:
7
8   meson
9
101. Prerequisites for building
11-----------------------------
12
131.1 General
14~~~~~~~~~~~
15
16Build system
17^^^^^^^^^^^^
18
19- `Meson <https://mesonbuild.com>`__ is required when building on \*nix
20  platforms and on Windows.
21- Android Build system when building as native Android component. Meson
22  is used when building ARC.
23
24Compiler
25^^^^^^^^
26
27The following compilers are known to work, if you know of others or
28you're willing to maintain support for other compiler get in touch.
29
30- GCC 8.0.0 or later (some parts of Mesa may require later versions)
31- Clang 5.0 or later (some parts of Mesa may require later versions)
32- Microsoft Visual Studio 2019 Version 16.11 or later and
33  Windows SDK of at least 20348 is required, for building on Windows.
34
35Third party/extra tools.
36^^^^^^^^^^^^^^^^^^^^^^^^
37
38- `Python <https://www.python.org/>`__ - Python 3.6 or newer is required.
39- Python package ``packaging`` is required on Python 3.12+:
40  ``pip install packaging``
41- `Python Mako module <https://www.makotemplates.org/>`__ - Python Mako
42  module is required. Version 0.8.0 or later should work.
43- Lex / Yacc - for building the Mesa IR and GLSL compiler.
44
45   On Linux systems, Flex and Bison versions 2.5.35 and 2.4.1,
46   respectively, (or later) should work. On Windows with MinGW, install
47   Flex and Bison with:
48
49   .. code-block:: sh
50
51      mingw-get install msys-flex msys-bison
52
53   For MSVC on Windows, install `Win
54   flex-bison <https://sourceforge.net/projects/winflexbison/>`__.
55
56.. note::
57
58   Some versions can be buggy (e.g. Flex 2.6.2) so do try others
59   if things fail.
60
611.2 Requirements
62~~~~~~~~~~~~~~~~
63
64The requirements depends on the features selected at configure stage.
65Check/install the respective development package as prompted by the
66configure error message.
67
68Here are some common ways to retrieve most/all of the dependencies based
69on the packaging tool used by your distro.
70
71.. code-block:: sh
72
73     zypper source-install --build-deps-only Mesa # openSUSE/SLED/SLES
74     yum-builddep mesa # yum Fedora, OpenSuse(?)
75     dnf builddep mesa # dnf Fedora
76     apt-get build-dep mesa # Debian and derivatives
77     ... # others
78
791. Building with meson
80----------------------
81
82Meson is the latest build system in mesa, it is currently able to build
83for \*nix systems like Linux and BSD, macOS, Haiku, and Windows.
84
85The general approach is:
86
87.. code-block:: sh
88
89     meson setup builddir/
90     meson compile -C builddir/
91     sudo meson install -C builddir/
92
93On Windows you can also use the Visual Studio backend
94
95.. code-block:: sh
96
97     meson setup builddir --backend=vs
98     cd builddir
99     msbuild mesa.sln /m
100
101Please read the :doc:`detailed meson instructions <meson>` for more
102information
103
1041. Running against a local build (easy way)
105-------------------------------------------
106
107It's often necessary or useful when debugging driver issues or testing new
108branches to run against a local build of Mesa without doing a system-wide
109install. Meson has built-in support for this with its ``devenv`` subcommand:
110
111.. code-block:: sh
112
113     meson devenv -C builddir glxinfo
114
115This will run the given command against the build in ``builddir``. Note that meson
116will ``chdir`` into the directory first, so any relative paths in the command line
117will be relative to ``builddir`` which may not be what you expect.
118
1191. Running against a local build (hard way)
120-------------------------------------------
121
122If you prefer you can configure your test environment manually. To do this,
123choose a temporary location for the install.  A directory called ``installdir``
124inside your mesa tree is as good as anything.  All of the commands below will
125assume ``$MESA_INSTALLDIR`` is an absolute path to this location.
126
127First, configure Mesa and install in the temporary location:
128
129.. code-block:: sh
130
131   meson setup builddir/ -Dprefix="$MESA_INSTALLDIR" OTHER_OPTIONS
132   meson install -C builddir/
133
134where ``OTHER_OPTIONS`` is replaced by any meson configuration options you may
135want.  For instance, if you want to build the LLVMpipe drivers, it would look
136like this:
137
138.. code-block:: sh
139
140   meson setup builddir/ -Dprefix="$MESA_INSTALLDIR" \
141      -Dgallium-drivers=swrast -Dvulkan-drivers=swrast
142   meson install -C builddir/
143
144Once Mesa has built and installed to ``$MESA_INSTALLDIR``, you can run any app
145against your temporary install by setting the right environment variables.
146Which variable you have to set depends on the API.
147
148OpenGL
149~~~~~~
150
151.. code-block:: sh
152
153   LD_LIBRARY_PATH="$MESA_INSTALLDIR/lib64" glxinfo
154
155You may need to use ``lib`` instead of ``lib64`` on some systems or a full
156library specifier on Debian.  Look inside ``installdir`` for the directory that
157contains ``libGL.so`` and use that one.
158
159Vulkan
160~~~~~~
161
162.. code-block:: sh
163
164   VK_DRIVER_FILES="$MESA_INSTALLDIR/share/vulkan/icd/my_icd.json" vulkaninfo
165
166where ``my_icd.json`` is replaced with the actual ICD json file name.  This
167will depend on your driver.  For instance, the 64-bit Lavapipe driver ICD file
168is named ``lvp_icd.x86_64.json``.
169
170OpenCL
171~~~~~~
172
173.. code-block:: sh
174
175   OCL_ICD_VENDORS="$MESA_INSTALLDIR/etc/OpenCL/vendors" clinfo
176
177Unlike Vulkan, OpenCL takes a path to the whole ``vendors`` folder and will
178enumerate any drivers found there.
179
180Troubleshooting local builds
181~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182
183If you are trying to run an app against a local build and it's not working,
184here are a few things to check:
185
186 1. Double-check your paths and try with the simplest app you can.  Before
187    banging your head on a Steam game, make sure your path works with
188    ``glxgears`` first.
189
190 2. Watch out for wrapper scripts.  Some more complex apps such as games have
191    big start-up scripts.  Sometimes those scripts scrub the environment or set
192    ``LD_LIBRARY_PATH`` to something in the game's install directory.
193
194 3. Is your Mesa build the same arch as your app?  Lots of games are still
195    32-bit and your Mesa build is probably 64-bit by default.
196
197 4. 32 and 64-bit builds in the same local install directory doesn't typically
198    work.  Distributions go to great lengths to make this work in your system
199    install and it's hard to get it right for a local install.  If you've
200    recently built 64-bit and are now building 32-bit, throw away the install
201    directory first to prevent conflicts.
202
2031. Building with AOSP (Android)
204-------------------------------
205
206<TODO>
207
2081. Library Information
209----------------------
210
211When compilation has finished, look in the top-level ``lib/`` (or
212``lib64/``) directory. You'll see a set of library files similar to
213this:
214
215.. code-block:: text
216
217   lrwxrwxrwx    1 brian    users          10 Mar 26 07:53 libGL.so -> libGL.so.1*
218   lrwxrwxrwx    1 brian    users          19 Mar 26 07:53 libGL.so.1 -> libGL.so.1.5.060100*
219   -rwxr-xr-x    1 brian    users     3375861 Mar 26 07:53 libGL.so.1.5.060100*
220   lrwxrwxrwx    1 brian    users          14 Mar 26 07:53 libOSMesa.so -> libOSMesa.so.6*
221   lrwxrwxrwx    1 brian    users          23 Mar 26 07:53 libOSMesa.so.6 -> libOSMesa.so.6.1.060100*
222   -rwxr-xr-x    1 brian    users       23871 Mar 26 07:53 libOSMesa.so.6.1.060100*
223
224**libGL** is the main OpenGL library (i.e. Mesa), while **libOSMesa** is
225the OSMesa (Off-Screen) interface library.
226
227If you built the DRI hardware drivers, you'll also see the DRI drivers:
228
229.. code-block:: text
230
231   -rwxr-xr-x   1 brian users 16895413 Jul 21 12:11 i915_dri.so
232   -rwxr-xr-x   1 brian users 16895413 Jul 21 12:11 i965_dri.so
233   -rwxr-xr-x   1 brian users 11849858 Jul 21 12:12 r200_dri.so
234   -rwxr-xr-x   1 brian users 11757388 Jul 21 12:12 radeon_dri.so
235
236If you built with Gallium support, look in lib/gallium/ for
237Gallium-based versions of libGL and device drivers.
238
2391. Building OpenGL programs with pkg-config
240-------------------------------------------
241
242Running ``meson install`` will install package configuration files for
243the pkg-config utility.
244
245When compiling your OpenGL application you can use pkg-config to
246determine the proper compiler and linker flags.
247
248For example, compiling and linking a GLUT application can be done with:
249
250.. code-block:: sh
251
252      gcc `pkg-config --cflags --libs glut` mydemo.c -o mydemo
253