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.

336 lines
12KB

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