diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dc95f972877..217e54379dfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,11 @@ if(${VELOX_FORCE_COLORED_OUTPUT}) endif() endif() +if("${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/README.md b/README.md index b23e644f7ed2..9bc7a46e0fe7 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,22 @@ $ make Note that `setup-adapters.sh` supports MacOS and Ubuntu 20.04 or later. +### Using Clang on Linux + +Clang 15 can be additionally installed during the setup step for Ubuntu 22.04/24.04 +and CentOS 9 by setting the `USE_CLANG` environment variable prior to running the platform specific setup script. +```shell +$ export USE_CLANG=true +``` +This will install and use Clang 15 to build the dependencies instead of using the default GCC compiler. + +Once completed, and before running any `make` command, set the compiler to be used: +```shell +$ export CC=/usr/bin/clang-15 +$ export CXX=/usr/bin/clang++-15 +$ make +``` + ### Building Velox Run `make` in the root directory to compile the sources. For development, use diff --git a/scripts/setup-centos9.sh b/scripts/setup-centos9.sh index 3841f2568d2f..825d2d29e32a 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,18 @@ 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 + cd boost + if [[ ${USE_CLANG} != "false" ]]; then + ./bootstrap.sh --prefix=/usr/local --with-toolset="clang-15" + # Switch the compiler from the clang-15 toolset which doesn't exist (clang-15.jam) to + # clang of version 15 when toolset clang-15 is used. + # This reconciles the project-config.jam generation with what the b2 build system allows for customization. + sed -i 's/using clang-15/using clang : 15/g' project-config.jam + ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi toolset=clang-15 --without-python + else + ./bootstrap.sh --prefix=/usr/local + ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi --without-python + fi ) } @@ -215,9 +231,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 +251,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..e40bba1d9923 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,19 @@ 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 "Warning: using the Clang configuration is for Ubuntu 22.04 and 24.04. Errors might occur." + fi + CLANG_PACKAGE_LIST=clang-15 + if [[ ${VERSION} =~ "22.04" ]]; then + CLANG_PACKAGE_LIST=${CLANG_PACKAGE_LIST} 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 +74,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 +118,18 @@ 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 + cd boost + if [[ ${USE_CLANG} != "false" ]]; then + ./bootstrap.sh --prefix=/usr/local --with-toolset="clang-15" + # Switch the compiler from the clang-15 toolset which doesn't exist (clang-15.jam) to + # clang of version 15 when toolset clang-15 is used. + # This reconciles the project-config.jam generation with what the b2 build system allows for customization. + sed -i 's/using clang-15/using clang : 15/g' project-config.jam + ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi toolset=clang-15 --without-python + else + ./bootstrap.sh --prefix=/usr/local + ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi --without-python + fi ) } @@ -218,6 +244,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 +262,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 )