diff --git a/CMake/ResolveDependency.cmake b/CMake/ResolveDependency.cmake index eba371fbcd60c..7998d9d050247 100644 --- a/CMake/ResolveDependency.cmake +++ b/CMake/ResolveDependency.cmake @@ -40,6 +40,8 @@ set(CMAKE_TLS_VERIFY true) macro(build_dependency dependency_name) string(TOLOWER ${dependency_name} dependency_name_lower) + set(CMAKE_COMPILER_SELECTION_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) include(${dependency_name_lower}) endmacro() diff --git a/CMake/resolve_dependency_modules/absl.cmake b/CMake/resolve_dependency_modules/absl.cmake index 11c267b688e80..d11be1b0ea033 100644 --- a/CMake/resolve_dependency_modules/absl.cmake +++ b/CMake/resolve_dependency_modules/absl.cmake @@ -28,7 +28,8 @@ FetchContent_Declare( absl URL ${VELOX_ABSL_SOURCE_URL} URL_HASH ${VELOX_ABSL_BUILD_SHA256_CHECKSUM} - OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL SYSTEM) + OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL SYSTEM CMAKE_ARGS + ${CMAKE_COMPILER_SELECTION_ARGS}) set(ABSL_BUILD_TESTING OFF) set(ABSL_PROPAGATE_CXX_STD ON) diff --git a/CMake/resolve_dependency_modules/arrow/CMakeLists.txt b/CMake/resolve_dependency_modules/arrow/CMakeLists.txt index 56b673e87a391..451d31296d96a 100644 --- a/CMake/resolve_dependency_modules/arrow/CMakeLists.txt +++ b/CMake/resolve_dependency_modules/arrow/CMakeLists.txt @@ -38,7 +38,8 @@ if(VELOX_ENABLE_ARROW) -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DARROW_BUILD_STATIC=ON -DThrift_SOURCE=${THRIFT_SOURCE} - -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}) + -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} + ${CMAKE_COMPILER_SELECTION_ARGS}) set(ARROW_LIBDIR ${ARROW_PREFIX}/install/${CMAKE_INSTALL_LIBDIR}) add_library(thrift STATIC IMPORTED GLOBAL) diff --git a/CMake/resolve_dependency_modules/boost/CMakeLists.txt b/CMake/resolve_dependency_modules/boost/CMakeLists.txt index c6d32b88c2b4d..84e9744269001 100644 --- a/CMake/resolve_dependency_modules/boost/CMakeLists.txt +++ b/CMake/resolve_dependency_modules/boost/CMakeLists.txt @@ -42,7 +42,8 @@ endif() FetchContent_Declare( Boost URL ${VELOX_BOOST_SOURCE_URL} - URL_HASH ${VELOX_BOOST_BUILD_SHA256_CHECKSUM}) + URL_HASH ${VELOX_BOOST_BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) # Configure the file before adding the header only libs configure_file(${CMAKE_CURRENT_LIST_DIR}/FindBoost.cmake.in diff --git a/CMake/resolve_dependency_modules/cpr.cmake b/CMake/resolve_dependency_modules/cpr.cmake index 45e0d16375a81..4fcb08c5b4e3f 100644 --- a/CMake/resolve_dependency_modules/cpr.cmake +++ b/CMake/resolve_dependency_modules/cpr.cmake @@ -26,7 +26,6 @@ set(curl_SOURCE BUNDLED) resolve_dependency(curl) resolve_dependency_url(CPR) - message(STATUS "Building cpr from source") FetchContent_Declare( cpr @@ -34,7 +33,8 @@ FetchContent_Declare( URL_HASH ${VELOX_CPR_BUILD_SHA256_CHECKSUM} PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/cpr/cpr-libcurl-compatible.patch && git - apply ${CMAKE_CURRENT_LIST_DIR}/cpr/cpr-remove-sancheck.patch) + apply ${CMAKE_CURRENT_LIST_DIR}/cpr/cpr-remove-sancheck.patch CMAKE_ARGS + ${CMAKE_COMPILER_SELECTION_ARGS}) set(BUILD_SHARED_LIBS OFF) set(CPR_USE_SYSTEM_CURL OFF) # ZLIB has already been found by find_package(ZLIB, REQUIRED), set CURL_ZLIB=OFF diff --git a/CMake/resolve_dependency_modules/duckdb.cmake b/CMake/resolve_dependency_modules/duckdb.cmake index f606ab48ef5b9..e030428242baf 100644 --- a/CMake/resolve_dependency_modules/duckdb.cmake +++ b/CMake/resolve_dependency_modules/duckdb.cmake @@ -34,7 +34,8 @@ FetchContent_Declare( PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/duckdb/remove-ccache.patch && git apply ${CMAKE_CURRENT_LIST_DIR}/duckdb/fix-duckdbversion.patch && git apply - ${CMAKE_CURRENT_LIST_DIR}/duckdb/re2.patch) + ${CMAKE_CURRENT_LIST_DIR}/duckdb/re2.patch CMAKE_ARGS + ${CMAKE_COMPILER_SELECTION_ARGS}) set(BUILD_UNITTESTS OFF) set(ENABLE_SANITIZER OFF) diff --git a/CMake/resolve_dependency_modules/fmt.cmake b/CMake/resolve_dependency_modules/fmt.cmake index 88d8d674d3a3d..abc7f46922a61 100644 --- a/CMake/resolve_dependency_modules/fmt.cmake +++ b/CMake/resolve_dependency_modules/fmt.cmake @@ -25,7 +25,8 @@ message(STATUS "Building fmt from source") FetchContent_Declare( fmt URL ${VELOX_FMT_SOURCE_URL} - URL_HASH ${VELOX_FMT_BUILD_SHA256_CHECKSUM}) + URL_HASH ${VELOX_FMT_BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) # Force fmt to create fmt-config.cmake which can be found by other dependecies # (e.g. folly) set(FMT_INSTALL ON) diff --git a/CMake/resolve_dependency_modules/folly/CMakeLists.txt b/CMake/resolve_dependency_modules/folly/CMakeLists.txt index df7a489384ee7..28234295007a7 100644 --- a/CMake/resolve_dependency_modules/folly/CMakeLists.txt +++ b/CMake/resolve_dependency_modules/folly/CMakeLists.txt @@ -34,7 +34,7 @@ FetchContent_Declare( URL ${VELOX_FOLLY_SOURCE_URL} URL_HASH ${VELOX_FOLLY_BUILD_SHA256_CHECKSUM} PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/folly-no-export.patch - ${glog_patch}) + ${glog_patch} CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) if(ON_APPLE_M1) # folly will wrongly assume x86_64 if this is not set diff --git a/CMake/resolve_dependency_modules/gflags.cmake b/CMake/resolve_dependency_modules/gflags.cmake index 41d302c923131..36a8b166d4ebf 100644 --- a/CMake/resolve_dependency_modules/gflags.cmake +++ b/CMake/resolve_dependency_modules/gflags.cmake @@ -27,7 +27,8 @@ FetchContent_Declare( gflags URL ${VELOX_GFLAGS_SOURCE_URL} URL_HASH ${VELOX_GFLAGS_BUILD_SHA256_CHECKSUM} - PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/gflags/gflags-config.patch) + PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/gflags/gflags-config.patch + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) set(GFLAGS_BUILD_STATIC_LIBS ON) set(GFLAGS_BUILD_gflags_LIB ON) diff --git a/CMake/resolve_dependency_modules/glog.cmake b/CMake/resolve_dependency_modules/glog.cmake index 54836009ed7c8..212def0617b6e 100644 --- a/CMake/resolve_dependency_modules/glog.cmake +++ b/CMake/resolve_dependency_modules/glog.cmake @@ -27,8 +27,10 @@ FetchContent_Declare( glog URL ${VELOX_GLOG_SOURCE_URL} URL_HASH ${VELOX_GLOG_BUILD_SHA256_CHECKSUM} - PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/glog/glog-no-export.patch - && git apply ${CMAKE_CURRENT_LIST_DIR}/glog/glog-config.patch) + PATCH_COMMAND + git apply ${CMAKE_CURRENT_LIST_DIR}/glog/glog-no-export.patch && git apply + ${CMAKE_CURRENT_LIST_DIR}/glog/glog-config.patch CMAKE_ARGS + ${CMAKE_COMPILER_SELECTION_ARGS}) set(BUILD_SHARED_LIBS OFF) set(WITH_UNWIND OFF) diff --git a/CMake/resolve_dependency_modules/google_cloud_cpp_storage.cmake b/CMake/resolve_dependency_modules/google_cloud_cpp_storage.cmake index 8106234925e7b..82cdcb5ab6be2 100644 --- a/CMake/resolve_dependency_modules/google_cloud_cpp_storage.cmake +++ b/CMake/resolve_dependency_modules/google_cloud_cpp_storage.cmake @@ -32,7 +32,8 @@ FetchContent_Declare( google_cloud_cpp URL ${VELOX_GOOGLE_CLOUD_CPP_SOURCE_URL} URL_HASH ${VELOX_GOOGLE_CLOUD_CPP_BUILD_SHA256_CHECKSUM} - OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL SYSTEM) + OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL SYSTEM CMAKE_ARGS + ${CMAKE_COMPILER_SELECTION_ARGS}) set(GOOGLE_CLOUD_CPP_ENABLE_EXAMPLES OFF) set(GOOGLE_CLOUD_CPP_ENABLE diff --git a/CMake/resolve_dependency_modules/grpc.cmake b/CMake/resolve_dependency_modules/grpc.cmake index f105356c231e7..49dba696da3bc 100644 --- a/CMake/resolve_dependency_modules/grpc.cmake +++ b/CMake/resolve_dependency_modules/grpc.cmake @@ -31,7 +31,8 @@ FetchContent_Declare( gRPC URL ${VELOX_GRPC_SOURCE_URL} URL_HASH ${VELOX_GRPC_BUILD_SHA256_CHECKSUM} - OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL) + OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL CMAKE_ARGS + ${CMAKE_COMPILER_SELECTION_ARGS}) set(gRPC_ABSL_PROVIDER "package" diff --git a/CMake/resolve_dependency_modules/gtest.cmake b/CMake/resolve_dependency_modules/gtest.cmake index 8f35b9e954b95..aa97ce86f73fd 100644 --- a/CMake/resolve_dependency_modules/gtest.cmake +++ b/CMake/resolve_dependency_modules/gtest.cmake @@ -26,7 +26,8 @@ message(STATUS "Building gtest from source") FetchContent_Declare( gtest URL ${VELOX_GTEST_SOURCE_URL} - URL_HASH ${VELOX_GTEST_BUILD_SHA256_CHECKSUM}) + URL_HASH ${VELOX_GTEST_BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) FetchContent_MakeAvailable(gtest) diff --git a/CMake/resolve_dependency_modules/icu.cmake b/CMake/resolve_dependency_modules/icu.cmake index 2f46ae885b1d9..94d3bdd824982 100644 --- a/CMake/resolve_dependency_modules/icu.cmake +++ b/CMake/resolve_dependency_modules/icu.cmake @@ -54,7 +54,8 @@ ExternalProject_Add( CONFIGURE_COMMAND /source/configure --prefix=${ICU_DIR} --libdir=${ICU_LIBRARIES} ${ICU_CFG} BUILD_COMMAND ${MAKE_PROGRAM} -j ${NUM_JOBS} - INSTALL_COMMAND ${HOST_ENV_CMAKE} ${MAKE_PROGRAM} install) + INSTALL_COMMAND ${HOST_ENV_CMAKE} ${MAKE_PROGRAM} install + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) add_library(ICU::ICU UNKNOWN IMPORTED) add_dependencies(ICU::ICU ICU-build) diff --git a/CMake/resolve_dependency_modules/protobuf.cmake b/CMake/resolve_dependency_modules/protobuf.cmake index e79d9871b9da5..9ebfe409979c2 100644 --- a/CMake/resolve_dependency_modules/protobuf.cmake +++ b/CMake/resolve_dependency_modules/protobuf.cmake @@ -39,7 +39,8 @@ FetchContent_Declare( protobuf URL ${VELOX_PROTOBUF_SOURCE_URL} URL_HASH ${VELOX_PROTOBUF_BUILD_SHA256_CHECKSUM} - OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL SYSTEM) + OVERRIDE_FIND_PACKAGE EXCLUDE_FROM_ALL SYSTEM CMAKE_ARGS + ${CMAKE_COMPILER_SELECTION_ARGS}) set(protobuf_BUILD_TESTS OFF) set(protobuf_ABSL_PROVIDER diff --git a/CMake/resolve_dependency_modules/pybind11.cmake b/CMake/resolve_dependency_modules/pybind11.cmake index 7874babaf714c..86791c806d036 100644 --- a/CMake/resolve_dependency_modules/pybind11.cmake +++ b/CMake/resolve_dependency_modules/pybind11.cmake @@ -27,6 +27,7 @@ message(STATUS "Building Pybind11 from source") FetchContent_Declare( pybind11 URL ${VELOX_PYBIND11_SOURCE_URL} - URL_HASH ${VELOX_PYBIND11_BUILD_SHA256_CHECKSUM}) + URL_HASH ${VELOX_PYBIND11_BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) FetchContent_MakeAvailable(pybind11) diff --git a/CMake/resolve_dependency_modules/re2.cmake b/CMake/resolve_dependency_modules/re2.cmake index 6bc00c66c0197..a87e690c608f3 100644 --- a/CMake/resolve_dependency_modules/re2.cmake +++ b/CMake/resolve_dependency_modules/re2.cmake @@ -28,7 +28,8 @@ message(STATUS "Building re2 from source") FetchContent_Declare( re2 URL ${VELOX_RE2_SOURCE_URL} - URL_HASH SHA256=${VELOX_RE2_BUILD_SHA256_CHECKSUM}) + URL_HASH SHA256=${VELOX_RE2_BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) set(RE2_USE_ICU ON) set(RE2_BUILD_TESTING OFF) diff --git a/CMake/resolve_dependency_modules/simdjson.cmake b/CMake/resolve_dependency_modules/simdjson.cmake index 69e7f204494b2..c7518b1029845 100644 --- a/CMake/resolve_dependency_modules/simdjson.cmake +++ b/CMake/resolve_dependency_modules/simdjson.cmake @@ -27,6 +27,7 @@ message(STATUS "Building simdjson from source") FetchContent_Declare( simdjson URL ${VELOX_SIMDJSON_SOURCE_URL} - URL_HASH ${VELOX_SIMDJSON_BUILD_SHA256_CHECKSUM}) + URL_HASH ${VELOX_SIMDJSON_BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) FetchContent_MakeAvailable(simdjson) diff --git a/CMake/resolve_dependency_modules/stemmer.cmake b/CMake/resolve_dependency_modules/stemmer.cmake index dbaca146341bc..a163189df55b4 100644 --- a/CMake/resolve_dependency_modules/stemmer.cmake +++ b/CMake/resolve_dependency_modules/stemmer.cmake @@ -42,7 +42,7 @@ ExternalProject_Add( PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/libstemmer/Makefile.patch BUILD_BYPRODUCTS ${STEMMER_PREFIX}/src/libstemmer/${CMAKE_STATIC_LIBRARY_PREFIX}stemmer${CMAKE_STATIC_LIBRARY_SUFFIX} -) + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) add_library(stemmer STATIC IMPORTED GLOBAL) add_library(stemmer::stemmer ALIAS stemmer) diff --git a/CMake/resolve_dependency_modules/template.cmake b/CMake/resolve_dependency_modules/template.cmake index 466cc548af98d..b86b4b27074e9 100644 --- a/CMake/resolve_dependency_modules/template.cmake +++ b/CMake/resolve_dependency_modules/template.cmake @@ -25,6 +25,7 @@ message(STATUS "Building from source") FetchContent_Declare( URL ${VELOX__SOURCE_URL} - URL_HASH ${VELOX__BUILD_SHA256_CHECKSUM}) + URL_HASH ${VELOX__BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) FetchContent_MakeAvailable() diff --git a/CMake/resolve_dependency_modules/xsimd.cmake b/CMake/resolve_dependency_modules/xsimd.cmake index 7719e991987c0..264b341174691 100644 --- a/CMake/resolve_dependency_modules/xsimd.cmake +++ b/CMake/resolve_dependency_modules/xsimd.cmake @@ -26,6 +26,7 @@ message(STATUS "Building xsimd from source") FetchContent_Declare( xsimd URL ${VELOX_XSIMD_SOURCE_URL} - URL_HASH ${VELOX_XSIMD_BUILD_SHA256_CHECKSUM}) + URL_HASH ${VELOX_XSIMD_BUILD_SHA256_CHECKSUM} + CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS}) FetchContent_MakeAvailable(xsimd) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb7c499079806..f9fd297c5c21a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,10 @@ if(${VELOX_FORCE_COLORED_OUTPUT}) elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") add_compile_options(-fcolor-diagnostics) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND "${CMAKE_CXX_COMPILER_VERSION}" + VERSION_GREATER_EQUAL 15) + set(CMAKE_EXE_LINKER_FLAGS "-latomic") + endif() endif() endif() diff --git a/Makefile b/Makefile index b604d560adf64..3529e3012674a 100644 --- a/Makefile +++ b/Makefile @@ -208,3 +208,14 @@ python-build: python-test: $(MAKE) python-build extras="[tests]" DEBUG=1 ${PYTHON_EXECUTABLE} -m unittest -v + +clang-debug: #: Build with debugging symbols using Clang + $(MAKE) debug EXTRA_CMAKE_FLAGS=" ${EXTRA_CMAKE_FLAGS} \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++" + + +clang-release: #: Build the release version using Clang + $(MAKE) release EXTRA_CMAKE_FLAGS=" ${EXTRA_CMAKE_FLAGS} \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++" diff --git a/scripts/setup-centos9.sh b/scripts/setup-centos9.sh index 81a9f4f234979..6cbf7c685e884 100755 --- a/scripts/setup-centos9.sh +++ b/scripts/setup-centos9.sh @@ -31,18 +31,28 @@ 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}" function dnf_install { dnf install -y -q --setopt=install_weak_deps=False "$@" } +function install_and_setup_clang15 { + dnf_install clang15 gcc-toolset-13-libatomic-devel + CLANG_NUM_ALTERNATIVES=`alternatives --list | grep "clang " | wc -l` + if [[ ${CLANG_NUM_ALTERNATIVES} -eq 0 ]]; then + alternatives --install /usr/bin/clang clang /usr/bin/clang-15 80 --follower /usr/bin/clang++ clang++ /usr/bin/clang++-15 + fi + (test ! -h /usr/local/bin/clang && ln -s /usr/bin/ccache /usr/local/bin/clang) || true + (test ! -h /usr/local/bin/clang++ && ln -s /usr/bin/ccache /usr/local/bin/clang++) || true + (test ! -h /usr/lib64/ccache/clang && ln -s /usr/bin/ccache /usr/lib64/ccache/clang) || true + (test ! -h /usr/lib64/ccache/clang++ && ln -s /usr/bin/ccache /usr/lib64/ccache/clang++) || true +} + # Install packages required for build. function install_build_prerequisites { dnf update -y @@ -51,7 +61,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_and_setup_clang15 + fi } # Install dependencies from the package managers. @@ -100,9 +115,14 @@ function install_lzo { function install_boost { wget_and_untar https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.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 + ./b2 "-j$(nproc)" -d0 install threading=multi toolset=clang --without-python + else + ./bootstrap.sh --prefix=/usr/local + ./b2 "-j$(nproc)" -d0 install threading=multi --without-python + fi ) } @@ -244,9 +264,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 + export CXX=/usr/bin/clang++ + 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 @@ -258,9 +284,14 @@ 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 + export CXX=/usr/bin/clang++ + 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!" dnf clean all diff --git a/scripts/setup-ubuntu.sh b/scripts/setup-ubuntu.sh index 8c39f79eaa75e..9b265375a72c4 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 @@ -42,6 +42,28 @@ 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_and_setup_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 + CLANG_NUM_ALTERNATIVES=`update-alternatives --list clang | grep "clang " | wc -l` + if [[ ${CLANG_NUM_ALTERNATIVES} -eq 0 ]]; then + ${SUDO} update-alternatives --install /usr/bin/clang clang /usr/bin/clang-15 80 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-15 + fi + (test ! -h /usr/local/bin/clang && ${SUDO} ln -s /usr/bin/ccache /usr/local/bin/clang) || true + (test ! -h /usr/local/bin/clang++ && ${SUDO} ln -s /usr/bin/ccache /usr/local/bin/clang++) || true + (test ! -h /usr/lib64/ccache/clang && ${SUDO} ln -s /usr/bin/ccache /usr/lib/ccache/clang) || true + (test ! -h /usr/lib64/ccache/clang++ && ${SUDO} ln -s /usr/bin/ccache /usr/lib/ccache/clang++) || true +} # Install packages required for build. function install_build_prerequisites { @@ -59,8 +81,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_and_setup_clang15 + fi } # Install packages required for build. @@ -97,9 +123,17 @@ function install_fmt { } function install_boost { - github_checkout boostorg/boost "${BOOST_VERSION}" --recursive - ./bootstrap.sh --prefix=/usr/local - ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi --without-python + wget_and_untar https://github.com/boostorg/boost/releases/download/${BOOST_VERSION}/${BOOST_VERSION}.tar.gz boost + ( + cd boost + if [[ ${USE_CLANG} != "false" ]]; then + ./bootstrap.sh --prefix=/usr/local --with-toolset=clang + ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi toolset=clang --without-python + else + ./bootstrap.sh --prefix=/usr/local + ${SUDO} ./b2 "-j$(nproc)" -d0 install threading=multi --without-python + fi + ) } function install_folly { @@ -217,6 +251,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 + export CXX=/usr/bin/clang++ + fi if [[ $# -ne 0 ]]; then for cmd in "$@"; do run_and_time "${cmd}"