Skip to content

Commit 66a562d

Browse files
committed
[libc++] Roll up fstream support into filesystem support
LIBCXX_ENABLE_FILESYSTEM should represent whether the platform has support for a filesystem, not just whether we support <filesystem>. This patch slightly generalizes the setting to also encompass whether we provide <fstream>, since that only makes sense when a filesystem is supported. Differential Revision: https://reviews.llvm.org/D152168
1 parent a3a4369 commit 66a562d

File tree

26 files changed

+53
-75
lines changed

26 files changed

+53
-75
lines changed

libcxx/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ option(LIBCXX_ENABLE_ASSERTIONS
5757
by users in their own code regardless of this option." OFF)
5858
option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
5959
option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
60-
option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library" ON)
60+
option(LIBCXX_ENABLE_FILESYSTEM
61+
"Whether to include support for parts of the library that rely on a filesystem being
62+
available on the platform. This includes things like most parts of <filesystem> and
63+
others like <fstream>" ON)
6164
option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
6265
option(LIBCXX_ENABLE_DEBUG_MODE
6366
"Whether to build libc++ with the debug mode enabled.
@@ -76,8 +79,6 @@ option(LIBCXX_ENABLE_LOCALIZATION
7679
the C locale API (e.g. embedded). When localization is not supported,
7780
several parts of the library will be disabled: <iostream>, <regex>, <locale>
7881
will be completely unusable, and other parts may be only partly available." ON)
79-
option(LIBCXX_ENABLE_FSTREAM
80-
"Whether to include support for <fstream>." ON) # TODO: Consider rolling that into LIBCXX_ENABLE_FILESYSTEM
8182
option(LIBCXX_ENABLE_UNICODE
8283
"Whether to include support for Unicode in the library. Disabling Unicode can
8384
be useful when porting to platforms that don't support UTF-8 encoding (e.g.
@@ -779,10 +780,9 @@ config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
779780
config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
780781
config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
781782
config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
782-
config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
783+
config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM)
783784
config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
784785
config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION)
785-
config_define_if_not(LIBCXX_ENABLE_FSTREAM _LIBCPP_HAS_NO_FSTREAM)
786786
config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE)
787787
config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS)
788788
config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)

libcxx/cmake/caches/Generic-no-fstream.cmake

Lines changed: 0 additions & 1 deletion
This file was deleted.

libcxx/docs/ReleaseNotes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,11 @@ Build System Changes
153153
- Building libc++ and libc++abi for Apple platforms now requires targeting macOS 10.13 and later.
154154
This is relevant for vendors building the libc++ shared library and for folks statically linking
155155
libc++ into an application that has back-deployment requirements on Apple platforms.
156+
157+
- ``LIBCXX_ENABLE_FILESYSTEM`` now represents whether a filesystem is supported on the platform instead
158+
of representing merely whether ``<filesystem>`` should be provided. This means that vendors building
159+
with ``LIBCXX_ENABLE_FILESYSTEM=OFF`` will now also get ``<fstream>`` excluded from their configuration
160+
of the library.
161+
162+
- ``LIBCXX_ENABLE_FSTREAM`` is not supported anymore, please use ``LIBCXX_ENABLE_FILESYSTEM=OFF`` if your
163+
platform does not have support for a filesystem.

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ set(files
990990
wctype.h
991991
)
992992

993-
foreach(feature LIBCXX_ENABLE_FILESYSTEM LIBCXX_ENABLE_LOCALIZATION LIBCXX_ENABLE_FSTREAM LIBCXX_ENABLE_THREADS LIBCXX_ENABLE_WIDE_CHARACTERS)
993+
foreach(feature LIBCXX_ENABLE_FILESYSTEM LIBCXX_ENABLE_LOCALIZATION LIBCXX_ENABLE_THREADS LIBCXX_ENABLE_WIDE_CHARACTERS)
994994
if (NOT ${${feature}})
995995
set(requires_${feature} "requires LIBCXX_CONFIGURED_WITHOUT_SUPPORT_FOR_THIS_HEADER")
996996
endif()

libcxx/include/__config_site.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
#cmakedefine _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
2525
#cmakedefine _LIBCPP_NO_VCRUNTIME
2626
#cmakedefine _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION @_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION@
27-
#cmakedefine _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY
27+
#cmakedefine _LIBCPP_HAS_NO_FILESYSTEM
2828
#cmakedefine _LIBCPP_HAS_NO_RANDOM_DEVICE
2929
#cmakedefine _LIBCPP_HAS_NO_LOCALIZATION
30-
#cmakedefine _LIBCPP_HAS_NO_FSTREAM
3130
#cmakedefine _LIBCPP_HAS_NO_WIDE_CHARACTERS
3231
#cmakedefine01 _LIBCPP_ENABLE_ASSERTIONS_DEFAULT
3332
#cmakedefine _LIBCPP_ENABLE_DEBUG_MODE

libcxx/include/filesystem

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_direct
457457
// [fs.filesystem.syn]
458458
#include <compare>
459459

460-
#if defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
460+
#if defined(_LIBCPP_HAS_NO_FILESYSTEM)
461461
# error "The <filesystem> library is not supported since libc++ has been configured without support for a filesystem."
462462
#endif
463463

libcxx/include/fstream

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ typedef basic_fstream<wchar_t> wfstream;
194194
#include <typeinfo>
195195
#include <version>
196196

197-
#if !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
197+
#if !defined(_LIBCPP_HAS_NO_FILESYSTEM)
198198
# include <filesystem>
199199
#endif
200200

@@ -209,7 +209,7 @@ _LIBCPP_PUSH_MACROS
209209
# define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS
210210
#endif
211211

212-
#if !defined(_LIBCPP_HAS_NO_FSTREAM)
212+
#if !defined(_LIBCPP_HAS_NO_FILESYSTEM)
213213

214214
_LIBCPP_BEGIN_NAMESPACE_STD
215215

@@ -245,7 +245,7 @@ public:
245245
_LIBCPP_INLINE_VISIBILITY
246246
basic_filebuf* open(const string& __s, ios_base::openmode __mode);
247247

248-
#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
248+
#if _LIBCPP_STD_VER >= 17
249249
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
250250
basic_filebuf* open(const _VSTD_FS::path& __p, ios_base::openmode __mode) {
251251
return open(__p.c_str(), __mode);
@@ -1168,7 +1168,7 @@ public:
11681168
#endif
11691169
_LIBCPP_INLINE_VISIBILITY
11701170
explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in);
1171-
#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
1171+
#if _LIBCPP_STD_VER >= 17
11721172
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
11731173
explicit basic_ifstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in)
11741174
: basic_ifstream(__p.c_str(), __mode) {}
@@ -1189,7 +1189,7 @@ public:
11891189
void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
11901190
#endif
11911191
void open(const string& __s, ios_base::openmode __mode = ios_base::in);
1192-
#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
1192+
#if _LIBCPP_STD_VER >= 17
11931193
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
11941194
void open(const filesystem::path& __p,
11951195
ios_base::openmode __mode = ios_base::in) {
@@ -1369,7 +1369,7 @@ public:
13691369
_LIBCPP_INLINE_VISIBILITY
13701370
explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out);
13711371

1372-
#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
1372+
#if _LIBCPP_STD_VER >= 17
13731373
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
13741374
explicit basic_ofstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out)
13751375
: basic_ofstream(__p.c_str(), __mode) {}
@@ -1392,7 +1392,7 @@ public:
13921392
#endif
13931393
void open(const string& __s, ios_base::openmode __mode = ios_base::out);
13941394

1395-
#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
1395+
#if _LIBCPP_STD_VER >= 17
13961396
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
13971397
void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out)
13981398
{ return open(__p.c_str(), __mode); }
@@ -1570,7 +1570,7 @@ public:
15701570
_LIBCPP_INLINE_VISIBILITY
15711571
explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
15721572

1573-
#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
1573+
#if _LIBCPP_STD_VER >= 17
15741574
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
15751575
explicit basic_fstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in | ios_base::out)
15761576
: basic_fstream(__p.c_str(), __mode) {}
@@ -1595,7 +1595,7 @@ public:
15951595
#endif
15961596
_LIBCPP_HIDE_FROM_ABI void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
15971597

1598-
#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
1598+
#if _LIBCPP_STD_VER >= 17
15991599
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
16001600
void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in|ios_base::out)
16011601
{ return open(__p.c_str(), __mode); }
@@ -1745,7 +1745,7 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>;
17451745

17461746
_LIBCPP_END_NAMESPACE_STD
17471747

1748-
#endif // _LIBCPP_HAS_NO_FSTREAM
1748+
#endif // _LIBCPP_HAS_NO_FILESYSTEM
17491749

17501750
_LIBCPP_POP_MACROS
17511751

libcxx/include/module.modulemap.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ module std [system] {
976976
}
977977
module fstream {
978978
@requires_LIBCXX_ENABLE_LOCALIZATION@
979-
@requires_LIBCXX_ENABLE_FSTREAM@
979+
@requires_LIBCXX_ENABLE_FILESYSTEM@
980980
header "fstream"
981981
export *
982982
}

libcxx/src/ios.instantiations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringstream<char>
3737
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostringstream<char>;
3838
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istringstream<char>;
3939

40-
#ifndef _LIBCPP_HAS_NO_FSTREAM
40+
#ifndef _LIBCPP_HAS_NO_FILESYSTEM
4141
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ifstream<char>;
4242
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ofstream<char>;
4343
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_filebuf<char>;

libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_bidirectional_iterator.compile.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <array>
2222
#include <deque>
23-
#ifndef TEST_HAS_NO_FILESYSTEM_LIBRARY
23+
#ifndef TEST_HAS_NO_FILESYSTEM
2424
#include <filesystem>
2525
#endif
2626
#include <forward_list>
@@ -61,7 +61,7 @@ static_assert(std::__iterator_traits_detail::__cpp17_bidirectional_iterator<std:
6161
static_assert(std::__iterator_traits_detail::__cpp17_bidirectional_iterator<std::deque<int>::const_reverse_iterator>);
6262

6363
// <filesystem>
64-
#ifndef TEST_HAS_NO_FILESYSTEM_LIBRARY
64+
#ifndef TEST_HAS_NO_FILESYSTEM
6565
static_assert(!std::__iterator_traits_detail::__cpp17_bidirectional_iterator<std::filesystem::directory_iterator>);
6666
static_assert(!std::__iterator_traits_detail::__cpp17_bidirectional_iterator<std::filesystem::recursive_directory_iterator>);
6767
#endif

0 commit comments

Comments
 (0)