LLVMBuild.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. ===============
  2. LLVMBuild Guide
  3. ===============
  4. .. contents::
  5. :local:
  6. Introduction
  7. ============
  8. This document describes the ``LLVMBuild`` organization and files which
  9. we use to describe parts of the LLVM ecosystem. For description of
  10. specific LLVMBuild related tools, please see the command guide.
  11. LLVM is designed to be a modular set of libraries which can be flexibly
  12. mixed together in order to build a variety of tools, like compilers,
  13. JITs, custom code generators, optimization passes, interpreters, and so
  14. on. Related projects in the LLVM system like Clang and LLDB also tend to
  15. follow this philosophy.
  16. In order to support this usage style, LLVM has a fairly strict structure
  17. as to how the source code and various components are organized. The
  18. ``LLVMBuild.txt`` files are the explicit specification of that
  19. structure, and are used by the build systems and other tools in order to
  20. develop the LLVM project.
  21. Project Organization
  22. ====================
  23. The source code for LLVM projects using the LLVMBuild system (LLVM,
  24. Clang, and LLDB) is organized into *components*, which define the
  25. separate pieces of functionality that make up the project. These
  26. projects may consist of many libraries, associated tools, build tools,
  27. or other utility tools (for example, testing tools).
  28. For the most part, the project contents are organized around defining
  29. one main component per each subdirectory. Each such directory contains
  30. an ``LLVMBuild.txt`` which contains the component definitions.
  31. The component descriptions for the project as a whole are automatically
  32. gathered by the LLVMBuild tools. The tools automatically traverse the
  33. source directory structure to find all of the component description
  34. files. NOTE: For performance/sanity reasons, we only traverse into
  35. subdirectories when the parent itself contains an ``LLVMBuild.txt``
  36. description file.
  37. Build Integration
  38. =================
  39. The LLVMBuild files themselves are just a declarative way to describe
  40. the project structure. The actual building of the LLVM project is
  41. handled by another build system.
  42. The build system implementation will load the relevant contents of the
  43. LLVMBuild files and use that to drive the actual project build.
  44. Typically, the build system will only need to load this information at
  45. "configure" time, and use it to generative native information. Build
  46. systems will also handle automatically reconfiguring their information
  47. when the contents of the ``LLVMBuild.txt`` files change.
  48. Developers generally are not expected to need to be aware of the details
  49. of how the LLVMBuild system is integrated into their build. Ideally,
  50. LLVM developers who are not working on the build system would only ever
  51. need to modify the contents of the ``LLVMBuild.txt`` description files
  52. (although we have not reached this goal yet).
  53. Component Overview
  54. ==================
  55. As mentioned earlier, LLVM projects are organized into logical
  56. *components*. Every component is typically grouped into its own
  57. subdirectory. Generally, a component is organized around a coherent
  58. group of sources which have some kind of clear API separation from other
  59. parts of the code.
  60. LLVM primarily uses the following types of components:
  61. - *Libraries* - Library components define a distinct API which can be
  62. independently linked into LLVM client applications. Libraries typically
  63. have private and public header files, and may specify a link of required
  64. libraries that they build on top of.
  65. - *Build Tools* - Build tools are applications which are designed to be run
  66. as part of the build process (typically to generate other source files).
  67. Currently, LLVM uses one main build tool called :doc:`TableGen/index`
  68. to generate a variety of source files.
  69. - *Tools* - Command line applications which are built using the LLVM
  70. component libraries. Most LLVM tools are small and are primarily
  71. frontends to the library interfaces.
  72. Components are described using ``LLVMBuild.txt`` files in the directories
  73. that define the component. See the `LLVMBuild Format Reference`_ section
  74. for information on the exact format of these files.
  75. LLVMBuild Format Reference
  76. ==========================
  77. LLVMBuild files are written in a simple variant of the INI or configuration
  78. file format (`Wikipedia entry`_). The format defines a list of sections
  79. each of which may contain some number of properties. A simple example of
  80. the file format is below:
  81. .. _Wikipedia entry: http://en.wikipedia.org/wiki/INI_file
  82. .. code-block:: ini
  83. ; Comments start with a semi-colon.
  84. ; Sections are declared using square brackets.
  85. [component_0]
  86. ; Properties are declared using '=' and are contained in the previous section.
  87. ;
  88. ; We support simple string and boolean scalar values and list values, where
  89. ; items are separated by spaces. There is no support for quoting, and so
  90. ; property values may not contain spaces.
  91. property_name = property_value
  92. list_property_name = value_1 value_2 ... value_n
  93. boolean_property_name = 1 (or 0)
  94. LLVMBuild files are expected to define a strict set of sections and
  95. properties. A typical component description file for a library
  96. component would look like the following example:
  97. .. code-block:: ini
  98. [component_0]
  99. type = Library
  100. name = Linker
  101. parent = Libraries
  102. required_libraries = Archive BitReader Core Support TransformUtils
  103. A full description of the exact sections and properties which are
  104. allowed follows.
  105. Each file may define exactly one common component, named ``common``. The
  106. common component may define the following properties:
  107. - ``subdirectories`` **[optional]**
  108. If given, a list of the names of the subdirectories from the current
  109. subpath to search for additional LLVMBuild files.
  110. Each file may define multiple components. Each component is described by a
  111. section who name starts with ``component``. The remainder of the section
  112. name is ignored, but each section name must be unique. Typically components
  113. are just number in order for files with multiple components
  114. (``component_0``, ``component_1``, and so on).
  115. .. warning::
  116. Section names not matching this format (or the ``common`` section) are
  117. currently unused and are disallowed.
  118. Every component is defined by the properties in the section. The exact
  119. list of properties that are allowed depends on the component type.
  120. Components **may not** define any properties other than those expected
  121. by the component type.
  122. Every component must define the following properties:
  123. - ``type`` **[required]**
  124. The type of the component. Supported component types are detailed
  125. below. Most components will define additional properties which may be
  126. required or optional.
  127. - ``name`` **[required]**
  128. The name of the component. Names are required to be unique across the
  129. entire project.
  130. - ``parent`` **[required]**
  131. The name of the logical parent of the component. Components are
  132. organized into a logical tree to make it easier to navigate and
  133. organize groups of components. The parents have no semantics as far
  134. as the project build is concerned, however. Typically, the parent
  135. will be the main component of the parent directory.
  136. Components may reference the root pseudo component using ``$ROOT`` to
  137. indicate they should logically be grouped at the top-level.
  138. Components may define the following properties:
  139. - ``dependencies`` **[optional]**
  140. If specified, a list of names of components which *must* be built
  141. prior to this one. This should only be exactly those components which
  142. produce some tool or source code required for building the component.
  143. .. note::
  144. ``Group`` and ``LibraryGroup`` components have no semantics for the
  145. actual build, and are not allowed to specify dependencies.
  146. The following section lists the available component types, as well as
  147. the properties which are associated with that component.
  148. - ``type = Group``
  149. Group components exist purely to allow additional arbitrary structuring
  150. of the logical components tree. For example, one might define a
  151. ``Libraries`` group to hold all of the root library components.
  152. ``Group`` components have no additionally properties.
  153. - ``type = Library``
  154. Library components define an individual library which should be built
  155. from the source code in the component directory.
  156. Components with this type use the following properties:
  157. - ``library_name`` **[optional]**
  158. If given, the name to use for the actual library file on disk. If
  159. not given, the name is derived from the component name itself.
  160. - ``required_libraries`` **[optional]**
  161. If given, a list of the names of ``Library`` or ``LibraryGroup``
  162. components which must also be linked in whenever this library is
  163. used. That is, the link time dependencies for this component. When
  164. tools are built, the build system will include the transitive closure
  165. of all ``required_libraries`` for the components the tool needs.
  166. - ``add_to_library_groups`` **[optional]**
  167. If given, a list of the names of ``LibraryGroup`` components which
  168. this component is also part of. This allows nesting groups of
  169. components. For example, the ``X86`` target might define a library
  170. group for all of the ``X86`` components. That library group might
  171. then be included in the ``all-targets`` library group.
  172. - ``installed`` **[optional]** **[boolean]**
  173. Whether this library is installed. Libraries that are not installed
  174. are only reported by ``llvm-config`` when it is run as part of a
  175. development directory.
  176. - ``type = LibraryGroup``
  177. ``LibraryGroup`` components are a mechanism to allow easy definition of
  178. useful sets of related components. In particular, we use them to easily
  179. specify things like "all targets", or "all assembly printers".
  180. Components with this type use the following properties:
  181. - ``required_libraries`` **[optional]**
  182. See the ``Library`` type for a description of this property.
  183. - ``add_to_library_groups`` **[optional]**
  184. See the ``Library`` type for a description of this property.
  185. - ``type = TargetGroup``
  186. ``TargetGroup`` components are an extension of ``LibraryGroup``\s,
  187. specifically for defining LLVM targets (which are handled specially in a
  188. few places).
  189. The name of the component should always be the name of the target.
  190. Components with this type use the ``LibraryGroup`` properties in
  191. addition to:
  192. - ``has_asmparser`` **[optional]** **[boolean]**
  193. Whether this target defines an assembly parser.
  194. - ``has_asmprinter`` **[optional]** **[boolean]**
  195. Whether this target defines an assembly printer.
  196. - ``has_disassembler`` **[optional]** **[boolean]**
  197. Whether this target defines a disassembler.
  198. - ``has_jit`` **[optional]** **[boolean]**
  199. Whether this target supports JIT compilation.
  200. - ``type = Tool``
  201. ``Tool`` components define standalone command line tools which should be
  202. built from the source code in the component directory and linked.
  203. Components with this type use the following properties:
  204. - ``required_libraries`` **[optional]**
  205. If given, a list of the names of ``Library`` or ``LibraryGroup``
  206. components which this tool is required to be linked with.
  207. .. note::
  208. The values should be the component names, which may not always
  209. match up with the actual library names on disk.
  210. Build systems are expected to properly include all of the libraries
  211. required by the linked components (i.e., the transitive closure of
  212. ``required_libraries``).
  213. Build systems are also expected to understand that those library
  214. components must be built prior to linking -- they do not also need
  215. to be listed under ``dependencies``.
  216. - ``type = BuildTool``
  217. ``BuildTool`` components are like ``Tool`` components, except that the
  218. tool is supposed to be built for the platform where the build is running
  219. (instead of that platform being targeted). Build systems are expected
  220. to handle the fact that required libraries may need to be built for
  221. multiple platforms in order to be able to link this tool.
  222. ``BuildTool`` components currently use the exact same properties as
  223. ``Tool`` components, the type distinction is only used to differentiate
  224. what the tool is built for.