reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
===============
LLVMBuild Guide
===============

.. contents::
   :local:

Introduction
============

This document describes the ``LLVMBuild`` organization and files which
we use to describe parts of the LLVM ecosystem. For description of
specific LLVMBuild related tools, please see the command guide.

LLVM is designed to be a modular set of libraries which can be flexibly
mixed together in order to build a variety of tools, like compilers,
JITs, custom code generators, optimization passes, interpreters, and so
on. Related projects in the LLVM system like Clang and LLDB also tend to
follow this philosophy.

In order to support this usage style, LLVM has a fairly strict structure
as to how the source code and various components are organized. The
``LLVMBuild.txt`` files are the explicit specification of that
structure, and are used by the build systems and other tools in order to
develop the LLVM project.

Project Organization
====================

The source code for LLVM projects using the LLVMBuild system (LLVM,
Clang, and LLDB) is organized into *components*, which define the
separate pieces of functionality that make up the project. These
projects may consist of many libraries, associated tools, build tools,
or other utility tools (for example, testing tools).

For the most part, the project contents are organized around defining
one main component per each subdirectory. Each such directory contains
an ``LLVMBuild.txt`` which contains the component definitions.

The component descriptions for the project as a whole are automatically
gathered by the LLVMBuild tools. The tools automatically traverse the
source directory structure to find all of the component description
files. NOTE: For performance/sanity reasons, we only traverse into
subdirectories when the parent itself contains an ``LLVMBuild.txt``
description file.

Build Integration
=================

The LLVMBuild files themselves are just a declarative way to describe
the project structure. The actual building of the LLVM project is
handled by another build system (See: :doc:`CMake <CMake>`).

The build system implementation will load the relevant contents of the
LLVMBuild files and use that to drive the actual project build.
Typically, the build system will only need to load this information at
"configure" time, and use it to generate native information. Build
systems will also handle automatically reconfiguring their information
when the contents of the ``LLVMBuild.txt`` files change.

Developers generally are not expected to need to be aware of the details
of how the LLVMBuild system is integrated into their build. Ideally,
LLVM developers who are not working on the build system would only ever
need to modify the contents of the ``LLVMBuild.txt`` description files
(although we have not reached this goal yet).

For more information on the utility tool we provide to help interfacing
with the build system, please see the :doc:`llvm-build
<CommandGuide/llvm-build>` documentation.

Component Overview
==================

As mentioned earlier, LLVM projects are organized into logical
*components*. Every component is typically grouped into its own
subdirectory. Generally, a component is organized around a coherent
group of sources which have some kind of clear API separation from other
parts of the code.

LLVM primarily uses the following types of components:

- *Libraries* - Library components define a distinct API which can be
  independently linked into LLVM client applications. Libraries typically
  have private and public header files, and may specify a link of required
  libraries that they build on top of.
- *Build Tools* - Build tools are applications which are designed to be run
  as part of the build process (typically to generate other source files).
  Currently, LLVM uses one main build tool called :doc:`TableGen/index`
  to generate a variety of source files.
- *Tools* - Command line applications which are built using the LLVM
  component libraries. Most LLVM tools are small and are primarily
  frontends to the library interfaces.

Components are described using ``LLVMBuild.txt`` files in the directories
that define the component. See the `LLVMBuild Format Reference`_ section
for information on the exact format of these files.

LLVMBuild Format Reference
==========================

LLVMBuild files are written in a simple variant of the INI or configuration
file format (`Wikipedia entry`_). The format defines a list of sections
each of which may contain some number of properties. A simple example of
the file format is below:

.. _Wikipedia entry: http://en.wikipedia.org/wiki/INI_file

.. code-block:: ini

   ; Comments start with a semi-colon.

   ; Sections are declared using square brackets.
   [component_0]

   ; Properties are declared using '=' and are contained in the previous section.
   ;
   ; We support simple string and boolean scalar values and list values, where
   ; items are separated by spaces. There is no support for quoting, and so
   ; property values may not contain spaces.
   property_name = property_value
   list_property_name = value_1 value_2 ... value_n
   boolean_property_name = 1 (or 0)

LLVMBuild files are expected to define a strict set of sections and
properties. A typical component description file for a library
component would look like the following example:

.. code-block:: ini

   [component_0]
   type = Library
   name = Linker
   parent = Libraries
   required_libraries = Archive BitReader Core Support TransformUtils

A full description of the exact sections and properties which are
allowed follows.

Each file may define exactly one common component, named ``common``. The
common component may define the following properties:

-  ``subdirectories`` **[optional]**

   If given, a list of the names of the subdirectories from the current
   subpath to search for additional LLVMBuild files.

Each file may define multiple components. Each component is described by a
section who name starts with ``component``. The remainder of the section
name is ignored, but each section name must be unique. Typically components
are just number in order for files with multiple components
(``component_0``, ``component_1``, and so on).

.. warning::

   Section names not matching this format (or the ``common`` section) are
   currently unused and are disallowed.

Every component is defined by the properties in the section. The exact
list of properties that are allowed depends on the component type.
Components **may not** define any properties other than those expected
by the component type.

Every component must define the following properties:

-  ``type`` **[required]**

   The type of the component. Supported component types are detailed
   below. Most components will define additional properties which may be
   required or optional.

-  ``name`` **[required]**

   The name of the component. Names are required to be unique across the
   entire project.

-  ``parent`` **[required]**

   The name of the logical parent of the component. Components are
   organized into a logical tree to make it easier to navigate and
   organize groups of components. The parents have no semantics as far
   as the project build is concerned, however. Typically, the parent
   will be the main component of the parent directory.

   Components may reference the root pseudo component using ``$ROOT`` to
   indicate they should logically be grouped at the top-level.

Components may define the following properties:

-  ``dependencies`` **[optional]**

   If specified, a list of names of components which *must* be built
   prior to this one. This should only be exactly those components which
   produce some tool or source code required for building the component.

   .. note::

      ``Group`` and ``LibraryGroup`` components have no semantics for the
      actual build, and are not allowed to specify dependencies.

The following section lists the available component types, as well as
the properties which are associated with that component.

-  ``type = Group``

   Group components exist purely to allow additional arbitrary structuring
   of the logical components tree. For example, one might define a
   ``Libraries`` group to hold all of the root library components.

   ``Group`` components have no additionally properties.

-  ``type = Library``

   Library components define an individual library which should be built
   from the source code in the component directory.

   Components with this type use the following properties:

   -  ``library_name`` **[optional]**

      If given, the name to use for the actual library file on disk. If
      not given, the name is derived from the component name itself.

   -  ``required_libraries`` **[optional]**

      If given, a list of the names of ``Library`` or ``LibraryGroup``
      components which must also be linked in whenever this library is
      used. That is, the link time dependencies for this component. When
      tools are built, the build system will include the transitive closure
      of all ``required_libraries`` for the components the tool needs.

   -  ``add_to_library_groups`` **[optional]**

      If given, a list of the names of ``LibraryGroup`` components which
      this component is also part of. This allows nesting groups of
      components.  For example, the ``X86`` target might define a library
      group for all of the ``X86`` components. That library group might
      then be included in the ``all-targets`` library group.

   -  ``installed`` **[optional]** **[boolean]**

      Whether this library is installed. Libraries that are not installed
      are only reported by ``llvm-config`` when it is run as part of a
      development directory.

-  ``type = LibraryGroup``

   ``LibraryGroup`` components are a mechanism to allow easy definition of
   useful sets of related components. In particular, we use them to easily
   specify things like "all targets", or "all assembly printers".

   Components with this type use the following properties:

   -  ``required_libraries`` **[optional]**

      See the ``Library`` type for a description of this property.

   -  ``add_to_library_groups`` **[optional]**

      See the ``Library`` type for a description of this property.

-  ``type = TargetGroup``

   ``TargetGroup`` components are an extension of ``LibraryGroup``\s,
   specifically for defining LLVM targets (which are handled specially in a
   few places).

   The name of the component should always be the name of the target.

   Components with this type use the ``LibraryGroup`` properties in
   addition to:

   -  ``has_asmparser`` **[optional]** **[boolean]**

      Whether this target defines an assembly parser.

   -  ``has_asmprinter`` **[optional]** **[boolean]**

      Whether this target defines an assembly printer.

   -  ``has_disassembler`` **[optional]** **[boolean]**

      Whether this target defines a disassembler.

   -  ``has_jit`` **[optional]** **[boolean]**

      Whether this target supports JIT compilation.

-  ``type = Tool``

   ``Tool`` components define standalone command line tools which should be
   built from the source code in the component directory and linked.

   Components with this type use the following properties:

   -  ``required_libraries`` **[optional]**

      If given, a list of the names of ``Library`` or ``LibraryGroup``
      components which this tool is required to be linked with.

      .. note::

         The values should be the component names, which may not always
         match up with the actual library names on disk.

      Build systems are expected to properly include all of the libraries
      required by the linked components (i.e., the transitive closure of
      ``required_libraries``).

      Build systems are also expected to understand that those library
      components must be built prior to linking -- they do not also need
      to be listed under ``dependencies``.

-  ``type = BuildTool``

   ``BuildTool`` components are like ``Tool`` components, except that the
   tool is supposed to be built for the platform where the build is running
   (instead of that platform being targeted). Build systems are expected
   to handle the fact that required libraries may need to be built for
   multiple platforms in order to be able to link this tool.

   ``BuildTool`` components currently use the exact same properties as
   ``Tool`` components, the type distinction is only used to differentiate
   what the tool is built for.