xref: /aosp_15_r20/external/pigweed/pw_minimal_cpp_stdlib/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_minimal_cpp_stdlib:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker=====================
4*61c4878aSAndroid Build Coastguard Workerpw_minimal_cpp_stdlib
5*61c4878aSAndroid Build Coastguard Worker=====================
6*61c4878aSAndroid Build Coastguard Worker.. admonition:: �� Stop ��
7*61c4878aSAndroid Build Coastguard Worker
8*61c4878aSAndroid Build Coastguard Worker   **Do not use this module** unless you have consulted with the Pigweed team.
9*61c4878aSAndroid Build Coastguard Worker
10*61c4878aSAndroid Build Coastguard Worker-----------
11*61c4878aSAndroid Build Coastguard WorkerMaintenance
12*61c4878aSAndroid Build Coastguard Worker-----------
13*61c4878aSAndroid Build Coastguard WorkerIf you discovered this module because of a build failure in a
14*61c4878aSAndroid Build Coastguard Worker``pw_strict_host_clang_size_optimized_minimal_cpp_stdlib`` or similar target,
15*61c4878aSAndroid Build Coastguard Workerthe important thing to know is that a small set of Pigweed targets are expected
16*61c4878aSAndroid Build Coastguard Workerto compile using a limited set of C++ Standard Library features and headers
17*61c4878aSAndroid Build Coastguard Workerthat have been polyfilled by this module in order to support environments
18*61c4878aSAndroid Build Coastguard Workerwithout a C++ stdlib.
19*61c4878aSAndroid Build Coastguard Worker
20*61c4878aSAndroid Build Coastguard WorkerFailed ``#include`` lines should be solved by either eliminating the dependency
21*61c4878aSAndroid Build Coastguard Workerfrom the target (strongly preferred) or by adding a (minimal) polyfill of the
22*61c4878aSAndroid Build Coastguard Workerrelevant C++ header to this module.
23*61c4878aSAndroid Build Coastguard Worker
24*61c4878aSAndroid Build Coastguard WorkerPolyfills may assume a C++17 (or greater) compiler but with only a C (not C++)
25*61c4878aSAndroid Build Coastguard Workerstdlib. As this target does not support tests, polyfills can only be checked for
26*61c4878aSAndroid Build Coastguard Workercompilation; this can be done by building the root
27*61c4878aSAndroid Build Coastguard Worker``build_with_pw_minimal_cpp_stdlib group``
28*61c4878aSAndroid Build Coastguard Worker(e.g. ``ninja -C out build_with_pw_minimal_cpp_stdlib``).
29*61c4878aSAndroid Build Coastguard Worker
30*61c4878aSAndroid Build Coastguard Worker-------
31*61c4878aSAndroid Build Coastguard WorkerPurpose
32*61c4878aSAndroid Build Coastguard Worker-------
33*61c4878aSAndroid Build Coastguard WorkerThe ``pw_minimal_cpp_stdlib`` module provides an extremely limited, incomplete
34*61c4878aSAndroid Build Coastguard Workerimplementation of the C++ Standard Library. This module is only intended for
35*61c4878aSAndroid Build Coastguard Workertesting and development when compiling with C++17 or newer, but without access
36*61c4878aSAndroid Build Coastguard Workerto the C++ Standard Library (``-nostdinc++``).
37*61c4878aSAndroid Build Coastguard Worker
38*61c4878aSAndroid Build Coastguard WorkerProduction code should use a real C++ Standard Library implementation, such as
39*61c4878aSAndroid Build Coastguard Worker`libc++ <https://libcxx.llvm.org/>`_ or `libstdc++
40*61c4878aSAndroid Build Coastguard Worker<https://gcc.gnu.org/onlinedocs/libstdc++/>`_.
41*61c4878aSAndroid Build Coastguard Worker
42*61c4878aSAndroid Build Coastguard Worker.. warning::
43*61c4878aSAndroid Build Coastguard Worker
44*61c4878aSAndroid Build Coastguard Worker  ``pw_minimal_cpp_stdlib`` was created for a very specific purpose. It is NOT a
45*61c4878aSAndroid Build Coastguard Worker  general purpose C++ Standard Library implementation and should not be used as
46*61c4878aSAndroid Build Coastguard Worker  one.
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard Worker  - Many library features are **missing**.
49*61c4878aSAndroid Build Coastguard Worker  - Many features are **non-functioning stubs**.
50*61c4878aSAndroid Build Coastguard Worker  - Some features **do not match the C++ standard**.
51*61c4878aSAndroid Build Coastguard Worker  - Test coverage is **extremely limited**.
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard Worker-----------------
54*61c4878aSAndroid Build Coastguard WorkerBuild integration
55*61c4878aSAndroid Build Coastguard Worker-----------------
56*61c4878aSAndroid Build Coastguard WorkerThe top-level ``build_with_minimal_cpp_stdlib`` GN group builds a few supported
57*61c4878aSAndroid Build Coastguard Workermodules with ``pw_minimal_cpp_stdlib`` swapped in for the C++ library at the
58*61c4878aSAndroid Build Coastguard Workertoolchain level. Notably, ``pw_minimal_cpp_stdlib`` does not support
59*61c4878aSAndroid Build Coastguard Worker``pw_unit_test``, so this group does NOT run any tests.
60*61c4878aSAndroid Build Coastguard Worker
61*61c4878aSAndroid Build Coastguard Worker-----------
62*61c4878aSAndroid Build Coastguard WorkerCode layout
63*61c4878aSAndroid Build Coastguard Worker-----------
64*61c4878aSAndroid Build Coastguard WorkerThe C++ Standard Library headers (e.g. ``<cstdint>`` and ``<type_traits>``) are
65*61c4878aSAndroid Build Coastguard Workerdefined in ``public/``. These files are symlinks to their implementations in
66*61c4878aSAndroid Build Coastguard Worker``public/internal/``.
67*61c4878aSAndroid Build Coastguard Worker
68*61c4878aSAndroid Build Coastguard Worker.. tip::
69*61c4878aSAndroid Build Coastguard Worker
70*61c4878aSAndroid Build Coastguard Worker  You can automatically recreate the symlinks in ``public/`` by executing the
71*61c4878aSAndroid Build Coastguard Worker  following Bash code from ``pw_minimal_cpp_stdlib/public/``.
72*61c4878aSAndroid Build Coastguard Worker
73*61c4878aSAndroid Build Coastguard Worker  .. code-block:: bash
74*61c4878aSAndroid Build Coastguard Worker
75*61c4878aSAndroid Build Coastguard Worker     for f in $(ls pw_minimal_cpp_stdlib/internal/); do ln -s pw_minimal_cpp_stdlib/internal/$f ${f%.h}; done
76*61c4878aSAndroid Build Coastguard Worker
77*61c4878aSAndroid Build Coastguard Worker------------
78*61c4878aSAndroid Build Coastguard WorkerRequirements
79*61c4878aSAndroid Build Coastguard Worker------------
80*61c4878aSAndroid Build Coastguard Worker- C++17
81*61c4878aSAndroid Build Coastguard Worker- gcc or clang
82*61c4878aSAndroid Build Coastguard Worker- The C Standard Library
83