1 .. _ContributingToLibcxx:
7 This file contains information useful when contributing to libc++. If this is your first time contributing,
8 please also read `this document <https://www.llvm.org/docs/Contributing.html>`__ on general rules for
11 If you plan on contributing to libc++, it can be useful to join the ``#libcxx`` channel
12 on `LLVM's Discord server <https://discord.gg/jzUbyP26tQ>`__.
14 Looking for pre-existing pull requests
15 ======================================
17 Before you start working on any feature, please take a look at the open libc++ pull
18 requests to avoid duplicating someone else's work. You can do that on GitHub by
19 filtering pull requests `tagged with libc++ <https://github.com/llvm/llvm-project/pulls?q=is%3Apr+is%3Aopen+label%3Alibc%2B%2B>`__.
20 If you see that your feature is already being worked on, please consider chiming in
21 and helping review the code instead of duplicating work!
23 RFCs for significant user-affecting changes
24 ===========================================
26 Before you start working on a change that can have significant impact on users of the library,
27 please consider creating a RFC on the `libc++ forum <https://discourse.llvm.org/c/runtimes/libcxx>`_.
28 This will ensure that you work in a direction that the project endorses and will ease reviewing your
29 contribution as directional questions can be raised early. Including a WIP patch is not mandatory,
30 but it can be useful to ground the discussion in something concrete.
32 Writing tests and running the test suite
33 ========================================
35 Every change in libc++ must come with appropriate tests. Libc++ has an extensive test suite that
36 should be run locally by developers before submitting patches and is also run as part of our CI
37 infrastructure. The documentation about writing tests and running them is :ref:`here <testing>`.
42 In general, libc++ follows the `LLVM Coding Standards <https://llvm.org/docs/CodingStandards.html>`_.
43 There are some deviations from these standards.
45 Libc++ uses ``__ugly_names``. These names are reserved for implementations, so
46 users may not use them in their own applications. When using a name like ``T``,
47 a user may have defined a macro that changes the meaning of ``T``. By using
48 ``__ugly_names`` we avoid that problem. Other standard libraries and compilers
49 use these names too. To avoid common clashes with other uglified names used in
50 other implementations (e.g. system headers), the test in
51 ``libcxx/test/libcxx/system_reserved_names.gen.py`` contains the list of
52 reserved names that can't be used.
54 Unqualified function calls are susceptible to
55 `argument-dependent lookup (ADL) <https://en.cppreference.com/w/cpp/language/adl>`_.
56 This means calling ``move(UserType)`` might not call ``std::move``. Therefore,
57 function calls must use qualified names to avoid ADL. Some functions in the
58 standard library `require ADL usage <http://eel.is/c++draft/contents#3>`_.
59 Names of classes, variables, concepts, and type aliases are not subject to ADL.
60 They don't need to be qualified.
62 Function overloading also applies to operators. Using ``&user_object`` may call
63 a user-defined ``operator&``. Use ``std::addressof`` instead. Similarly, to
64 avoid invoking a user-defined ``operator,``, make sure to cast the result to
65 ``void`` when using the ``,``. For example:
69 for (; __first1 != __last1; ++__first1, (void)++__first2) {
73 In general, try to follow the style of existing code. There are a few
76 - Prefer ``using foo = int`` over ``typedef int foo``. The compilers supported
77 by libc++ accept alias declarations in all standard modes.
81 - Keep the number of formatting changes in patches minimal.
82 - Provide separate patches for style fixes and for bug fixes or features. Keep in
83 mind that large formatting patches may cause merge conflicts with other patches
84 under review. In general, we prefer to avoid large reformatting patches.
85 - Keep patches self-contained. Large and/or complicated patches are harder to
86 review and take a significant amount of time. It's fine to have multiple
87 patches to implement one feature if the feature can be split into
88 self-contained sub-tasks.
97 - ``libcxx/include/__config`` -- this file contains the commonly used
98 macros in libc++. Libc++ supports all C++ language versions. Newer versions
99 of the Standard add new features. For example, making functions ``constexpr``
100 in C++20 is done by using ``_LIBCPP_CONSTEXPR_SINCE_CXX20``. This means the
101 function is ``constexpr`` in C++20 and later. The Standard does not allow
102 making this available in C++17 or earlier, so we use a macro to implement
104 - ``libcxx/test/support/test_macros.h`` -- similar to the above, but for the
111 Libc++ implements the library part of the ISO C++ standard. The official
112 publication must be bought from ISO or your national body. This is not
113 needed to work on libc++, there are other free resources available.
115 - The `LaTeX sources <https://github.com/cplusplus/draft>`_ used to
116 create the official C++ standard. This can be used to create your own
117 unofficial build of the standard.
119 - An `HTML rendered version of the draft <https://eel.is/c++draft/>`_ is
120 available. This is the most commonly used place to look for the
121 wording of the standard.
123 - An `alternative <https://github.com/timsong-cpp/cppwp>`_ is available.
124 This link has both recent and historic versions of the standard.
126 - When implementing features, there are
127 `general requirements <https://eel.is/c++draft/#library>`_.
129 `jargon <http://eel.is/c++draft/structure#specifications>`_
130 to describe how library functions work.
132 - The `WG21 redirect service <https://wg21.link/>`_ is a tool to quickly locate
133 papers, issues, and wording in the standard.
135 - The `paper trail <https://github.com/cplusplus/papers/issues>`_ of
136 papers is publicly available, including the polls taken. It
137 contains links to the minutes of paper's discussion. Per ISO rules,
138 these minutes are only accessible by members of the C++ committee.
140 - `Feature-Test Macros and Policies
141 <https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations>`_
142 contains information about feature-test macros in C++.
143 It contains a list with all feature-test macros, their versions, and the paper
144 that introduced them.
146 - `cppreference <https://en.cppreference.com/w/>`_ is a good resource
147 for the usage of C++ library and language features. It's easier to
148 read than the C++ Standard, but it lacks details needed to properly implement
152 Pre-commit check list
153 =====================
155 Before committing or creating a review, please go through this check-list to make
156 sure you don't forget anything:
158 - Do you have :ref:`tests <testing>` for every public class and/or function you're adding or modifying?
159 - Did you update the synopsis of the relevant headers?
160 - Did you update the relevant files to track implementation status (in ``docs/Status/``)?
161 - Did you mark all functions and type declarations with the :ref:`proper visibility macro <visibility-macros>`?
162 - Did you add all new named declarations to the ``std`` module?
163 - If you added a header:
165 - Did you add it to ``include/module.modulemap``?
166 - Did you add it to ``include/CMakeLists.txt``?
167 - If it's a public header, did you update ``utils/libcxx/header_information.py``?
169 - Did you add the relevant feature test macro(s) for your feature? Did you update the ``generate_feature_test_macro_components.py`` script with it?
170 - Did you run the ``libcxx-generate-files`` target and verify its output?
171 - If needed, did you add ``_LIBCPP_PUSH_MACROS`` and ``_LIBCPP_POP_MACROS`` to the relevant headers?
176 After uploading your patch, you should see that the "libc++" review group is automatically
177 added as a reviewer for your patch. Once the group is marked as having approved your patch,
178 you can commit it. However, if you get an approval very quickly for a significant patch,
179 please try to wait a couple of business days before committing to give the opportunity for
180 other reviewers to chime in. If you need someone else to commit the patch for you, please
181 mention it and provide your ``Name <email@domain>`` for us to attribute the commit properly.
183 Note that the rule for accepting as the "libc++" review group is to wait for two members
184 of the group to have approved the patch, excluding the patch author. This is not a hard
185 rule -- for very simple patches, use your judgement. The `"libc++" review group <https://reviews.llvm.org/project/members/64/>`__
186 consists of frequent libc++ contributors with a good understanding of the project's
187 guidelines -- if you would like to be added to it, please reach out on Discord.
189 Exporting new symbols from the library
190 ======================================
192 When exporting new symbols from libc++, you must update the ABI lists located in ``lib/abi``.
193 To test whether the lists are up-to-date, please run the target ``check-cxx-abilist``.
194 To regenerate the lists, use the target ``generate-cxx-abilist``.
195 The ABI lists must be updated for all supported platforms; currently Linux and
196 Apple. If you don't have access to one of these platforms, you can download an
197 updated list from the failed build at
198 `Buildkite <https://buildkite.com/llvm-project/libcxx-ci>`__.
199 Look for the failed build and select the ``artifacts`` tab. There, download the
200 abilist for the platform, e.g.:
203 * MacOS X86_64 and MacOS arm64 for the Apple platform.
212 Unlike most parts of the LLVM project, libc++ uses a pre-commit CI [#]_. This
213 CI is hosted on `Buildkite <https://buildkite.com/llvm-project/libcxx-ci>`__ and
214 the build results are visible in the review on GitHub. Please make sure
215 the CI is green before committing a patch.
217 The CI tests libc++ for all :ref:`supported platforms <SupportedPlatforms>`.
218 The build is started for every commit added to a Pull Request. A complete CI
219 run takes approximately one hour. To reduce the load:
221 * The build is cancelled when a new commit is pushed to a PR that is already running CI.
222 * The build is done in several stages and cancelled when a stage fails.
224 Typically, the libc++ jobs use a Ubuntu Docker image. This image contains
225 recent `nightly builds <https://apt.llvm.org>`__ of all supported versions of
226 Clang and the current version of the ``main`` branch. These versions of Clang
227 are used to build libc++ and execute its tests.
229 Unless specified otherwise, the configurations:
231 * use a nightly build of the ``main`` branch of Clang,
232 * execute the tests using the language C++<latest>. This is the version
233 "developed" by the C++ committee.
235 .. note:: Updating the Clang nightly builds in the Docker image is a manual
236 process and is done at an irregular interval on purpose. When you need to
237 have the latest nightly build to test recent Clang changes, ask in the
238 ``#libcxx`` channel on `LLVM's Discord server
239 <https://discord.gg/jzUbyP26tQ>`__.
241 .. [#] There's `LLVM Dev Meeting talk <https://www.youtube.com/watch?v=B7gB6van7Bw>`__
242 explaining the benefits of libc++'s pre-commit CI.
247 Below is a short description of the most interesting CI builds [#]_:
249 * ``Format`` runs ``clang-format`` and uploads its output as an artifact. At the
250 moment this build is a soft error and doesn't fail the build.
251 * ``Generated output`` runs the ``libcxx-generate-files`` build target and
252 tests for non-ASCII characters in libcxx. Some files are excluded since they
253 use Unicode, mainly tests. The output of these commands are uploaded as
255 * ``Documentation`` builds the documentation. (This is done early in the build
256 process since it is cheap to run.)
257 * ``C++<version>`` these build steps test the various C++ versions, making sure all
258 C++ language versions work with the changes made.
259 * ``Clang <version>`` these build steps test whether the changes work with all
260 supported Clang versions.
261 * ``Booststrapping build`` builds Clang using the revision of the patch and
262 uses that Clang version to build and test libc++. This validates the current
263 Clang and lib++ are compatible.
265 When a crash occurs in this build, the crash reproducer is available as an
268 * ``Modular build`` tests libc++ using Clang modules [#]_.
269 * ``GCC <version>`` tests libc++ with the latest stable GCC version. Only C++11
270 and the latest C++ version are tested.
271 * ``Santitizers`` tests libc++ using the Clang sanitizers.
272 * ``Parts disabled`` tests libc++ with certain libc++ features disabled.
273 * ``Windows`` tests libc++ using MinGW and clang-cl.
274 * ``Apple`` tests libc++ on MacOS.
275 * ``ARM`` tests libc++ on various Linux ARM platforms.
276 * ``AIX`` tests libc++ on AIX.
278 .. [#] Not all steps are listed: steps are added and removed when the need arises.
279 .. [#] Clang modules are not the same as C++20's modules.
284 All files of the CI infrastructure are in the directory ``libcxx/utils/ci``.
285 Note that quite a bit of this infrastructure is heavily Linux focused. This is
286 the platform used by most of libc++'s Buildkite runners and developers.
291 Contains the Docker image for the Ubuntu CI. Because the same Docker image is
292 used for the ``main`` and ``release`` branch, it should contain no hard-coded
293 versions. It contains the used versions of Clang, various clang-tools,
296 .. note:: This image is pulled from Docker hub and not rebuild when changing
299 run-buildbot-container
300 ~~~~~~~~~~~~~~~~~~~~~~
302 Helper script that pulls and runs the Docker image. This image mounts the LLVM
303 monorepo at ``/llvm``. This can be used to test with compilers not available on
309 Contains the build script executed on Buildkite. This script can be executed
310 locally or inside ``run-buildbot-container``. The script must be called with
311 the target to test. For example, ``run-buildbot generic-cxx20`` will build
312 libc++ and test it using C++20.
314 .. warning:: This script will overwrite the directory ``<llvm-root>/build/XX``
315 where ``XX`` is the target of ``run-buildbot``.
317 This script contains as little version information as possible. This makes it
318 easy to use the script with a different compiler. This allows testing a
319 combination not in the libc++ CI. It can be used to add a new (temporary)
320 job to the CI. For example, testing the C++17 build with Clang-14 can be done
325 CC=clang-14 CXX=clang++-14 run-buildbot generic-cxx17
327 buildkite-pipeline.yml
328 ~~~~~~~~~~~~~~~~~~~~~~
330 Contains the jobs executed in the CI. This file contains the version
331 information of the jobs being executed. Since this script differs between the
332 ``main`` and ``release`` branch, both branches can use different compiler