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