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