Skip to content

Commit 41dcdfb

Browse files
committed
[libc++][docs] Major update to the documentation
- Landing page: add link to the libc++ Discord channel - Landing page: reorder "Getting Involved" above "Design documents" - Landing page: remove "Notes and Known Issues" which was completely outdated - Rename "Using Libc++" to "User Documentation" and update contents - Rename "Building Libc++" to "Vendor Documentation" and update contents The "BuildingLibcxx" and "UsingLibcxx" pages have basically been used for vendor and user documentation respectively. However, they were named in a way that doesn't really make that clear. Renaming the pages now gives us a location to clearly document what we target at vendors and what we target at users, and to do that separately.
1 parent 32679e1 commit 41dcdfb

File tree

6 files changed

+299
-341
lines changed

6 files changed

+299
-341
lines changed

libcxx/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# See https://libcxx.llvm.org/docs/BuildingLibcxx.html for instructions on how
2-
# to build libcxx with CMake.
3-
41
#===============================================================================
52
# Setup Project
63
#===============================================================================

libcxx/docs/Contributing.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
Contributing to libc++
55
======================
66

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.
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
9+
contributing to LLVM.
1010

1111
If you plan on contributing to libc++, it can be useful to join the ``#libcxx`` channel
1212
on `LLVM's Discord server <https://discord.gg/jzUbyP26tQ>`__.
@@ -24,16 +24,22 @@ RFCs for significant user-affecting changes
2424
===========================================
2525

2626
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>`__.
27+
please consider creating a RFC on the `libc++ forum <https://discourse.llvm.org/c/runtimes/libcxx>`_.
2828
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.
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.
31+
32+
Writing tests and running the test suite
33+
========================================
34+
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>`.
3138

3239
Coding standards
3340
================
3441

35-
In general, libc++ follows the
36-
`LLVM Coding Standards <https://llvm.org/docs/CodingStandards.html>`_.
42+
In general, libc++ follows the `LLVM Coding Standards <https://llvm.org/docs/CodingStandards.html>`_.
3743
There are some deviations from these standards.
3844

3945
Libc++ uses ``__ugly_names``. These names are reserved for implementations, so

libcxx/docs/TestingLibcxx.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
.. _testing:
2+
13
==============
24
Testing libc++
35
==============
46

57
.. contents::
68
:local:
79

8-
.. _testing:
9-
1010
Getting Started
1111
===============
1212

@@ -459,11 +459,6 @@ This will build all of the benchmarks under ``<libcxx>/test/benchmarks`` to be
459459
built against the just-built libc++. The compiled tests are output into
460460
``build/libcxx/test/benchmarks``.
461461

462-
Also See:
463-
464-
* :ref:`Building Libc++ <build instructions>`
465-
* :ref:`CMake Options`
466-
467462
Running Benchmarks
468463
------------------
469464

libcxx/docs/UsingLibcxx.rst renamed to libcxx/docs/UserDocumentation.rst

Lines changed: 86 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
.. _using-libcxx:
1+
.. _user-documentation:
22

3-
============
4-
Using libc++
5-
============
3+
==================
4+
User documentation
5+
==================
66

77
.. contents::
88
:local:
99

10-
Usually, libc++ is packaged and shipped by a vendor through some delivery vehicle
11-
(operating system distribution, SDK, toolchain, etc) and users don't need to do
12-
anything special in order to use the library.
13-
1410
This page contains information about configuration knobs that can be used by
1511
users when they know libc++ is used by their toolchain, and how to use libc++
16-
when it is not the default library used by their toolchain.
12+
when it is not the default library used by their toolchain. It is aimed at
13+
users of libc++: a separate page contains documentation aimed at vendors who
14+
build and ship libc++ as part of their toolchain.
1715

1816

1917
Using a different version of the C++ Standard
@@ -28,10 +26,29 @@ matches that Standard in the library.
2826
2927
$ clang++ -std=c++17 test.cpp
3028
31-
.. warning::
32-
Using ``-std=c++XY`` with a version of the Standard that has not been ratified yet
33-
is considered unstable. Libc++ reserves the right to make breaking changes to the
34-
library until the standard has been ratified.
29+
Note that using ``-std=c++XY`` with a version of the Standard that has not been ratified
30+
yet is considered unstable. While we strive to maintain stability, libc++ may be forced to
31+
make breaking changes to features shipped in a Standard that hasn't been ratified yet. Use
32+
these versions of the Standard at your own risk.
33+
34+
35+
Using libc++ when it is not the system default
36+
==============================================
37+
38+
Usually, libc++ is packaged and shipped by a vendor through some delivery vehicle
39+
(operating system distribution, SDK, toolchain, etc) and users don't need to do
40+
anything special in order to use the library.
41+
42+
On systems where libc++ is provided but is not the default, Clang provides a flag
43+
called ``-stdlib=`` that can be used to decide which standard library is used.
44+
Using ``-stdlib=libc++`` will select libc++:
45+
46+
.. code-block:: bash
47+
48+
$ clang++ -stdlib=libc++ test.cpp
49+
50+
On systems where libc++ is the library in use by default such as macOS and FreeBSD,
51+
this flag is not required.
3552

3653

3754
Enabling experimental C++ Library features
@@ -43,6 +60,11 @@ the Standard but whose implementation is not complete or stable yet in libc++. T
4360
are disabled by default because they are neither API nor ABI stable. However, the
4461
``-fexperimental-library`` compiler flag can be defined to turn those features on.
4562

63+
On compilers that do not support the ``-fexperimental-library`` flag (such as GCC),
64+
users can define the ``_LIBCPP_ENABLE_EXPERIMENTAL`` macro and manually link against
65+
the appropriate static library (usually shipped as ``libc++experimental.a``) to get
66+
access to experimental library features.
67+
4668
The following features are currently considered experimental and are only provided
4769
when ``-fexperimental-library`` is passed:
4870

@@ -51,7 +73,7 @@ when ``-fexperimental-library`` is passed:
5173
* ``std::jthread``
5274
* ``std::chrono::tzdb`` and related time zone functionality
5375

54-
.. warning::
76+
.. note::
5577
Experimental libraries are experimental.
5678
* The contents of the ``<experimental/...>`` headers and the associated static
5779
library will not remain compatible between versions.
@@ -60,98 +82,18 @@ when ``-fexperimental-library`` is passed:
6082
the experimental feature is removed two releases after the non-experimental
6183
version has shipped. The full policy is explained :ref:`here <experimental features>`.
6284

63-
.. note::
64-
On compilers that do not support the ``-fexperimental-library`` flag, users can
65-
define the ``_LIBCPP_ENABLE_EXPERIMENTAL`` macro and manually link against the
66-
appropriate static library (usually shipped as ``libc++experimental.a``) to get
67-
access to experimental library features.
68-
69-
70-
Using libc++ when it is not the system default
71-
==============================================
72-
73-
On systems where libc++ is provided but is not the default, Clang provides a flag
74-
called ``-stdlib=`` that can be used to decide which standard library is used.
75-
Using ``-stdlib=libc++`` will select libc++:
76-
77-
.. code-block:: bash
78-
79-
$ clang++ -stdlib=libc++ test.cpp
80-
81-
On systems where libc++ is the library in use by default such as macOS and FreeBSD,
82-
this flag is not required.
83-
84-
85-
.. _alternate libcxx:
86-
87-
Using a custom built libc++
88-
===========================
89-
90-
Most compilers provide a way to disable the default behavior for finding the
91-
standard library and to override it with custom paths. With Clang, this can
92-
be done with:
93-
94-
.. code-block:: bash
95-
96-
$ clang++ -nostdinc++ -nostdlib++ \
97-
-isystem <install>/include/c++/v1 \
98-
-L <install>/lib \
99-
-Wl,-rpath,<install>/lib \
100-
-lc++ \
101-
test.cpp
102-
103-
The option ``-Wl,-rpath,<install>/lib`` adds a runtime library search path,
104-
which causes the system's dynamic linker to look for libc++ in ``<install>/lib``
105-
whenever the program is loaded.
106-
107-
GCC does not support the ``-nostdlib++`` flag, so one must use ``-nodefaultlibs``
108-
instead. Since that removes all the standard system libraries and not just libc++,
109-
the system libraries must be re-added manually. For example:
110-
111-
.. code-block:: bash
112-
113-
$ g++ -nostdinc++ -nodefaultlibs \
114-
-isystem <install>/include/c++/v1 \
115-
-L <install>/lib \
116-
-Wl,-rpath,<install>/lib \
117-
-lc++ -lc++abi -lm -lc -lgcc_s -lgcc \
118-
test.cpp
119-
120-
121-
GDB Pretty printers for libc++
122-
==============================
123-
124-
GDB does not support pretty-printing of libc++ symbols by default. However, libc++ does
125-
provide pretty-printers itself. Those can be used as:
126-
127-
.. code-block:: bash
128-
129-
$ gdb -ex "source <libcxx>/utils/gdb/libcxx/printers.py" \
130-
-ex "python register_libcxx_printer_loader()" \
131-
<args>
132-
133-
.. _include-what-you-use:
134-
135-
include-what-you-use (IWYU)
136-
===========================
137-
138-
libc++ provides an IWYU `mapping file <https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md>`_,
139-
which drastically improves the accuracy of the tool when using libc++. To use the mapping file with
140-
IWYU, you should run the tool like so:
141-
142-
.. code-block:: bash
143-
144-
$ include-what-you-use -Xiwyu --mapping_file=/path/to/libcxx/include/libcxx.imp file.cpp
145-
146-
If you would prefer to not use that flag, then you can replace ``/path/to/include-what-you-use/share/libcxx.imp``
147-
file with the libc++-provided ``libcxx.imp`` file.
14885

14986
Libc++ Configuration Macros
15087
===========================
15188

152-
Libc++ provides a number of configuration macros which can be used to enable
153-
or disable extended libc++ behavior, including enabling hardening or thread
154-
safety annotations.
89+
Libc++ provides a number of configuration macros that can be used by developers to
90+
enable or disable extended libc++ behavior.
91+
92+
.. warning::
93+
Configuration macros that are not documented here are not intended to be customized
94+
by developers and should not be used. In particular, some configuration macros are
95+
only intended to be used by vendors and changing their value from the one provided
96+
in your toolchain can lead to unexpected behavior.
15597

15698
**_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
15799
This macro is used to enable -Wthread-safety annotations on libc++'s
@@ -193,6 +135,12 @@ safety annotations.
193135
warning saying that `std::auto_ptr` is deprecated. If the macro is defined,
194136
no warning will be emitted. By default, this macro is not defined.
195137

138+
**_LIBCPP_ENABLE_EXPERIMENTAL**:
139+
This macro enables experimental features. This can be used on compilers that do
140+
not support the ``-fexperimental-library`` flag. When used, users also need to
141+
ensure that the appropriate experimental library (usually ``libc++experimental.a``)
142+
is linked into their program.
143+
196144
C++17 Specific Configuration Macros
197145
-----------------------------------
198146
**_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR**:
@@ -307,7 +255,7 @@ Extensions to the C++23 modules ``std`` and ``std.compat``
307255
----------------------------------------------------------
308256

309257
Like other major implementations, libc++ provides C++23 modules ``std`` and
310-
``std.compat`` in C++20 as an extension"
258+
``std.compat`` in C++20 as an extension.
311259

312260
Constant-initialized std::string
313261
--------------------------------
@@ -386,3 +334,38 @@ specific locale is imbued, the IO with the underlying stream happens with
386334
regular ``char`` elements, which are converted to/from wide characters
387335
according to the locale. Note that this doesn't behave as expected if the
388336
stream has been set in Unicode mode.
337+
338+
339+
Third-party Integrations
340+
========================
341+
342+
Libc++ provides integration with a few third-party tools.
343+
344+
GDB Pretty printers for libc++
345+
------------------------------
346+
347+
GDB does not support pretty-printing of libc++ symbols by default. However, libc++ does
348+
provide pretty-printers itself. Those can be used as:
349+
350+
.. code-block:: bash
351+
352+
$ gdb -ex "source <libcxx>/utils/gdb/libcxx/printers.py" \
353+
-ex "python register_libcxx_printer_loader()" \
354+
<args>
355+
356+
357+
.. _include-what-you-use:
358+
359+
include-what-you-use (IWYU)
360+
---------------------------
361+
362+
libc++ provides an IWYU `mapping file <https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md>`_,
363+
which drastically improves the accuracy of the tool when using libc++. To use the mapping file with
364+
IWYU, you should run the tool like so:
365+
366+
.. code-block:: bash
367+
368+
$ include-what-you-use -Xiwyu --mapping_file=/path/to/libcxx/include/libcxx.imp file.cpp
369+
370+
If you would prefer to not use that flag, then you can replace ``/path/to/include-what-you-use/share/libcxx.imp``
371+
file with the libc++-provided ``libcxx.imp`` file.

0 commit comments

Comments
 (0)