You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 line
9.6KB

  1. .. highlight:: js
  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 JSON5 file
  25. that describes the entire toolchain. When running a build for a project, the
  26. ``dds`` executable will look in a few locations for a default toolchain, and
  27. generate an error if no default toolchain file is found (Refer to
  28. :ref:`toolchains.default`). A different toolchain can be provided by passing
  29. the toolchain file for the ``--toolchain`` (or ``-t``) option on the command
  30. line::
  31. $ dds build -t my-toolchain.json5
  32. Alternatively, you can pass the name of a built-in toolchain. See below.
  33. .. _toolchains.builtin:
  34. Built-in Toolchains
  35. *******************
  36. For convenience, ``dds`` includes several built-in toolchains that can be
  37. accessed in the ``--toolchain`` command-line option using a colon ``:``
  38. prefix::
  39. $ dds build -T :gcc
  40. ``dds`` will treat the leading colon (``:``) as a name for a built-in
  41. toolchain (this means that a toolchain's filepath may not begin with a colon).
  42. There are several built-in toolchains that may be specified:
  43. ``:gcc``
  44. Uses the default ``gcc`` and ``g++`` executables, linkers, and options
  45. thereof.
  46. ``:gcc-N`` (for some integer ``N``)
  47. Equivalent to ``:gcc``, but uses the ``gcc-N`` and ``g++-N`` executables.
  48. ``:clang``
  49. Equivalent to ``:gcc``, but uses the ``clang`` and ``clang++`` executables.
  50. ``:clang-N`` (for some integer ``N``)
  51. Equivalent to ``:clang``, but uses the ``clang-N`` and ``clang++-N``
  52. executables.
  53. ``:msvc``
  54. Compiles and links using the Visual C++ toolchain.
  55. The following pseudo-toolchains are also available:
  56. ``:debug:XYZ``
  57. Uses built-in toolchain ``:XYZ``, but generates debugging information.
  58. ``:ccache:XYZ``
  59. Uses built-in toolchain ``:XYZ``, but prefixes all compile commands with
  60. ``ccache``.
  61. ``:c++UV:XYZ`` (for two integers ``UV``)
  62. Sets the C++ version to ``C++UV`` and uses the ``:XYZ`` toolchain.
  63. .. _toolchains.default:
  64. Providing a Default Toolchain File
  65. **********************************
  66. If you do not which to provide a new toolchain for every individual project,
  67. and the built-in toolchains do not suit your needs, you can write a toolchain
  68. file to one of a few predefined paths, and ``dds`` will find and use it for the
  69. build. The following directories are searched, in order:
  70. #. ``$pwd/`` - If the working directory contains a toolchain file, it will be
  71. used as the default.
  72. #. ``$dds_config_dir/`` - Searches for a toolchain file in ``dds``'s user-local
  73. configuration directory (see below).
  74. #. ``$user_home/`` - Searches for a toolchain file at the root of the current
  75. user's home directory. (``$HOME`` on Unix-like systems, and ``$PROFILE`` on
  76. Windows.)
  77. In each directory, it will search for ``toolchain.json5``, ``toolchain.jsonc``,
  78. or ``toolchain.json``.
  79. The ``$dds_user_config`` directory is the ``dds`` subdirectory of the
  80. user-local configuration directory.
  81. The user-local config directory is ``$XDG_CONFIG_DIR`` or ``~/.config`` on
  82. Linux, ``~/Library/Preferences`` on macOS, and ``~/AppData/Roaming`` on
  83. Windows.
  84. Toolchain Definitions
  85. *********************
  86. Besides using the built-in toolchains, it is likely that you'll soon want to
  87. customize a toolchain further. Further customization must be done with a
  88. file that contains the toolchain definition. The most basic toolchain file is
  89. simply one line:
  90. .. code-block::
  91. {
  92. compiler_id: "<compiler-id>"
  93. }
  94. where ``<compiler-id>`` is one of the known ``compiler_id`` options (See the
  95. toolchain option reference). ``dds`` will infer common suitable defaults for
  96. the remaining options based on the value of ``compiler_id``.
  97. For example, if you specify ``gnu``, then ``dds`` will assume ``gcc`` to be the
  98. C compiler, ``g++`` to be the C++ compiler, and ``ar`` to be the library
  99. archiving tool.
  100. If you know that your compiler executable has a different name, you can
  101. specify them with additional options:
  102. .. code-block::
  103. {
  104. compiler_id: 'gnu',
  105. c_compiler: 'gcc-9',
  106. cxx_compiler: 'g++-9',
  107. }
  108. ``dds`` will continue to infer other options based on the ``compiler_id``, but
  109. will use the provided executable names when compiling files for the respective
  110. languages.
  111. To specify compilation flags, the ``Flags`` option can be used:
  112. .. code-block::
  113. {
  114. // [...]
  115. flags: '-fsanitize=address -fno-inline',
  116. }
  117. .. note::
  118. Use ``Warning-Flags`` to specify options regarding compiler warnings.
  119. Flags for linking executables can be specified with ``link_flags``:
  120. .. code-block::
  121. {
  122. // [...]
  123. link_flags: '-fsanitize=address -fPIE'
  124. }
  125. .. _toolchains.opt-ref:
  126. Toolchain Option Reference
  127. **************************
  128. The following options are available to be specified within a toolchain file:
  129. ``compiler_id``
  130. ---------------
  131. Specify the identity of the compiler. This option is used to infer many other
  132. facts about the toolchain. If specifying the full toolchain with the command
  133. templates, this option is not required.
  134. Valid values are:
  135. ``gnu``
  136. For GCC
  137. ``clang``
  138. For LLVM/Clang
  139. ``msvc``
  140. For Microsoft Visual C++
  141. ``c_compiler`` and ``cxx_compiler``
  142. -----------------------------------
  143. Names/paths of the C and C++ compilers, respectively. Defaults will be inferred
  144. from ``compiler_id``.
  145. ``c_version`` and ``cxx_version``
  146. ---------------------------------
  147. Specify the language versions for C and C++, respectively. By default, ``dds``
  148. will not set any language version. Using this option requires that the
  149. ``compiler_id`` be specified.
  150. Valid ``c_version`` values are:
  151. - ``c89``
  152. - ``c99``
  153. - ``c11``
  154. - ``c18``
  155. Valid ``cxx_version`` values are:
  156. - ``c++98``
  157. - ``c++03``
  158. - ``c++11``
  159. - ``c++14``
  160. - ``c++17``
  161. - ``c++20``
  162. .. warning::
  163. ``dds`` will not do any "smarts" to infer the exact option to pass to have
  164. the required effect. If you ask for ``c++20`` from ``gcc 4.8``, ``dds``
  165. will simply pass ``-std=c++20`` with no questions asked. If you need
  166. finer-grained control, use the ``c_flags`` and ``cxx_flags`` options.
  167. ``warning_flags``
  168. -----------------
  169. Override the compiler flags that should be used to enable warnings. This option
  170. is stored separately from ``flags``, as these options may be enabled/disabled
  171. separately depending on how ``dds`` is invoked.
  172. .. note::
  173. If ``compiler_id`` is provided, a default value will be used that enables
  174. common warning levels.
  175. If you need to tweak warnings further, use this option.
  176. ``flags``, ``c_flags``, and ``cxx_flags``
  177. -----------------------------------------
  178. Specify *additional* compiler options, possibly per-language.
  179. ``link_flags``
  180. --------------
  181. Specify *additional* link options to use when linking executables.
  182. ``optimize``
  183. ------------
  184. Boolean option (``true`` or ``false``) to enable/disable optimizations. Default
  185. is ``false``.
  186. ``debug``
  187. ---------
  188. Boolean option (``true`` or ``false``) to enable/disable the generation of
  189. debugging information. Default is ``false``.
  190. ``compiler_launcher``
  191. ---------------------
  192. Provide a command prefix that should be used on all compiler executions.
  193. e.g. ``ccache``.
  194. ``advanced``
  195. ------------
  196. A nested object that contains advanced toolchain options. Refer to section on
  197. advanced toolchain options.
  198. Advanced Options Reference
  199. **************************
  200. The options below are probably not good to tweak unless you *really* know what
  201. you are doing. Their values will be inferred from ``compiler_id``.
  202. ``deps_mode``
  203. -------------
  204. Specify the way in which ``dds`` should track compilation dependencies. One
  205. of ``gnu``, ``msvc``, or ``none``.
  206. ``c_compile_file``
  207. ------------------
  208. Override the *command template* that is used to compile C source files.
  209. ``cxx_compile_file``
  210. --------------------
  211. Override the *command template* that is used to compile C++ source files.
  212. ``create_archive``
  213. ------------------
  214. Override the *command template* that is used to generate static library archive
  215. files.
  216. ``link_executable``
  217. -------------------
  218. Override the *command template* that is used to link executables.
  219. ``include_template``
  220. --------------------
  221. Override the *command template* for the flags to specify a header search path.
  222. ``external_include_template``
  223. -----------------------------
  224. Override the *command template* for the flags to specify a header search path
  225. of an external library.
  226. ``define_template``
  227. -------------------
  228. Override the *command template* for the flags to set a preprocessor definition.
  229. ``obj_prefix``, ``obj_suffix``, ``archive_prefix``, ``archive_suffix``,
  230. ``exe_prefix``, and ``exe_suffix``
  231. ----------------------------------
  232. Set the filename prefixes and suffixes for object files, library archive files,
  233. and executable files, respectively.