|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- .. highlight:: js
-
- Toolchains
- ##########
-
- One of the core components of ``dds`` is that of the *toolchain*. A toolchain
- encompasses the environment used to build and link source code, including, but
- not limited to:
-
- #. The executable binaries that constitute the language implementation:
- Compilers, linkers, and archive managers.
- #. The configuration of those tools, including most options given to those
- tools when they are invoked.
- #. The set of preprocessor macros and language features that are active during
- compilation.
-
- When a build is run, every file in the entire tree (including dependencies)
- will be compiled, archived, and linked using the same toolchain.
-
- This page provides an introduction on how one can make use of toolchains most
- effectively in your project.
-
- .. note::
- **IMPORTANT**: ``dds`` will *not* automatically load the Visual C++
- environment. To use Visual C++, ``dds`` must be executed from the
- appropriate environment in order for the Visual C++ toolchain executables
- and files to be available.
-
-
- Passing a Toolchain
- *******************
-
- In ``dds``, the default format of a toolchain is that of a single JSON5 file
- that describes the entire toolchain. When running a build for a project, the
- ``dds`` executable will look in a few locations for a default toolchain, and
- generate an error if no default toolchain file is found (Refer to
- :ref:`toolchains.default`). A different toolchain can be provided by passing
- the toolchain file for the ``--toolchain`` (or ``-t``) option on the command
- line::
-
- $ dds build -t my-toolchain.json5
-
- Alternatively, you can pass the name of a built-in toolchain. See below.
-
-
- .. _toolchains.builtin:
-
- Built-in Toolchains
- *******************
-
- For convenience, ``dds`` includes several built-in toolchains that can be
- accessed in the ``--toolchain`` command-line option using a colon ``:``
- prefix::
-
- $ dds build -T :gcc
-
- ``dds`` will treat the leading colon (``:``) as a name for a built-in
- toolchain (this means that a toolchain's filepath may not begin with a colon).
-
- There are several built-in toolchains that may be specified:
-
- ``:gcc``
- Uses the default ``gcc`` and ``g++`` executables, linkers, and options
- thereof.
-
- ``:gcc-N`` (for some integer ``N``)
- Equivalent to ``:gcc``, but uses the ``gcc-N`` and ``g++-N`` executables.
-
- ``:clang``
- Equivalent to ``:gcc``, but uses the ``clang`` and ``clang++`` executables.
-
- ``:clang-N`` (for some integer ``N``)
- Equivalent to ``:clang``, but uses the ``clang-N`` and ``clang++-N``
- executables.
-
- ``:msvc``
- Compiles and links using the Visual C++ toolchain.
-
- The following pseudo-toolchains are also available:
-
- ``:debug:XYZ``
- Uses built-in toolchain ``:XYZ``, but generates debugging information.
-
- ``:ccache:XYZ``
- Uses built-in toolchain ``:XYZ``, but prefixes all compile commands with
- ``ccache``.
-
- ``:c++UV:XYZ`` (for two integers ``UV``)
- Sets the C++ version to ``C++UV`` and uses the ``:XYZ`` toolchain.
-
-
- .. _toolchains.default:
-
- Providing a Default Toolchain File
- **********************************
-
- If you do not which to provide a new toolchain for every individual project,
- and the built-in toolchains do not suit your needs, you can write a toolchain
- file to one of a few predefined paths, and ``dds`` will find and use it for the
- build. The following directories are searched, in order:
-
- #. ``$pwd/`` - If the working directory contains a toolchain file, it will be
- used as the default.
- #. ``$dds_config_dir/`` - Searches for a toolchain file in ``dds``'s user-local
- configuration directory (see below).
- #. ``$user_home/`` - Searches for a toolchain file at the root of the current
- user's home directory. (``$HOME`` on Unix-like systems, and ``$PROFILE`` on
- Windows.)
-
- In each directory, it will search for ``toolchain.json5``, ``toolchain.jsonc``,
- or ``toolchain.json``.
-
- The ``$dds_user_config`` directory is the ``dds`` subdirectory of the
- user-local configuration directory.
-
- The user-local config directory is ``$XDG_CONFIG_DIR`` or ``~/.config`` on
- Linux, ``~/Library/Preferences`` on macOS, and ``~/AppData/Roaming`` on
- Windows.
-
-
- Toolchain Definitions
- *********************
-
- Besides using the built-in toolchains, it is likely that you'll soon want to
- customize a toolchain further. Further customization must be done with a
- file that contains the toolchain definition. The most basic toolchain file is
- simply one line:
-
- .. code-block::
-
- {
- compiler_id: "<compiler-id>"
- }
-
- where ``<compiler-id>`` is one of the known ``compiler_id`` options (See the
- toolchain option reference). ``dds`` will infer common suitable defaults for
- the remaining options based on the value of ``compiler_id``.
-
- For example, if you specify ``gnu``, then ``dds`` will assume ``gcc`` to be the
- C compiler, ``g++`` to be the C++ compiler, and ``ar`` to be the library
- archiving tool.
-
- If you know that your compiler executable has a different name, you can
- specify them with additional options:
-
- .. code-block::
-
- {
- compiler_id: 'gnu',
- c_compiler: 'gcc-9',
- cxx_compiler: 'g++-9',
- }
-
- ``dds`` will continue to infer other options based on the ``compiler_id``, but
- will use the provided executable names when compiling files for the respective
- languages.
-
- To specify compilation flags, the ``Flags`` option can be used:
-
- .. code-block::
-
- {
- // [...]
- flags: '-fsanitize=address -fno-inline',
- }
-
- .. note::
- Use ``Warning-Flags`` to specify options regarding compiler warnings.
-
- Flags for linking executables can be specified with ``link_flags``:
-
- .. code-block::
-
- {
- // [...]
- link_flags: '-fsanitize=address -fPIE'
- }
-
-
- .. _toolchains.opt-ref:
-
- Toolchain Option Reference
- **************************
-
- The following options are available to be specified within a toolchain file:
-
-
- ``compiler_id``
- ---------------
-
- Specify the identity of the compiler. This option is used to infer many other
- facts about the toolchain. If specifying the full toolchain with the command
- templates, this option is not required.
-
- Valid values are:
-
- ``gnu``
- For GCC
-
- ``clang``
- For LLVM/Clang
-
- ``msvc``
- For Microsoft Visual C++
-
-
- ``c_compiler`` and ``cxx_compiler``
- -----------------------------------
-
- Names/paths of the C and C++ compilers, respectively. Defaults will be inferred
- from ``compiler_id``.
-
-
- ``c_version`` and ``cxx_version``
- ---------------------------------
-
- Specify the language versions for C and C++, respectively. By default, ``dds``
- will not set any language version. Using this option requires that the
- ``compiler_id`` be specified.
-
- Valid ``c_version`` values are:
-
- - ``c89``
- - ``c99``
- - ``c11``
- - ``c18``
-
- Valid ``cxx_version`` values are:
-
- - ``c++98``
- - ``c++03``
- - ``c++11``
- - ``c++14``
- - ``c++17``
- - ``c++20``
-
- .. warning::
- ``dds`` will not do any "smarts" to infer the exact option to pass to have
- the required effect. If you ask for ``c++20`` from ``gcc 4.8``, ``dds``
- will simply pass ``-std=c++20`` with no questions asked. If you need
- finer-grained control, use the ``c_flags`` and ``cxx_flags`` options.
-
-
- ``warning_flags``
- -----------------
-
- Override the compiler flags that should be used to enable warnings. This option
- is stored separately from ``flags``, as these options may be enabled/disabled
- separately depending on how ``dds`` is invoked.
-
- .. note::
- If ``compiler_id`` is provided, a default value will be used that enables
- common warning levels.
-
- If you need to tweak warnings further, use this option.
-
-
- ``flags``, ``c_flags``, and ``cxx_flags``
- -----------------------------------------
-
- Specify *additional* compiler options, possibly per-language.
-
-
- ``link_flags``
- --------------
-
- Specify *additional* link options to use when linking executables.
-
-
- ``optimize``
- ------------
-
- Boolean option (``true`` or ``false``) to enable/disable optimizations. Default
- is ``false``.
-
-
- ``debug``
- ---------
-
- Boolean option (``true`` or ``false``) to enable/disable the generation of
- debugging information. Default is ``false``.
-
-
- ``compiler_launcher``
- ---------------------
-
- Provide a command prefix that should be used on all compiler executions.
- e.g. ``ccache``.
-
-
- ``advanced``
- ------------
-
- A nested object that contains advanced toolchain options. Refer to section on
- advanced toolchain options.
-
-
- Advanced Options Reference
- **************************
-
- The options below are probably not good to tweak unless you *really* know what
- you are doing. Their values will be inferred from ``compiler_id``.
-
-
- ``deps_mode``
- -------------
-
- Specify the way in which ``dds`` should track compilation dependencies. One
- of ``gnu``, ``msvc``, or ``none``.
-
-
- ``c_compile_file``
- ------------------
-
- Override the *command template* that is used to compile C source files.
-
-
- ``cxx_compile_file``
- --------------------
-
- Override the *command template* that is used to compile C++ source files.
-
-
- ``create_archive``
- ------------------
-
- Override the *command template* that is used to generate static library archive
- files.
-
-
- ``link_executable``
- -------------------
-
- Override the *command template* that is used to link executables.
-
-
- ``include_template``
- --------------------
-
- Override the *command template* for the flags to specify a header search path.
-
-
- ``external_include_template``
- -----------------------------
-
- Override the *command template* for the flags to specify a header search path
- of an external library.
-
-
- ``define_template``
- -------------------
-
- Override the *command template* for the flags to set a preprocessor definition.
-
-
- ``obj_prefix``, ``obj_suffix``, ``archive_prefix``, ``archive_suffix``,
- ``exe_prefix``, and ``exe_suffix``
- ----------------------------------
-
- Set the filename prefixes and suffixes for object files, library archive files,
- and executable files, respectively.
|