From baea4091202e38a905b71e1e1053e39c5a8b9e81 Mon Sep 17 00:00:00 2001 From: Christian Zentgraf Date: Mon, 5 Aug 2024 15:24:34 -0700 Subject: [PATCH] Changes to compile with Clang15 --- CMakeLists.txt | 6 +++++ scripts/setup-centos9.sh | 55 ++++++++++++++++++++++++++++++---------- scripts/setup-ubuntu.sh | 43 ++++++++++++++++++++++++++----- 3 files changed, 84 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dc95f972877..24001b916d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,12 @@ if(${VELOX_FORCE_COLORED_OUTPUT}) endif() endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" + AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" + AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL 15) + set(CMAKE_EXE_LINKER_FLAGS "-latomic") +endif() + # At the moment we prefer static linking but by default cmake looks for shared # libs first. This will still fallback to shared libs when static ones are not # found diff --git a/scripts/setup-centos9.sh b/scripts/setup-centos9.sh index 3841f2568d2f..31b6c33a8e72 100755 --- a/scripts/setup-centos9.sh +++ b/scripts/setup-centos9.sh @@ -31,13 +31,11 @@ set -efx -o pipefail SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") source $SCRIPTDIR/setup-helper-functions.sh NPROC=$(getconf _NPROCESSORS_ONLN) -export CFLAGS=$(get_cxx_flags) # Used by LZO. -export CXXFLAGS=$CFLAGS # Used by boost. -export CPPFLAGS=$CFLAGS # Used by LZO. +export CXXFLAGS=$(get_cxx_flags) # Used by boost. +export CFLAGS=${CXXFLAGS//"-std=c++17"/} # Used by LZO. CMAKE_BUILD_TYPE="${BUILD_TYPE:-Release}" BUILD_DUCKDB="${BUILD_DUCKDB:-true}" -export CC=/opt/rh/gcc-toolset-12/root/bin/gcc -export CXX=/opt/rh/gcc-toolset-12/root/bin/g++ +USE_CLANG="${USE_CLANG:-false}" FB_OS_VERSION="v2024.05.20.00" FMT_VERSION="10.1.1" @@ -48,6 +46,10 @@ function dnf_install { dnf install -y -q --setopt=install_weak_deps=False "$@" } +function install_clang15 { + dnf_install clang15 gcc-toolset-13-libatomic-devel +} + # Install packages required for build. function install_build_prerequisites { dnf update -y @@ -56,7 +58,12 @@ function install_build_prerequisites { dnf update -y dnf_install ninja-build cmake ccache gcc-toolset-12 git wget which dnf_install autoconf automake python3-devel pip libtool + pip install cmake==3.28.3 + + if [[ ${USE_CLANG} != "false" ]]; then + install_clang15 + fi } # Install dependencies from the package managers. @@ -99,9 +106,13 @@ function install_lzo { function install_boost { wget_and_untar https://github.com/boostorg/boost/releases/download/${BOOST_VERSION}/${BOOST_VERSION}.tar.gz boost ( - cd boost - ./bootstrap.sh --prefix=/usr/local - ./b2 "-j$(nproc)" -d0 install threading=multi --without-python + # Note, this will use the guessed toolset. If both gcc and clang-15 are present it will pick gcc. + # There is no easy way to use clang++-15 if it doesn't exist as clang++. + # Therefore, in order to use clang-15, one needs to install it as an alternative, set it as the default, and then + # select the --with-toolset=clang for boostrap script and toolset=clang for the b2 script. + cd boost + ./bootstrap.sh --prefix=/usr/local + ./b2 "-j$(nproc)" -d0 install threading=multi --without-python ) } @@ -215,9 +226,15 @@ function install_velox_deps { ( if [[ $# -ne 0 ]]; then - # Activate gcc12; enable errors on unset variables afterwards. - source /opt/rh/gcc-toolset-12/enable || exit 1 - set -u + if [[ ${USE_CLANG} != "false" ]]; then + export CC=/usr/bin/clang-15 + export CXX=/usr/bin/clang++-15 + else + # Activate gcc12; enable errors on unset variables afterwards. + source /opt/rh/gcc-toolset-12/enable || exit 1 + set -u + fi + for cmd in "$@"; do run_and_time "${cmd}" done @@ -229,11 +246,21 @@ function install_velox_deps { else echo "Skipping installation of build dependencies since INSTALL_PREREQUISITES is not set" fi - # Activate gcc12; enable errors on unset variables afterwards. - source /opt/rh/gcc-toolset-12/enable || exit 1 - set -u + if [[ ${USE_CLANG} != "false" ]]; then + export CC=/usr/bin/clang-15 + export CXX=/usr/bin/clang++-15 + else + # Activate gcc12; enable errors on unset variables afterwards. + source /opt/rh/gcc-toolset-12/enable || exit 1 + set -u + fi install_velox_deps echo "All dependencies for Velox installed!" + if [[ ${USE_CLANG} != "false" ]]; then + echo "To use clang for the Velox build set the CC and CXX environment variables in your session." + echo " export CC=/usr/bin/clang-15" + echo " export CXX=/usr/bin/clang++-15" + fi dnf clean all fi ) diff --git a/scripts/setup-ubuntu.sh b/scripts/setup-ubuntu.sh index 2529716ddd56..6d0a9583abb6 100755 --- a/scripts/setup-ubuntu.sh +++ b/scripts/setup-ubuntu.sh @@ -25,7 +25,7 @@ # $ scripts/setup-ubuntu.sh install_googletest install_fmt # -# Minimal setup for Ubuntu 20.04. +# Minimal setup for Ubuntu 22.04. set -eufx -o pipefail SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") source $SCRIPTDIR/setup-helper-functions.sh @@ -39,6 +39,20 @@ DEPENDENCY_DIR=${DEPENDENCY_DIR:-$(pwd)} BUILD_DUCKDB="${BUILD_DUCKDB:-true}" export CMAKE_BUILD_TYPE=Release SUDO="${SUDO:-"sudo --preserve-env"}" +USE_CLANG="${USE_CLANG:-false}" + +function install_clang15 { + VERSION=`cat /etc/os-release | grep VERSION_ID` + if [[ ! ${VERSION} =~ "22.04" && ! ${VERSION} =~ "24.04" ]]; then + echo "The clang configuration is for Ubuntu 22.04 and 22.04. Unset USE_CLANG and redo the setup." + exit + fi + CLANG_PACKAGE_LIST=clang-15 + if [[ ${VERSION} =~ "22.04" ]]; then + CLANG_PACKAGE_LIST=clang-15 gcc-12 g++-12 libc++-12-dev + fi + ${SUDO} apt install ${CLANG_PACKAGE_LIST} -y +} FB_OS_VERSION="v2024.05.20.00" FMT_VERSION="10.1.1" @@ -61,8 +75,12 @@ function install_build_prerequisites { git \ wget - # Install to /usr/local to make it available to all users. - ${SUDO} pip3 install cmake==3.28.3 + # Install to /usr/local to make it available to all users. + ${SUDO} pip3 install cmake==3.28.3 + + if [[ ${USE_CLANG} != "false" ]]; then + install_clang15 + fi } # Install packages required for build. @@ -101,9 +119,13 @@ function install_fmt { function install_boost { wget_and_untar https://github.com/boostorg/boost/releases/download/${BOOST_VERSION}/${BOOST_VERSION}.tar.gz boost ( - cd boost - ./bootstrap.sh --prefix=/usr/local - ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi --without-python + # Note, this will use the guessed toolset. If both gcc and clang-15 are present it will pick gcc. + # There is no easy way to use clang++-15 if it doesn't exist as clang++. + # Therefore, in order to use clang-15, one needs to install it as an alternative, set it as the default, and then + # select the --with-toolset=clang for boostrap script and toolset=clang for the b2 script. + cd boost + ./bootstrap.sh --prefix=/usr/local + ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi --without-python ) } @@ -218,6 +240,10 @@ function install_apt_deps { (return 2> /dev/null) && return # If script was sourced, don't run commands. ( + if [[ ${USE_CLANG} != "false" ]]; then + export CC=/usr/bin/clang-15 + export CXX=/usr/bin/clang++-15 + fi if [[ $# -ne 0 ]]; then for cmd in "$@"; do run_and_time "${cmd}" @@ -232,6 +258,11 @@ function install_apt_deps { fi install_velox_deps echo "All dependencies for Velox installed!" + if [[ ${USE_CLANG} != "false" ]]; then + echo "To use clang for the Velox build set the CC and CXX environment variables in your session." + echo " export CC=/usr/bin/clang-15" + echo " export CXX=/usr/bin/clang++-15" + fi fi )