From 06e4e1521ffb0efb4e0ff6e1058755438afd3a0a Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Thu, 18 Nov 2021 17:16:10 +0000 Subject: [PATCH] Using -DCMAKE_SYSROOT to pass wasi-sysroot properly under msys2 bash With the following building commands: ``` call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64 set MSYS2_PATH_TYPE=inherit set MSYSTEM=MINGW32 set CC=cl set CXX=cl set "HOME=%CD%" bash.exe --login -c "make package" bash.exe --login -c "make check" cmd /k ``` Fixes following error: c:\wasi-sdk\bin\clang++.exe --target=wasm32-wasi -DNDEBUG -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Iinclude/c++build -fdebug-prefix-map=C:\work\wasi-sdk=wasisdk;\v13.5g73d30af917c4 --sysroot=c;C:\CI-Tools\msys64\wasi-sdk\share\wasi-sysroot -fPIC -DLIBCXX_BUILDING_LIBCXXABI -IC:/work/wasi-sdk/build/libcxx/include/c++/v1 -std=c++20 -MD -MT src/CMakeFiles/cxx_static.dir/regex.cpp.obj -MF src\CMakeFiles\cxx_static.dir\regex.cpp.obj.d -o src/CMakeFiles/cxx_static.dir/regex.cpp.obj -c C:/work/wasi-sdk/src/llvm-project/libcxx/src/regex.cpp In file included from C:/work/wasi-sdk/src/llvm-project/libcxx/src/regex.cpp:9: In file included from C:/work/wasi-sdk/build/libcxx/include/c++/v1\regex:766: In file included from C:/work/wasi-sdk/build/libcxx/include/c++/v1\__debug:14: In file included from C:/work/wasi-sdk/build/libcxx/include/c++/v1\iosfwd:98: C:/work/wasi-sdk/build/libcxx/include/c++/v1\wchar.h:119:15: fatal error: 'wchar.h' file not found #include_next ^~~~~~~~~ --- Makefile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 89eee63..426df1d 100644 --- a/Makefile +++ b/Makefile @@ -99,6 +99,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT build/wasi-libc.BUILT # Do the build, and install it. mkdir -p build/compiler-rt cd build/compiler-rt && cmake -G Ninja \ + -DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \ -DCMAKE_C_COMPILER_WORKS=ON \ -DCMAKE_CXX_COMPILER_WORKS=ON \ -DCMAKE_AR=$(BUILD_PREFIX)/bin/ar \ @@ -112,7 +113,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT build/wasi-libc.BUILT -DCOMPILER_RT_ENABLE_IOS=OFF \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=On \ -DWASI_SDK_PREFIX=$(BUILD_PREFIX) \ - -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ + -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ -DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \ -DCOMPILER_RT_OS_DIR=wasi \ -DCMAKE_INSTALL_PREFIX=$(PREFIX)/lib/clang/$(CLANG_VERSION)/ \ @@ -154,10 +155,11 @@ build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUI # Do the build. mkdir -p build/libcxx cd build/libcxx && cmake -G Ninja $(LIBCXX_CMAKE_FLAGS) \ - -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ - -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ - -DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ - $(LLVM_PROJ_DIR)/libcxx + -DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \ + -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) \ + -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) \ + -DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ + $(LLVM_PROJ_DIR)/libcxx ninja $(NINJA_FLAGS) -v -C build/libcxx # Do the install. DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -v -C build/libcxx install @@ -195,10 +197,11 @@ build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT # Do the build. mkdir -p build/libcxxabi cd build/libcxxabi && cmake -G Ninja $(LIBCXXABI_CMAKE_FLAGS) \ - -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ - -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ - -DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ - $(LLVM_PROJ_DIR)/libcxxabi + -DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \ + -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) \ + -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) \ + -DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ + $(LLVM_PROJ_DIR)/libcxxabi ninja $(NINJA_FLAGS) -v -C build/libcxxabi # Do the install. DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -v -C build/libcxxabi install