Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

303 Zeilen
11KB

  1. Package Layout
  2. ##############
  3. The units of distribution in ``dds`` are *packages*. A single package consists
  4. of one or more *libraries*. In the simplest case, a package will contain a
  5. single library.
  6. It may be easiest to work from the bottom-up when trying to understand how
  7. ``dds`` understands code.
  8. The layout expected by ``dds`` is based on the `Pitchfork layout`_ (PFL).
  9. ``dds`` does not make use of every provision of the layout document, but the
  10. features it does have are based on PFL.
  11. .. _Pitchfork layout: https://api.csswg.org/bikeshed/?force=1&url=https://raw.githubusercontent.com/vector-of-bool/pitchfork/develop/data/spec.bs
  12. In particular, the following directories are used:
  13. - ``src/``
  14. - ``include/``
  15. - ``libs/``
  16. - ``_build/`` (the default build output directory used by ``dds``).
  17. Note that the ``libs/*/`` directories can contain their own ``src/`` and
  18. ``include/`` directories, the purposes and behaviors of which match those of
  19. their top-level counterparts.
  20. Source Files
  21. ************
  22. The smallest subdivision of code that ``dds`` recognizes is the *source file*,
  23. which is exactly as it sounds: A single file containing some amount of code.
  24. Source files can be grouped on a few axes, the most fundamental of which is
  25. "Is this compiled?"
  26. ``dds`` uses source file extensions to determine whether a source file should
  27. be fed to the compiler. All of the common C and C++ file extensions are
  28. supported:
  29. .. list-table::
  30. - * Compiled as C
  31. * ``.c`` and ``.C``
  32. - * Compiled as C++
  33. * ``.cpp``, ``.c++``, ``.cc``, and ``.cxx``
  34. - * Not compiled
  35. * ``.H``, ``.H++``, ``.h``, ``.h++``, ``.hh``, ``.hpp``, ``.hxx``, and ``.inl``
  36. If a file's extension is not listed in the table above, ``dds`` will ignore it.
  37. .. note::
  38. Although headers are not compiled, this does not mean they are ignored.
  39. ``dds`` still understands and respects headers, and they are collected
  40. together as part of *source distribution*.
  41. .. _pkgs.apps-tests:
  42. Applications and Tests
  43. **********************
  44. ``dds`` will recognize certain compilable source files as belonging to
  45. applications and tests. If a compilable source file stem ends with ``.main`` or
  46. ``.test``, that source file is assumed to correspond to an executable to
  47. generate. The filename stem before the ``.main`` or ``.test`` will be used as
  48. the name of the generated executable. For example:
  49. - ``foo.main.cpp`` will generate an executable named ``foo``.
  50. - ``bar.test.cpp`` will generate an executable named ``bar``.
  51. - ``cat-meow.main.cpp`` will generate an executable named ``cat-meow``.
  52. - ``cats.musical.test.cpp`` will generate an executable named ``cats.musical``.
  53. .. note::
  54. ``dds`` will automatically append the appropriate filename extension to the
  55. generated executables based on the host and toolchain.
  56. An *application* source file is a source file whose file stem ends with
  57. ``.main``. ``dds`` will assume this source file to contain a program entry
  58. point function and not include it as part of the main library build. Instead,
  59. when ``dds`` is generating applications, the source file will be compiled, and
  60. the resulting object will be linked together with the enclosing library into an
  61. executable.
  62. A *test* source file is a source file whose file stem ends with ``.test``. Like
  63. application sources, a *test* source file is omitted from the main library, and
  64. it will be used to generate tests. The exact behavior of tests is determined by
  65. the ``Test-Driver`` setting for the package, but the default is that each test
  66. source file will generate a single test executable that is executed by ``dds``
  67. when running unit tests.
  68. The building of tests and applications can be controlled when running
  69. ``dds build``. If tests are built, ``dds`` will automatically execute those
  70. tests in parallel once the executables have been generated.
  71. In any case, the executables are associated with a *library*, and, when those
  72. executables are linked, the associated library (and its dependencies) will be
  73. linked into the final executable. There is no need to manually specify this
  74. linking behavior.
  75. .. _pkg.source-root:
  76. Source Roots
  77. ************
  78. Source files are collected as children of some *source root*. A *source
  79. root* is a single directory that contains some *portable* bundle of source
  80. files. The word "portable" is important: It is what distinguishes the
  81. source root from its child directories.
  82. Portability
  83. ===========
  84. By saying that a source root is "portable", It indicates that the directory
  85. itself can be moved, renamed, or copied without breaking the ``#include``
  86. directives of its children or of the directory's referrers.
  87. As a practical example, let's examine such a directory, which we'll call
  88. ``src/`` for the purposes of this example. Suppose we have a directory named
  89. ``src`` with the following structure:
  90. .. code-block:: text
  91. <path>/src/
  92. animals/
  93. mammal/
  94. mammal.hpp
  95. cat/
  96. cat.hpp
  97. sound.hpp
  98. sound.cpp
  99. dog/
  100. dog.hpp
  101. sound.hpp
  102. sound.cpp
  103. In this example, ``src/`` is a *source root*, but ``src/animals/``,
  104. ``src/animals/cat/``, and ``src/animals/dog/`` are **not** source roots.
  105. While they may be directories that contain source files, they are not "roots."
  106. Suppose now that ``dog.hpp`` contains an ``#include`` directive:
  107. .. code-block:: c++
  108. #include <animals/mammal/mammal.hpp>
  109. or even a third-party user that wants to use our library:
  110. .. code-block:: c++
  111. #include <animals/dog/dog.hpp>
  112. #include <animals/dog/sound.hpp>
  113. In order for any code to compile and resolve these ``#include`` directives, the
  114. ``src/`` directory must be added to their *include search path*.
  115. Because the ``#include`` directives are based on the *portable* source root,
  116. the exactly location of ``src/`` is not important to the content of the
  117. consuming source code, and can thus be relocated and renamed as necessary.
  118. Consumers only need to update the path of the *include search path* in a single
  119. location rather than modifying their source code.
  120. .. _pkgs.source-root:
  121. Source Roots in ``dds``
  122. =======================
  123. To avoid ambiguity and aide in portability, the following rules should be
  124. strictly adhered to:
  125. #. Source roots may not contain other source roots.
  126. #. Only source roots will be added to the *include-search-path*.
  127. #. All ``#include``-directives are relative to a source root.
  128. By construction, ``dds`` cannot build a project that has nested source roots,
  129. and it will only ever add source roots to the *include-search-path*.
  130. ``dds`` supports either one or two source roots in a library.
  131. .. _pkgs.lib-roots:
  132. Library Roots
  133. *************
  134. In ``dds``, a *library root* is a directory that contains a ``src/`` directory,
  135. an ``include/`` directory, or both. ``dds`` will treat both directories as
  136. source roots, but behaves differently between the two. The ``src/`` and
  137. ``include/`` directories are themselves *source roots*.
  138. ``dds`` distinguishes between a *public* include-directory, and a *private*
  139. include-directory. When ``dds`` is compiling a library, both its *private* and
  140. its *public* include-paths will be added to the compiler's
  141. *include-search-path*. When a downstream user of a library is compiling against
  142. a library managed by ``dds``, only the *public* include-directory will be
  143. added to the compiler's *include-search-path*. This has the effect that only
  144. the files that are children of the source root that is the *public*
  145. include-directory will be available when compiling consumers.
  146. .. warning::
  147. Because only the *public* include-directory is available when compiling
  148. consumers, it is essential that no headers within the *public*
  149. include-directory attempt to use headers from the *private*
  150. include-directory, as they **will not** be visible.
  151. If both ``src/`` and ``include/`` are present in a library root, then ``dds``
  152. will use ``include/`` as the *public* include-directory and ``src/`` as the
  153. *private* include-directory. If only one of the two is present, then that
  154. directory will be treated as the *public* include-directory, and there will be
  155. no *private* include-directory.
  156. When ``dds`` exports a library, the header files from the *public*
  157. include-directory source root will be collected together and distributed as
  158. that library's header tree. The path to the individual header files relative to
  159. their source root will be retained as part of the library distribution.
  160. ``dds`` will compile every compilable source file that appears in the ``src/``
  161. directory. ``dds`` will not compile compilable source files that appear in the
  162. ``include/`` directory and will issue a warning on each file found.
  163. Libraries
  164. *********
  165. The *library* is a fundamental unit of consumable code, and ``dds`` is
  166. specifically built to work with them. When you are in ``dds``, the library is
  167. the center of everything.
  168. A single *library root* will always correspond to exactly one library. If the
  169. library has any compilable sources then ``dds`` will use those sources to
  170. generate a static library file that is linked into runtime binaries. If a
  171. library contains only headers then ``dds`` will not generate an archive to be
  172. included in downstream binaries, but it will still generate link rules for the
  173. dependencies of a header-only library.
  174. In order for ``dds`` to be able to distribute and interlink libraries, a
  175. ``library.dds`` file must be present at the corresponding library root. The
  176. only required key in a ``library.dds`` file is ``Name``:
  177. .. code-block:: yaml
  178. Name: my-library
  179. .. seealso:: More information is discussed on the :ref:`deps.lib-deps` page
  180. .. _pkgs.pkg-root:
  181. Package Roots
  182. *************
  183. A *package root* is a directory that contains some number of library roots. If
  184. the package root contains a ``src/`` and/or ``include/`` directory then the
  185. package root is itself a library root, and a library is defined at the root of
  186. the package. This is intended to be the most common and simplest method of
  187. creating libraries with ``dds``.
  188. If the package root contains a ``libs/`` directory, then each subdirectory of
  189. the ``libs/`` directory is checked to be a library root. Each direct child of
  190. the ``libs/`` directory that is also a library root is added as a child of the
  191. owning package.
  192. Packages
  193. ********
  194. A package is defined by some *package root*, and contains some number of
  195. *libraries*.
  196. The primary distribution format of packages that is used by ``dds`` is the
  197. *source distribution*. Refer to the page :doc:`source-dists`.
  198. Packages are identified by a name/version pair, joined together by an ``@``
  199. symbol. The version of a package must be a semantic version string. Together,
  200. the ``name@version`` string forms the *package ID*, and it must be unique
  201. within a repository or package catalog.
  202. In order for a package to be exported by ``dds`` it must have a
  203. ``package.dds`` file at its package root. Three keys are required to be
  204. present in the ``package.dds`` file: ``Name``, ``Version``, and ``Namespace``:
  205. .. code-block:: yaml
  206. Name: acme-widgets
  207. Version: 6.7.3
  208. Namespace: acme
  209. ``Version`` must be a valid semantic version string.
  210. .. note::
  211. The ``Namespace`` key is arbitrary, and not necessarily associated with
  212. and C++ ``namespace``.
  213. .. seealso::
  214. The purpose of ``Namespace``, as well as additional options in this file,
  215. are described in the :ref:`deps.pkg-deps` page