Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

333 lines
9.0KB

  1. .. highlight:: yaml
  2. Toolchains
  3. ##########
  4. One of the core components of ``dds`` is that of the *toolchain*. A toolchain
  5. encompasses the environment used to build and link source code, including, but
  6. not limited to:
  7. #. The executable binaries that constitute the language implementation:
  8. Compilers, linkers, and archive managers.
  9. #. The configuration of those tools, including most options given to those
  10. tools when they are invoked.
  11. #. The set of preprocessor macros and language features that are active during
  12. compilation.
  13. When a build is run, every file in the entire tree (including dependencies)
  14. will be compiled, archived, and linked using the same toolchain.
  15. This page provides an introduction on how one can make use of toolchains most
  16. effectively in your project.
  17. .. note::
  18. **IMPORTANT**: ``dds`` will *not* automatically load the Visual C++
  19. environment. To use Visual C++, ``dds`` must be executed from the
  20. appropriate environment in order for the Visual C++ toolchain executables
  21. and files to be available.
  22. Passing a Toolchain
  23. *******************
  24. In ``dds``, the default format of a toolchain is that of a single file that
  25. describes the entire toolchain, and uses the extension ``.tc.dds`` by
  26. convention. When running a build for a project, the ``dds`` executable will
  27. look for a file named ``toolchain.tc.dds`` by default, and will error out if
  28. this file does not exist. A different toolchain can be provided by passing the
  29. toolchain file for the ``--toolchain`` (or ``-t``) option on the command line::
  30. $ dds build -t my-toolchain.tc.dds
  31. Alternatively, you can pass the name of a built-in toolchain. See below.
  32. .. _toolchains.builtin:
  33. Built-in Toolchains
  34. *******************
  35. For convenience, ``dds`` includes several built-in toolchains that can be
  36. accessed in the ``--toolchain`` command-line option using a colon ``:``
  37. prefix::
  38. $ dds build -T :gcc
  39. ``dds`` will treat the leading colon (``:``) as a name for a built-in
  40. toolchain (this means that a toolchain's filepath may not begin with a colon).
  41. There are several built-in toolchains that may be specified:
  42. ``:gcc``
  43. Uses the default ``gcc`` and ``g++`` executables, linkers, and options
  44. thereof.
  45. ``:gcc-N`` (for some integer ``N``)
  46. Equivalent to ``:gcc``, but uses the ``gcc-N`` and ``g++-N`` executables.
  47. ``:clang``
  48. Equivalent to ``:gcc``, but uses the ``clang`` and ``clang++`` executables.
  49. ``:clang-N`` (for some integer ``N``)
  50. Equivalent to ``:clang``, but uses the ``clang-N`` and ``clang++-N``
  51. executables.
  52. ``:msvc``
  53. Compiles and links using the Visual C++ toolchain.
  54. The following pseudo-toolchains are also available:
  55. ``:debug:XYZ``
  56. Uses built-in toolchain ``:XYZ``, but generates debugging information.
  57. ``:ccache:XYZ``
  58. Uses built-in toolchain ``:XYZ``, but prefixes all compile commands with
  59. ``ccache``.
  60. ``:c++UV:XYZ`` (for two integers ``UV``)
  61. Sets the C++ version to ``C++UV`` and uses the ``:XYZ`` toolchain.
  62. .. _toolchains.default:
  63. Providing a Default Toolchain File
  64. **********************************
  65. If you do not which to provide a new toolchain for every individual project,
  66. and the built-in toolchains do not suit your needs, you can write a toolchain
  67. file to one of a few predefined paths, and ``dds`` will find and use it for the
  68. build. The following paths are searched, in order:
  69. #. ``$pwd/toolchain.dds`` - If the working directory contains ``toolchain.dds``,
  70. it will be used as the default.
  71. #. ``$dds_config_dir/toolchain.dds`` - Searches for a toolchain file in
  72. ``dds``'s user-local configuration directory (see below).
  73. #. ``$user_home/toolchain.dds`` - Searches for a toolchain file at the root of
  74. the current user's home directory. (``$HOME`` on Unix-like systems, and
  75. ``$PROFILE`` on Windows.)
  76. The ``$dds_user_config`` directory is the ``dds`` subdirectory of the
  77. user-local configuration directory.
  78. The user-local config directory is ``$XDG_CONFIG_DIR`` or ``~/.config`` on
  79. Linux, ``~/Library/Preferences`` on macOS, and ``~/AppData/Roaming`` on
  80. Windows.
  81. Toolchain Definitions
  82. *********************
  83. Besides using the built-in toolchains, it is likely that you'll soon want to
  84. customize a toolchain further. Further customization must be done with a
  85. file that contains the toolchain definition. The most basic toolchain file is
  86. simply one line:
  87. .. code-block::
  88. Compiler-ID: <compiler-id>
  89. where ``<compiler-id>`` is one of the known ``Compiler-ID`` options (See the
  90. toolchain option reference). ``dds`` will infer common suitable defaults for
  91. the remaining options based on the value of ``Compiler-ID``.
  92. For example, if you specify ``GNU``, then ``dds`` will assume ``gcc`` to be the
  93. C compiler, ``g++`` to be the C++ compiler, and ``ar`` to be the library
  94. archiving tool.
  95. If you know that your compiler executable has a different name, you can
  96. specify them with additional options:
  97. .. code-block::
  98. Compiler-ID: GNU
  99. C-Compiler: gcc-9
  100. C++-Compiler: g++-9
  101. ``dds`` will continue to infer other options based on the ``Compiler-ID``, but
  102. will use the provided executable names when compiling files for the respective
  103. languages.
  104. To specify compilation flags, the ``Flags`` option can be used:
  105. .. code-block::
  106. Flags: -fsanitize=address -fno-inline
  107. .. note::
  108. Use ``Warning-Flags`` to specify options regarding compiler warnings.
  109. Flags for linking executables can be specified with ``Link-Flags``:
  110. .. code-block::
  111. Link-Flags: -fsanitize=address -fPIE
  112. .. _toolchains.opt-ref:
  113. Toolchain Option Reference
  114. **************************
  115. The following options are available to be specified within a toolchain file:
  116. ``Compiler-ID``
  117. ---------------
  118. Specify the identity of the compiler. This option is used to infer many other
  119. facts about the toolchain. If specifying the full toolchain with the command
  120. templates, this option is not required.
  121. Valid values are:
  122. ``GNU``
  123. For GCC
  124. ``Clang``
  125. For LLVM/Clang
  126. ``MSVC``
  127. For Microsoft Visual C++
  128. ``C-Compiler`` and ``C++-Compiler``
  129. -----------------------------------
  130. Names/paths of the C and C++ compilers, respectively. Defaults will be inferred
  131. from ``Compiler-ID``.
  132. ``C-Version`` and ``C++-Version``
  133. ---------------------------------
  134. Specify the language versions for C and C++, respectively. By default, ``dds``
  135. will not set any language version. Using this option requires that the
  136. ``Compiler-ID`` be specified
  137. Valid ``C-Version`` values are:
  138. - ``C89``
  139. - ``C99``
  140. - ``C11``
  141. - ``C18``
  142. Valid ``C++-Version`` values are:
  143. - ``C++98``
  144. - ``C++03``
  145. - ``C++11``
  146. - ``C++14``
  147. - ``C++17``
  148. - ``C++20``
  149. .. warning::
  150. ``dds`` will not do any "smarts" to infer the exact option to pass to have
  151. the required effect. If you ask for ``C++20`` from ``gcc 5.3``, ``dds``
  152. will simply pass ``-std=c++20`` with no questions asked. If you need
  153. finer-grained control, use the ``Flags`` option.
  154. ``Warning-Flags``
  155. -----------------
  156. Override the compiler flags that should be used to enable warnings. This option
  157. is stored separately from ``Flags``, as these options may be enabled/disabled
  158. separately depending on how ``dds`` is invoked.
  159. .. note::
  160. If ``Compiler-ID`` is provided, a default value will be used that enables
  161. common warning levels.
  162. If you need to tweak warnings further, use this option.
  163. ``Flags``, ``C-Flags``, and ``C++-Flags``
  164. -----------------------------------------
  165. Specify *additional* compiler options, possibly per-language.
  166. ``Link-Flags``
  167. --------------
  168. Specify *additional* link options to use when linking executables.
  169. ``Optimize``
  170. ------------
  171. Boolean option (``True`` or ``False``) to enable/disable optimizations. Default
  172. is ``False``.
  173. ``Debug``
  174. ---------
  175. Boolean option (``True`` or ``False``) to enable/disable the generation of
  176. debugging information. Default is ``False``.
  177. ``Compiler-Launcher``
  178. ---------------------
  179. Provide a command prefix that should be used on all compiler executions.
  180. e.g. ``ccache``.
  181. Advanced Options Reference
  182. **************************
  183. The options below are probably not good to tweak unless you *really* know what
  184. you are doing. Their values will be inferred from ``Compiler-ID``.
  185. ``Deps-Mode``
  186. -------------
  187. Specify the way in which ``dds`` should track compilation dependencies. One
  188. of ``GNU``, ``MSVC``, or ``None``.
  189. ``C-Compile-File``
  190. ------------------
  191. Override the *command template* that is used to compile C source files.
  192. ``C++-Compile-File``
  193. --------------------
  194. Override the *command template* that is used to compile C++ source files.
  195. ``Create-Archive``
  196. ------------------
  197. Override the *command template* that is used to generate static library archive
  198. files.
  199. ``Link-Executable``
  200. -------------------
  201. Override the *command template* that is used to link executables.
  202. ``Include-Template``
  203. --------------------
  204. Override the *command template* for the flags to specify a header search path.
  205. ``External-Include-Template``
  206. -----------------------------
  207. Override the *command template* for the flags to specify a header search path
  208. of an external library.
  209. ``Define-Template``
  210. -------------------
  211. Override the *command template* for the flags to set a preprocessor definition.