Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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