Skip to content

Commit 5d9aaae

Browse files
committed
[libcxx] Fix freestanding build failure with filesystem disabled on Windows
Building libc++ for freestanding targets on Windows with LIBCXX_ENABLE_FILESYSTEM=OFF fails due to compilation errors. The root cause is twofold: 1. path.cpp and filesystem_error.cpp are compiled even when filesystem is disabled. These files depend on wide character and localization support, which freestanding builds typically don't provide. 2. print.cpp transitively depends on filesystem headers for Windows error reporting, pulling in <filesystem> even when the feature is disabled. This patch fixes both problems by: - Guarding filesystem sources in src/CMakeLists.txt with LIBCXX_ENABLE_FILESYSTEM - Making print.cpp call GetLastError() directly when filesystem support is unavailable Fixes #164074
1 parent 12bf183 commit 5d9aaae

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

libcxx/src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ set(LIBCXX_SOURCES
99
error_category.cpp
1010
exception.cpp
1111
expected.cpp
12-
filesystem/filesystem_clock.cpp
13-
filesystem/filesystem_error.cpp
1412
filesystem/path_parser.h
15-
filesystem/path.cpp
1613
functional.cpp
1714
hash.cpp
1815
include/apple_availability.h
@@ -117,6 +114,9 @@ endif()
117114

118115
if (LIBCXX_ENABLE_FILESYSTEM)
119116
list(APPEND LIBCXX_SOURCES
117+
filesystem/filesystem_clock.cpp
118+
filesystem/filesystem_error.cpp
119+
filesystem/path.cpp
120120
filesystem/directory_entry.cpp
121121
filesystem/directory_iterator.cpp
122122
filesystem/file_descriptor.h

libcxx/src/print.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
#include <__system_error/system_error.h>
1515

16-
#include "filesystem/error.h"
17-
1816
#if defined(_LIBCPP_WIN32API)
1917
# define WIN32_LEAN_AND_MEAN
2018
# define NOMINMAX
@@ -51,7 +49,11 @@ __write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wst
5149
__view.size(),
5250
nullptr,
5351
nullptr) == 0) {
52+
# if _LIBCPP_HAS_FILESYSTEM
5453
std::__throw_system_error(filesystem::detail::get_last_error(), "failed to write formatted output");
54+
# else
55+
std::__throw_system_error(error_code(GetLastError(), system_category()), "failed to write formatted output");
56+
# endif
5557
}
5658
}
5759
# endif // _LIBCPP_HAS_WIDE_CHARACTERS

0 commit comments

Comments
 (0)