Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use llvm project #361

Merged
merged 14 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
submodules: recursive

- name: Prepare environment
run: bash .github/workflows/prepare-env.sh 14
run: bash .github/workflows/prepare-env.sh 17

- name: Generate Makefile
run: |
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/prepare-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ llvm_priority=300

sudo apt install -y ninja-build ccache

# install llvm
#wget https://apt.llvm.org/llvm.sh
#chmod 755 llvm.sh && sudo ./llvm.sh ${llvm_version} all
# Check if the desired LLVM version is already installed
if ! llvm-config-"${llvm_version}" --version &>/dev/null; then
sudo curl -sL https://apt.llvm.org/llvm.sh | sudo bash -s -- "${llvm_version}" all
else
echo "LLVM ${llvm_version} is already installed."
fi

# make clang as default compiler
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${llvm_version} ${llvm_priority}
sudo update-alternatives --install /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-${llvm_version} ${llvm_priority}
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${llvm_version} ${llvm_priority}
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${llvm_version} ${llvm_priority}
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-"${llvm_version}" ${llvm_priority}
sudo update-alternatives --install /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-"${llvm_version}" ${llvm_priority}
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-"${llvm_version}" ${llvm_priority}
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-"${llvm_version}" ${llvm_priority}

clang-${llvm_version} -v

Expand Down
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
[submodule "contrib/libxml2"]
path = contrib/libxml2
url = https://github.com/GNOME/libxml2.git
[submodule "contrib/libcxx"]
path = contrib/libcxx
url = https://github.com/ClickHouse-Extras/libcxx.git
[submodule "contrib/libcxxabi"]
path = contrib/libcxxabi
url = https://github.com/ClickHouse-Extras/libcxxabi.git
[submodule "contrib/libunwind"]
path = contrib/libunwind
url = https://github.com/ClickHouse-Extras/libunwind.git
Expand All @@ -43,3 +37,6 @@
[submodule "contrib/libc-headers"]
path = contrib/libc-headers
url = https://github.com/ClickHouse-Extras/libc-headers.git
[submodule "contrib/llvm-project"]
path = contrib/llvm-project
url = https://github.com/llvm/llvm-project.git
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ We really appreciate the excellent work of the ClickHouse and NuRaft teams.

### Build on Ubuntu

Requirement: Ubuntu 20.04+, Clang 13+(17 is recommended), Cmake 3.20+
Requirement: Ubuntu 20.04+, Clang 17+, Cmake 3.20+
```
# install tools
sudo apt-get install cmake llvm-17
Expand Down
7 changes: 6 additions & 1 deletion base/common/logger_useful.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace
template <typename T, typename... Ts> constexpr auto firstArg(T && x, Ts &&...) { return std::forward<T>(x); }
}

template<typename... Args>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems logFormat is meaningless.

std::string logFormat(const std::string& fmt, Args&&... args) {
std::string formatted_string = fmt::format(fmt::runtime(std::string_view(fmt.data(), fmt.size())), std::forward<Args>(args)...);
return formatted_string;
}

/// Logs a message to a specified logger with that level.
/// If more than one argument is provided,
Expand All @@ -24,7 +29,7 @@ namespace
{ \
if ((logger)->is((PRIORITY))) \
{ \
std::string formatted_message = numArgs(__VA_ARGS__) > 1 ? fmt::format(__VA_ARGS__) : firstArg(__VA_ARGS__); \
std::string formatted_message = numArgs(__VA_ARGS__) > 1 ? logFormat(__VA_ARGS__) : firstArg(__VA_ARGS__); \
if (auto channel = (logger)->getChannel()) \
{ \
std::string file_function; \
Expand Down
2 changes: 1 addition & 1 deletion base/readpassphrase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
add_library(readpassphrase readpassphrase.c)

set_target_properties(readpassphrase PROPERTIES LINKER_LANGUAGE C)
target_compile_options(readpassphrase PRIVATE -Wno-unused-result -Wno-reserved-id-macro -Wno-reserved-identifier -Wno-disabled-macro-expansion -Wno-sign-conversion)
target_compile_options(readpassphrase PRIVATE -Wno-unused-result -Wno-reserved-id-macro -Wno-reserved-identifier -Wno-disabled-macro-expansion -Wno-sign-conversion -Wno-switch-default)
target_include_directories(readpassphrase PUBLIC .)
1 change: 1 addition & 0 deletions cmake/darwin/default_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

include (cmake/find/unwind.cmake)
include (cmake/find/cxx.cmake)

add_library(global-group INTERFACE)
Expand Down
23 changes: 14 additions & 9 deletions cmake/find/cxx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ set(USE_INTERNAL_LIBCXX_LIBRARY_DEFAULT ON)
option (USE_INTERNAL_LIBCXX_LIBRARY "Disable to use system libcxx and libcxxabi libraries instead of bundled"
${USE_INTERNAL_LIBCXX_LIBRARY_DEFAULT})

if(NOT EXISTS "${RaftKeeper_SOURCE_DIR}/contrib/libcxx/CMakeLists.txt")
if(NOT EXISTS "${RaftKeeper_SOURCE_DIR}/contrib/llvm-project/libcxx")
if (USE_INTERNAL_LIBCXX_LIBRARY)
message(WARNING "submodule contrib/libcxx is missing. to fix try run: \n git submodule update --init --recursive")
message(WARNING "submodule contrib/llvm-project is missing. to fix try run: \n git submodule update --init --recursive")
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find internal libcxx")
set(USE_INTERNAL_LIBCXX_LIBRARY 0)
endif()
Expand All @@ -29,7 +29,6 @@ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG=0") # More

if (NOT USE_INTERNAL_LIBCXX_LIBRARY)
find_library (LIBCXX_LIBRARY c++)
find_library (LIBCXXFS_LIBRARY c++fs)
find_library (LIBCXXABI_LIBRARY c++abi)

if(LIBCXX_LIBRARY AND LIBCXXABI_LIBRARY) # c++fs is now a part of the libc++
Expand All @@ -38,16 +37,23 @@ if (NOT USE_INTERNAL_LIBCXX_LIBRARY)
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find system libcxx")
endif()

if(NOT LIBCXXFS_LIBRARY)
set(LIBCXXFS_LIBRARY ${LIBCXX_LIBRARY})
endif()

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")

target_link_libraries(global-libs INTERFACE ${EXCEPTION_HANDLING_LIBRARY})
endif ()

if (NOT HAVE_LIBCXX AND NOT MISSING_INTERNAL_LIBCXX_LIBRARY)
set(LIBCXX_SOURCE_DIR "${RaftKeeper_SOURCE_DIR}/contrib/llvm-project/libcxx")

set(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS ON)
set(_LIBCPP_PSTL_CPU_BACKEND_SERIAL ON)
set(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION ON)

configure_file("${LIBCXX_SOURCE_DIR}/include/__config_site.in" "${CMAKE_CURRENT_BINARY_DIR}/include/__config_site" @ONLY)
set(CONFIG_SITE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
message("CONFIG_SITE_DIR ${CONFIG_SITE_DIR}")
include_directories(${CONFIG_SITE_DIR})

set (LIBCXX_LIBRARY cxx)
set (LIBCXXABI_LIBRARY cxxabi)
add_subdirectory(contrib/libcxxabi-cmake)
Expand All @@ -60,10 +66,9 @@ if (NOT HAVE_LIBCXX AND NOT MISSING_INTERNAL_LIBCXX_LIBRARY)
endif ()

if (HAVE_LIBCXX)
target_link_libraries(global-libs INTERFACE ${LIBCXX_LIBRARY} ${LIBCXXABI_LIBRARY} ${LIBCXXFS_LIBRARY})
target_link_libraries(global-libs INTERFACE ${LIBCXX_LIBRARY} ${LIBCXXABI_LIBRARY})

message (STATUS "Using libcxx: ${LIBCXX_LIBRARY}")
message (STATUS "Using libcxxfs: ${LIBCXXFS_LIBRARY}")
message (STATUS "Using libcxxabi: ${LIBCXXABI_LIBRARY}")
else()
target_link_libraries(global-libs INTERFACE -l:libstdc++.a -l:libstdc++fs.a) # Always link these libraries as static
Expand Down
2 changes: 1 addition & 1 deletion cmake/tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif ()

if (COMPILER_CLANG)
set (CLANG_MINIMUM_VERSION 13)
set (CLANG_MINIMUM_VERSION 17)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${CLANG_MINIMUM_VERSION})
message (FATAL_ERROR "Clang version must be at least ${CLANG_MINIMUM_VERSION}.")
endif ()
Expand Down
1 change: 1 addition & 0 deletions contrib/boost-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ if (NOT EXTERNAL_BOOST_FOUND)
)

add_library (_boost_program_options ${SRCS_PROGRAM_OPTIONS})
target_compile_definitions (_boost_program_options PUBLIC BOOST_NO_CXX98_FUNCTION_BASE=1)
add_library (boost::program_options ALIAS _boost_program_options)
target_include_directories (_boost_program_options SYSTEM BEFORE PUBLIC ${LIBRARY_DIR})

Expand Down
2 changes: 1 addition & 1 deletion contrib/fmtlib
Submodule fmtlib updated 247 files
3 changes: 1 addition & 2 deletions contrib/fmtlib-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set (SRCS
../fmtlib/src/fmt.cc
../fmtlib/src/format.cc
../fmtlib/src/os.cc

Expand All @@ -8,10 +9,8 @@ set (SRCS
../fmtlib/include/fmt/core.h
../fmtlib/include/fmt/format.h
../fmtlib/include/fmt/format-inl.h
../fmtlib/include/fmt/locale.h
../fmtlib/include/fmt/os.h
../fmtlib/include/fmt/ostream.h
../fmtlib/include/fmt/posix.h
../fmtlib/include/fmt/printf.h
../fmtlib/include/fmt/ranges.h
)
Expand Down
1 change: 0 additions & 1 deletion contrib/libcxx
Submodule libcxx deleted from 9a457a
122 changes: 56 additions & 66 deletions contrib/libcxx-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,79 +1,74 @@
include(CheckCXXCompilerFlag)

set(LIBCXX_SOURCE_DIR ${RaftKeeper_SOURCE_DIR}/contrib/libcxx)
set(LIBCXX_SOURCE_DIR "${RaftKeeper_SOURCE_DIR}/contrib/llvm-project/libcxx")
message("${RaftKeeper_SOURCE_DIR}/contrib/llvm-project/libcxx")

set(SRCS
"${LIBCXX_SOURCE_DIR}/src/algorithm.cpp"
"${LIBCXX_SOURCE_DIR}/src/any.cpp"
"${LIBCXX_SOURCE_DIR}/src/atomic.cpp"
"${LIBCXX_SOURCE_DIR}/src/barrier.cpp"
"${LIBCXX_SOURCE_DIR}/src/bind.cpp"
"${LIBCXX_SOURCE_DIR}/src/charconv.cpp"
"${LIBCXX_SOURCE_DIR}/src/chrono.cpp"
"${LIBCXX_SOURCE_DIR}/src/condition_variable.cpp"
"${LIBCXX_SOURCE_DIR}/src/condition_variable_destructor.cpp"
"${LIBCXX_SOURCE_DIR}/src/debug.cpp"
"${LIBCXX_SOURCE_DIR}/src/exception.cpp"
"${LIBCXX_SOURCE_DIR}/src/experimental/memory_resource.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/directory_iterator.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/int128_builtins.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/operations.cpp"
"${LIBCXX_SOURCE_DIR}/src/format.cpp"
"${LIBCXX_SOURCE_DIR}/src/functional.cpp"
"${LIBCXX_SOURCE_DIR}/src/future.cpp"
"${LIBCXX_SOURCE_DIR}/src/hash.cpp"
"${LIBCXX_SOURCE_DIR}/src/ios.cpp"
"${LIBCXX_SOURCE_DIR}/src/ios.instantiations.cpp"
"${LIBCXX_SOURCE_DIR}/src/iostream.cpp"
"${LIBCXX_SOURCE_DIR}/src/legacy_debug_handler.cpp"
"${LIBCXX_SOURCE_DIR}/src/legacy_pointer_safety.cpp"
"${LIBCXX_SOURCE_DIR}/src/locale.cpp"
"${LIBCXX_SOURCE_DIR}/src/memory.cpp"
"${LIBCXX_SOURCE_DIR}/src/mutex.cpp"
"${LIBCXX_SOURCE_DIR}/src/mutex_destructor.cpp"
"${LIBCXX_SOURCE_DIR}/src/new.cpp"
"${LIBCXX_SOURCE_DIR}/src/optional.cpp"
"${LIBCXX_SOURCE_DIR}/src/random.cpp"
"${LIBCXX_SOURCE_DIR}/src/random_shuffle.cpp"
"${LIBCXX_SOURCE_DIR}/src/regex.cpp"
"${LIBCXX_SOURCE_DIR}/src/ryu/d2fixed.cpp"
"${LIBCXX_SOURCE_DIR}/src/ryu/d2s.cpp"
"${LIBCXX_SOURCE_DIR}/src/ryu/f2s.cpp"
"${LIBCXX_SOURCE_DIR}/src/shared_mutex.cpp"
"${LIBCXX_SOURCE_DIR}/src/stdexcept.cpp"
"${LIBCXX_SOURCE_DIR}/src/string.cpp"
"${LIBCXX_SOURCE_DIR}/src/strstream.cpp"
"${LIBCXX_SOURCE_DIR}/src/system_error.cpp"
"${LIBCXX_SOURCE_DIR}/src/thread.cpp"
"${LIBCXX_SOURCE_DIR}/src/typeinfo.cpp"
"${LIBCXX_SOURCE_DIR}/src/utility.cpp"
"${LIBCXX_SOURCE_DIR}/src/valarray.cpp"
"${LIBCXX_SOURCE_DIR}/src/variant.cpp"
"${LIBCXX_SOURCE_DIR}/src/vector.cpp"
"${LIBCXX_SOURCE_DIR}/src/verbose_abort.cpp"
"${LIBCXX_SOURCE_DIR}/src/algorithm.cpp"
"${LIBCXX_SOURCE_DIR}/src/any.cpp"
"${LIBCXX_SOURCE_DIR}/src/atomic.cpp"
"${LIBCXX_SOURCE_DIR}/src/barrier.cpp"
"${LIBCXX_SOURCE_DIR}/src/bind.cpp"
"${LIBCXX_SOURCE_DIR}/src/charconv.cpp"
"${LIBCXX_SOURCE_DIR}/src/chrono.cpp"
"${LIBCXX_SOURCE_DIR}/src/condition_variable.cpp"
"${LIBCXX_SOURCE_DIR}/src/condition_variable_destructor.cpp"
# "${LIBCXX_SOURCE_DIR}/src/debug.cpp"
"${LIBCXX_SOURCE_DIR}/src/exception.cpp"
"${LIBCXX_SOURCE_DIR}/src/experimental/memory_resource.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/directory_iterator.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/int128_builtins.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/operations.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/path.cpp"
"${LIBCXX_SOURCE_DIR}/src/filesystem/filesystem_error.cpp"
# "${LIBCXX_SOURCE_DIR}/src/format.cpp"
"${LIBCXX_SOURCE_DIR}/src/functional.cpp"
"${LIBCXX_SOURCE_DIR}/src/future.cpp"
"${LIBCXX_SOURCE_DIR}/src/hash.cpp"
"${LIBCXX_SOURCE_DIR}/src/ios.cpp"
"${LIBCXX_SOURCE_DIR}/src/ios.instantiations.cpp"
"${LIBCXX_SOURCE_DIR}/src/iostream.cpp"
"${LIBCXX_SOURCE_DIR}/src/legacy_debug_handler.cpp"
"${LIBCXX_SOURCE_DIR}/src/legacy_pointer_safety.cpp"
"${LIBCXX_SOURCE_DIR}/src/locale.cpp"
"${LIBCXX_SOURCE_DIR}/src/memory.cpp"
"${LIBCXX_SOURCE_DIR}/src/mutex.cpp"
"${LIBCXX_SOURCE_DIR}/src/mutex_destructor.cpp"
"${LIBCXX_SOURCE_DIR}/src/new.cpp"
"${LIBCXX_SOURCE_DIR}/src/optional.cpp"
"${LIBCXX_SOURCE_DIR}/src/random.cpp"
"${LIBCXX_SOURCE_DIR}/src/random_shuffle.cpp"
"${LIBCXX_SOURCE_DIR}/src/ryu/d2fixed.cpp"
"${LIBCXX_SOURCE_DIR}/src/ryu/d2s.cpp"
"${LIBCXX_SOURCE_DIR}/src/ryu/f2s.cpp"
"${LIBCXX_SOURCE_DIR}/src/shared_mutex.cpp"
"${LIBCXX_SOURCE_DIR}/src/stdexcept.cpp"
"${LIBCXX_SOURCE_DIR}/src/string.cpp"
"${LIBCXX_SOURCE_DIR}/src/strstream.cpp"
"${LIBCXX_SOURCE_DIR}/src/system_error.cpp"
"${LIBCXX_SOURCE_DIR}/src/thread.cpp"
"${LIBCXX_SOURCE_DIR}/src/typeinfo.cpp"
# "${LIBCXX_SOURCE_DIR}/src/utility.cpp"
"${LIBCXX_SOURCE_DIR}/src/valarray.cpp"
"${LIBCXX_SOURCE_DIR}/src/variant.cpp"
"${LIBCXX_SOURCE_DIR}/src/vector.cpp"
"${LIBCXX_SOURCE_DIR}/src/verbose_abort.cpp"
"${LIBCXX_SOURCE_DIR}/src/stdexcept.cpp"
"${LIBCXX_SOURCE_DIR}/src/new_helpers.cpp"
)

add_library(cxx ${SRCS})
set_target_properties(cxx PROPERTIES FOLDER "contrib/libcxx-cmake")

target_include_directories(cxx SYSTEM BEFORE PRIVATE $<BUILD_INTERFACE:${LIBCXX_SOURCE_DIR}/src>)
target_include_directories(cxx SYSTEM BEFORE PUBLIC $<BUILD_INTERFACE:${LIBCXX_SOURCE_DIR}/include>)
target_include_directories(cxx SYSTEM BEFORE PUBLIC $<$<COMPILE_LANGUAGE:CXX>:$<BUILD_INTERFACE:${LIBCXX_SOURCE_DIR}/include>>)
target_compile_definitions(cxx PRIVATE -D_LIBCPP_BUILDING_LIBRARY -DLIBCXX_BUILDING_LIBCXXABI)

# Enable capturing stack traces for all exceptions.
if (USE_UNWIND)
target_compile_definitions(cxx PUBLIC -DSTD_EXCEPTION_HAS_STACK_TRACE=1)
endif ()
#target_compile_definitions(cxx PUBLIC -DSTD_EXCEPTION_HAS_STACK_TRACE=0)

if (USE_MUSL)
target_compile_definitions(cxx PUBLIC -D_LIBCPP_HAS_MUSL_LIBC=1)
endif ()

# Override the deduced attribute support that causes error.
if (OS_DARWIN AND COMPILER_GCC)
add_compile_definitions(_LIBCPP_INIT_PRIORITY_MAX)
endif ()

target_compile_options(cxx PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)

# Third party library may have substandard code.
Expand All @@ -84,15 +79,10 @@ target_compile_definitions(cxx PUBLIC -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS

target_link_libraries(cxx PUBLIC cxxabi)

# For __udivmodti4, __divmodti4.
if (OS_DARWIN AND COMPILER_GCC)
target_link_libraries(cxx PRIVATE gcc)
endif ()

install(
TARGETS cxx
EXPORT global
ARCHIVE DESTINATION lib
RUNTIME DESTINATION lib
LIBRARY DESTINATION lib
)
)
1 change: 0 additions & 1 deletion contrib/libcxxabi
Submodule libcxxabi deleted from 65ba93
Loading
Loading