<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/164074>164074</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libcxx][CMake] `LIBCXX_ENABLE_FILESYSTEM=OFF` is not respected on Windows for freestanding runtimes build
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
moleium
</td>
</tr>
</table>
<pre>
When configuring a freestanding libcxx build on Windows using the runtimes build entrypoint, setting `-DLIBCXX_ENABLE_FILESYSTEM=OFF` does not prevent filesystem source files from being added to the build target. This results in a compilation failure, as these sources have dependencies (e.g, Unicode, wide characters) that are typically disabled in such a configuration.
This issue does not occur on Linux with an identical configruation.
## Environment
* OS: Windows 10 22H2
* Compiler: Clang 21.1.1 (From MSYS2 `clang64` toolchain)
* Build System: Ninja
* LLVM commit: `main` branch
## Reproduction
1. From the root of `llvm-project`, run the following CMake command:
```bash
cmake -G Ninja -S runtimes -B build-freestanding
-DLLVM_ENABLE_RUNTIMES=libcxx
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=install
-DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++
-DLIBCXX_ENABLE_SHARED=OFF
-DLIBCXX_ENABLE_STATIC=ON
-DLIBCXX_CXX_ABI=none
-DLIBCXX_ENABLE_EXCEPTIONS=OFF
-DLIBCXX_ENABLE_RTTI=OFF
-DLIBCXX_ENABLE_FILESYSTEM=OFF
-DLIBCXX_ENABLE_LOCALIZATION=OFF
-DLIBCXX_ENABLE_UNICODE=OFF
-DLIBCXX_ENABLE_WIDE_CHARACTERS=OFF
-DLIBCXX_ENABLE_THREADS=OFF
-DLIBCXX_ENABLE_MONOTONIC_CLOCK=OFF
-DLIBCXX_ENABLE_TIME_ZONE_DATABASE=OFF
-DLIBCXX_ENABLE_RANDOM_DEVICE=OFF
-DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=OFF
-DLIBCXX_INCLUDE_TESTS=OFF
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
-DLIBCXX_USE_COMPILER_RT=ON
```
2. Go to the build directoryt and run `ninja`:
```
cd build-freestanding
ninja
```
## Actual Behavior
The build fails with compilation errors in filesystem-related source files.
```
... llvm-project/build-freestanding/include/c++/v1/__filesystem/path.h:186:9: error: unknown type name 'wstring'; did you mean 'string'?
186 | typedef wstring __path_string;
| ^~~~~~~
| string
... llvm-project/build-freestanding/include/c++/v1/__fwd/string.h:45:7: note: 'string' declared here
45 | using string = basic_string<char>;
| ^
```
## Expected Behavior
The build should succeed. Source files from the `libcxx/src/filesystem` directory should not be part of the build when `LIBCXX_ENABLE_FILESYSTEM` is `OFF`.
## Speculation
Probable root cause is in `libcxx/src/CMakeLists.txt`. Filesystem source files (`filesystem_*.cpp`) are unconditionally added to the `LIBCXX_SOURCES` variable.
These files should be moved inside the guard for `LIBCXX_ENABLE_FILESYSTEM` block.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVktz4roS_jXKRhWXscGQBQvjx4lreKTAOZM5G5csNVhnjERJch6b-9tvSXYSmAlzN9dFiuButb5-f0RrfhAAczRZoEl6QzrTSDU_yhZ4d7ypJXubf29AYCrFnh86xcUBE7xXANoQwezPltf09RXXHW8ZlgJ_54LJF407baWmAaw6YfgR9KADwqi3k-TCoCDBGoyxiijyb9NlsUienqpsHS-WWZUXy2z3Y1dmKxSmmzxHkY-ZBI2FNPik4BmEwXvegn7TBo5Yy05R6N_gvZJHXIMDzBgwbKQD02MwRB3AeLhsuMYKdNcajbnABFN5PPGWGC4F3hPedgosTKLtaQ3DJRo35BkwgxMIBoJy0BgFM_AOVvlRcCqZO_fCGWDaEEWoAaVRcIexaYjBRAE2bydOSdu-YcY1qVtgFoPuaOOA9CF3UDzkx8iPHVyudQefgZCUdsoGfslF94pfuGkwEZgzEMZaHwyp7twQCkIUhDgTz1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