<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63588>63588</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            libc++ build failure for wasm32-wasi
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          TerrorJack
      </td>
    </tr>
</table>

<pre>
    When doing a wasi-sdk build using latest `master` branch of llvm since https://github.com/llvm/llvm-project/commit/c352fa7407122ee62d990d6b82551650149f98d4, libc++ build fails with something like:

```
FAILED: libcxx/src/CMakeFiles/cxx_static.dir/filesystem/filesystem_clock.cpp.o 
/workspace/wasi-sdk/build/install/opt/wasi-sdk/bin/clang++ --target=wasm32-wasi --sysroot=/workspace/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot -DLIBCXX_BUILDING_LIBCXXABI -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/workspace/wasi-sdk/src/llvm-project/libcxx/src -I/workspace/wasi-sdk/build/libcxx/include/c++/v1 -I/workspace/wasi-sdk/src/llvm-project/libcxxabi/include -fdebug-prefix-map=/workspace/wasi-sdk=wasisdk://v17  -Oz -fno-exceptions -fno-strict-aliasing -msimd128 -mnontrapping-fptoint -msign-ext -mbulk-memory -mmutable-globals -mmultivalue -mreference-types -fno-exceptions -fno-strict-aliasing -msimd128 -mnontrapping-fptoint -msign-ext -mbulk-memory -mmutable-globals -mmultivalue -mreference-types -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -faligned-allocation -nostdinc++ -fvisibility-inlines-hidden -fvisibility=hidden -Wall -Wextra -Wnewline-eof -Wshadow -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wundef -Wunused-template -Wformat-nonliteral -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -fno-exceptions -std=c++20 -MD -MT libcxx/src/CMakeFiles/cxx_static.dir/filesystem/filesystem_clock.cpp.o -MF libcxx/src/CMakeFiles/cxx_static.dir/filesystem/filesystem_clock.cpp.o.d -o libcxx/src/CMakeFiles/cxx_static.dir/filesystem/filesystem_clock.cpp.o -c /workspace/wasi-sdk/src/llvm-project/libcxx/src/filesystem/filesystem_clock.cpp
In file included from /workspace/wasi-sdk/src/llvm-project/libcxx/src/filesystem/filesystem_clock.cpp:14:
/workspace/wasi-sdk/src/llvm-project/libcxx/src/filesystem/posix_compat.h:42:11: fatal error: 'sys/statvfs.h' file not found
   42 | # include <sys/statvfs.h>
      |           ^~~~~~~~~~~~~~~
1 error generated.
```

The solution is pretty simple: partially revert a small fraction of that commit:

```diff
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index f782d85d61a8..76fe6f83b5ed 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -12,7 +12,6 @@ set(LIBCXX_SOURCES
 condition_variable.cpp
   condition_variable_destructor.cpp
 exception.cpp
-  filesystem/filesystem_clock.cpp
 filesystem/filesystem_error.cpp
   filesystem/path_parser.h
 filesystem/path.cpp
@@ -117,6 +116,7 @@ if (LIBCXX_ENABLE_FILESYSTEM)
 filesystem/directory_entry.cpp
 filesystem/directory_iterator.cpp
     filesystem/file_descriptor.h
+ filesystem/filesystem_clock.cpp
     filesystem/operations.cpp
 filesystem/posix_compat.h
     filesystem/time_utils.h
```

Just putting the patch here in case someone else gets bitten by the same issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWEtv4zjy_zTMpUBDpvw8-OBnjwd5NGL3ZOYk0GJJ4j8UqT9JOfYc9rMvKDmxO-309O70ABsENlXPH6uKxZK5czLXiBPSn5H-4obXvjB2skVrjf2Vp883OyOOk6cCNQgjdQ4cXriT1Iln2NVSCahdICvu0Xkgg6jkzqMlgwh2luu0AJOBUvsSnNQpQuF95Ug8JWxF2CqXvqh3ndSUhK2C1OmLVtb8H6aesFVqylI2i7jPMj7sRcMuY4gDJsbjSAx2I9bvdwf9qNsbZ-OR6BE2ByV3KWEzwmYnlBmXysGL9AU4U6IvGtDyGQOUaEGi189BdPpvHlfT9e1yQeJpY_FwIGzlbErYan7Hn3ElFbqA7HBInOdeph0hLWGrLDCOzmP51UOSKpM-d9Kq6hg4-WOrF2OfXcVTDOtTbAlbNbgJW0ntPFeKsJWp_DsRqYN3xXV-2iylntscPYkXL9yVMaNBHCh1R2eNCfS_5dEV3J61WptAF7fr2fz335PZl_XtYn3_KWmfp7M10EWyWt8uk4fVarPcJrP1dkPixaAXGLfTx0_Lhrt5-PI4Xza09Wz--fNXlh6nj39csH6ZbpL7h-Tz4_TT3TTZ_LHZLu-SX5bTxfLxQupxeffw2zLZPk7vN-vt-rdlsr6f335ZLDdBKNlsF_Nk_nC_2U7vt8nddP74cMFYPTzeTb8l367v1mfq-uNAtiXyro4vC-i72q9peFOQOlW1CFKnmiZste_-twj4Tp5tAs0E7uqcVhYzeaAlr75TIk1RyWZ1Or_77hCAPvwJNNOG4iHFykujXfvsvJWpp1xJ3jQJWjpZii4bAS210d7yqpI6p1nljdS-4eea4iEsd7V6piWWxh6BlmXt-U4hzZXZceUaivJyz1WNQEuLGVrUKVJ_rND978HZSyd3Ukl_pF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