llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.11k forks source link

libc++ build failure for wasm32-wasi #63588

Open TerrorJack opened 1 year ago

TerrorJack commented 1 year ago

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 --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.

llvmbot commented 1 year ago

@llvm/issue-subscribers-backend-webassembly