.. SPDX-License-Identifier: MIT .. _startup: =========== Using RCSW =========== .. _startup/consumer: As a Dependency =============== The recommended way to consume RCSW in a CMake project is via `CPM `_: .. code-block:: cmake CPMAddPackage( NAME rcsw GITHUB_REPOSITORY jharwell/rcsw VERSION ) target_link_libraries(myapp PRIVATE rcsw::rcsw) Or, if you have installed RCSW via ``cmake --install``: .. code-block:: cmake find_package(rcsw REQUIRED) target_link_libraries(myapp PRIVATE rcsw::rcsw) Which targets you link depends on how RCSW was built: - **Monolithic build**: one target, ``rcsw::rcsw``, as above. - **Component build**: one target per component. Link the components you use; each one brings its own dependencies (see :ref:`concepts/components`). Either way, include paths, compile definitions, and transitive dependencies are propagated automatically through the targets. .. _startup/dev: As a Developer ============== From the root of the repo: .. code-block:: bash cmake --preset debug ```` is a list of cmake arguments. You can pass any option that LIBRA supports (see :ref:`libra:main`) or any RCSW option listed below. .. _startup/cmake: CMake Configuration =================== .. NOTE:: All cmake options with a direct code analogue are prefixed ``RCSW_CONFIG_``; options that affect only the build system (e.g., ``RCSW_SUMMARY``) are prefixed ``RCSW_``. Build Targets ------------- .. cmake:variable:: RCSW_BUILD_FOR :default: POSIX Target platform. Valid values: - ``POSIX`` — Linux and POSIX-compatible OSes. Enables the full feature set including multithread, multiprocess, and swbus. - ``BAREMETAL`` — Bare-metal environments without an OS. Enables stdlib from the selected compiler. To also strip stdlib, pass ``LIBRA_NOSTDLIB`` (see :ref:`LIBRA docs `); this restricts which modules are usable. See :ref:`platforms` for the full breakdown. .. cmake:variable:: RCSW_CONFIG_LIBTYPE :default: STATIC Whether to build RCSW as a ``SHARED`` or ``STATIC`` library. .. cmake:variable:: RCSW_CONFIG_NO_STDIO :default: NO Exclude the STDIO module from compilation. Useful on POSIX targets when you are linking against libc and do not need the printf replacement. .. cmake:variable:: RCSW_SUMMARY :default: YES Print a summary of all RCSW-specific cmake variables at configure time. Memory Allocation ----------------- .. cmake:variable:: RCSW_CONFIG_NOALLOC :default: NO Disallow all dynamic heap allocation. When ``YES``, implies :c:macro:`RCSW_NOALLOC_META`, :c:macro:`RCSW_NOALLOC_DATA`, and :c:macro:`RCSW_NOALLOC_HANDLE` for all modules that support them. You can also set these flags individually at run time, in the ``flags`` field of each module's ``xx_config`` struct. See :ref:`concepts/memory-model`. Some parts of RCSW can't work without a heap, and fail to initialize in such a build: - the LOG4CL ER plugin, whose module table is a heap-allocated list; use the ``simple`` plugin instead; - :c:struct:`dynmatrix`, whose rows are always heap-allocated; - the dynamic-programming algorithms (edit distance, LCS, matrix chain optimization), whose scratch tables are heap-allocated; - :c:struct:`darray` growth beyond its initial capacity, and unbounded (``max_elts = -1``) structures. Tests tagged ``[noalloc]`` are exactly the ones that run without a heap; run only those (``"[noalloc]"`` as the Catch2 test spec) in a ``RCSW_CONFIG_NOALLOC`` build. .. cmake:variable:: RCSW_CONFIG_ZALLOC :default: NO Zero-initialize all memory (whether dynamically allocated or caller-supplied) before use, as if :c:macro:`RCSW_ZALLOC` were passed everywhere. See :ref:`concepts/memory-model`. .. cmake:variable:: RCSW_CONFIG_PTR_ALIGN :default: 8 on 64-bit and 4 on 32-bit known architectures; 1 otherwise Override the pointer alignment used to store all application data managed by RCSW. Some architectures trap on unaligned accesses (e.g., strict ARM variants); others handle them silently or in hardware. RCSW detects the best value for known architectures, but falls back to byte alignment (1) for unknown targets. Override if you know your target requires or benefits from a specific alignment. Must be one of [1, 2, 4, 8]. See :ref:`concepts/memory-model` for how to choose. STDIO / printf Replacement -------------------------- .. cmake:variable:: RCSW_CONFIG_STDIO_PUTCHAR :default: ``putchar`` Name of the ``putchar()``-compatible function RCSW's printf will call to emit characters. Must have the same signature as ``putchar()``. Override when linking to a custom BSP output routine. In a shared build the function must be resolvable when RCSW itself is linked; see :ref:`concepts/components`. .. cmake:variable:: RCSW_CONFIG_STDIO_GETCHAR :default: ``getchar`` Name of the ``getchar()``-compatible function :c:func:`stdio_getchar` calls to read characters (minimon reads its input this way). Must have the same signature as ``getchar()``. The same linking rule as :cmake:variable:`RCSW_CONFIG_STDIO_PUTCHAR` applies. printf() formatting behavior (float support, buffer sizes, precision, etc.) is controlled by the `eyalroz/printf `_ dependency, which RCSW pulls in via CPM. To override an upstream option, set it in your CMake invocation before including RCSW — CPM respects already-set cache variables. Event Reporting --------------- .. cmake:variable:: RCSW_CONFIG_ER_PLUGIN :default: LOG4CL The ER plugin to build against. See :ref:`library/er` for plugin details and tradeoffs. .. cmake:variable:: RCSW_CONFIG_ER_PLUGIN_PATH :default: (empty) Absolute or relative (to the build directory) path to the ``#include`` file defining the custom ER plugin macros. Only required when ``RCSW_CONFIG_ER_PLUGIN=CUSTOM``. This file is **not** installed with RCSW; ensure it is findable by any application that links against RCSW. See the Custom plugin tab in :ref:`library/er` for required macro definitions. Instrumentation --------------- .. cmake:variable:: RCSW_CONFIG_NO_GRIND :default: NO Compile out the timing/profiling macros :c:macro:`RCSW_GRIND_START()`, :c:macro:`RCSW_GRIND_END()`, :c:macro:`RCSW_GRIND_COUNT()`, and :c:macro:`RCSW_GRIND_TICK()`. Allows timing instrumentation to be left in application source and enabled only when profiling is needed, without runtime cost otherwise.