Skip to content

Commit 998a5c8

Browse files
committed
Implement <filesystem>
This patch implements the <filesystem> header and uses that to provide <experimental/filesystem>. Unlike other standard headers, the symbols needed for <filesystem> have not yet been placed in libc++.so. Instead they live in the new libc++fs.a library. Users of filesystem are required to link this library. (Also note that libc++experimental no longer contains the definition of <experimental/filesystem>, which now requires linking libc++fs). The reason for keeping <filesystem> out of the dylib for now is that it's still somewhat experimental, and the possibility of requiring an ABI breaking change is very real. In the future the symbols will likely be moved into the dylib, or the dylib will be made to link libc++fs automagically). Note that moving the symbols out of libc++experimental may break user builds until they update to -lc++fs. This should be OK, because the experimental library provides no stability guarantees. However, I plan on looking into ways we can force libc++experimental to automagically link libc++fs. In order to use a single implementation and set of tests for <filesystem>, it has been placed in a special `__fs` namespace. This namespace is inline in C++17 onward, but not before that. As such implementation is available in C++11 onward, but no filesystem namespace is present "directly", and as such name conflicts shouldn't occur in C++11 or C++14. llvm-svn: 338093
1 parent 567485a commit 998a5c8

File tree

178 files changed

+3980
-3163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+3980
-3163
lines changed

libcxx/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
107107
cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY
108108
"Install libc++experimental.a" ON
109109
"LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF)
110+
cmake_dependent_option(LIBCXX_INSTALL_FILESYSTEM_LIBRARY
111+
"Install libc++fs.a" ON
112+
"LIBCXX_ENABLE_FILESYSTEM_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF)
113+
110114
if (FUCHSIA)
111115
set(DEFAULT_ABI_VERSION 2)
112116
else()

libcxx/docs/BuildingLibcxx.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,15 @@ libc++experimental Specific Options
242242

243243
.. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL
244244

245-
**Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY``
245+
**Default**: ``ON``
246+
247+
Build filesystem as a standalone library libc++fs.a.
248+
249+
.. option:: LIBCXX_INSTALL_FILESYSTEM_LIBRARY:BOOL
246250

247-
Build filesystem as part of libc++experimental.a. This allows filesystem
248-
to be disabled without turning off the entire experimental library.
251+
**Default**: ``LIBCXX_ENABLE_FILESYSTEM AND LIBCXX_INSTALL_LIBRARY``
249252

253+
Install libc++fs.a alongside libc++.
250254

251255
.. _ABI Library Specific Options:
252256

libcxx/docs/UsingLibcxx.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ An example of using ``LD_LIBRARY_PATH``:
4949
$ export LD_LIBRARY_PATH=<libcxx-install-prefix>/lib
5050
$ ./a.out # Searches for libc++ along LD_LIBRARY_PATH
5151
52+
53+
Using ``<filesystem>`` and libc++fs
54+
====================================
55+
56+
Libc++ provides the implementation of the filesystem library in a separate
57+
library. Users of ``<filesystem>`` and ``<experimental/filesystem>`` are
58+
required to link ``-lc++fs``.
59+
60+
.. note::
61+
Prior to libc++ 7.0, users of ``<experimental/filesystem>`` were required
62+
to link libc++experimental.
63+
64+
.. warning::
65+
The Filesystem library is still experimental in nature. As such normal
66+
guarantees about ABI stability and backwards compatibility do not yet apply
67+
to it. In the future, this restriction will be removed.
68+
69+
5270
Using libc++experimental and ``<experimental/...>``
5371
=====================================================
5472

@@ -65,6 +83,9 @@ installed. For information on building libc++experimental from source see
6583
:ref:`Building Libc++ <build instructions>` and
6684
:ref:`libc++experimental CMake Options <libc++experimental options>`.
6785

86+
Note that as of libc++ 7.0 using the ``<experimental/filesystem>`` requires linking
87+
libc++fs instead of libc++experimental.
88+
6889
Also see the `Experimental Library Implementation Status <http://libcxx.llvm.org/ts1z_status.html>`__
6990
page.
7091

libcxx/include/__config

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343
# endif
4444
#endif
4545

46+
#ifndef _LIBCPP_STD_VER
47+
# if __cplusplus <= 201103L
48+
# define _LIBCPP_STD_VER 11
49+
# elif __cplusplus <= 201402L
50+
# define _LIBCPP_STD_VER 14
51+
# elif __cplusplus <= 201703L
52+
# define _LIBCPP_STD_VER 17
53+
# else
54+
# define _LIBCPP_STD_VER 18 // current year, or date of c++2a ratification
55+
# endif
56+
#endif // _LIBCPP_STD_VER
57+
4658
#if defined(__ELF__)
4759
# define _LIBCPP_OBJECT_FORMAT_ELF 1
4860
#elif defined(__MACH__)
@@ -462,6 +474,19 @@ namespace std {
462474
}
463475
}
464476

477+
#if _LIBCPP_STD_VER >= 17
478+
#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
479+
_LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
480+
#else
481+
#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
482+
_LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
483+
#endif
484+
485+
#define _LIBCPP_END_NAMESPACE_FILESYSTEM \
486+
_LIBCPP_END_NAMESPACE_STD } }
487+
488+
#define _VSTD_FS _VSTD::__fs::filesystem
489+
465490
#if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer)
466491
#define _LIBCPP_HAS_NO_ASAN
467492
#endif
@@ -959,18 +984,6 @@ template <unsigned> struct __static_assert_check {};
959984
#define _LIBCPP_WCTYPE_IS_MASK
960985
#endif
961986

962-
#ifndef _LIBCPP_STD_VER
963-
# if __cplusplus <= 201103L
964-
# define _LIBCPP_STD_VER 11
965-
# elif __cplusplus <= 201402L
966-
# define _LIBCPP_STD_VER 14
967-
# elif __cplusplus <= 201703L
968-
# define _LIBCPP_STD_VER 17
969-
# else
970-
# define _LIBCPP_STD_VER 18 // current year, or date of c++2a ratification
971-
# endif
972-
#endif // _LIBCPP_STD_VER
973-
974987
#if _LIBCPP_STD_VER > 11
975988
# define _LIBCPP_DEPRECATED [[deprecated]]
976989
#else

libcxx/include/experimental/__config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252

5353
#define _VSTD_CORO _VSTD_EXPERIMENTAL::coroutines_v1
5454

55-
#define _VSTD_FS ::std::experimental::filesystem::v1
56-
5755
#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD \
5856
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace parallelism_v2 {
5957

0 commit comments

Comments
 (0)