From a4d918fa119c9beb712bf08bbb8fa9996aab0a71 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera Date: Fri, 13 Dec 2024 03:42:56 +0800 Subject: [PATCH] Replace `DEFAULT_SYSROOT` usage with Clang config files (#503) Upstream want to deprecate `DEFAULT_SYSROOT`[^1][^2][^3], but one blocker is wasi-sdk's usage of it. Let's try to help that along by switching to using config files[^4] instead. This should result in no user-facing changes in functionality. (If it does, then that's an LLVM bug that should be fixed there.) [^1]: https://reviews.llvm.org/D158218 [^2]: https://github.com/llvm/llvm-project/issues/94284 [^3]: https://github.com/llvm/llvm-project/pull/77537 [^4]: https://clang.llvm.org/docs/UsersManual.html#configuration-files --- clang.cfg | 1 + cmake/wasi-sdk-toolchain.cmake | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 clang.cfg diff --git a/clang.cfg b/clang.cfg new file mode 100644 index 0000000..38ddf54 --- /dev/null +++ b/clang.cfg @@ -0,0 +1 @@ +--sysroot=/../share/wasi-sysroot diff --git a/cmake/wasi-sdk-toolchain.cmake b/cmake/wasi-sdk-toolchain.cmake index 4c45abf..cba9c63 100644 --- a/cmake/wasi-sdk-toolchain.cmake +++ b/cmake/wasi-sdk-toolchain.cmake @@ -90,7 +90,6 @@ ExternalProject_Add(llvm-build -DLLVM_DEFAULT_TARGET_TRIPLE=wasm32-wasi -DLLVM_INSTALL_BINUTILS_SYMLINKS=TRUE -DLLVM_ENABLE_LIBXML2=OFF - -DDEFAULT_SYSROOT=../share/wasi-sysroot # Pass `-s` to strip symbols by default and shrink the size of the # distribution -DCMAKE_EXE_LINKER_FLAGS=-s @@ -159,6 +158,18 @@ copy_misc_file(wasi-sdk-p1.cmake cmake) copy_misc_file(wasi-sdk-p2.cmake cmake) copy_misc_file(cmake/Platform/WASI.cmake cmake/Platform) +function(copy_cfg_file compiler) + set(dst ${wasi_tmp_install}/bin/${compiler}.cfg) + add_custom_command( + OUTPUT ${dst} + COMMAND cmake -E copy ${CMAKE_CURRENT_SOURCE_DIR}/clang.cfg ${dst}) + add_custom_target(copy-${compiler} DEPENDS ${dst}) + add_dependencies(misc-files copy-${compiler}) +endfunction() + +copy_cfg_file(clang) +copy_cfg_file(clang++) + include(wasi-sdk-dist) # Figure out the name of the artifact which is either explicitly specified or