Skip to content

Commit

Permalink
Changes to compile with Clang15
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Zentgraf committed Jul 23, 2024
1 parent 0c2c385 commit 1f4f2ce
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CMake/ResolveDependency.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/absl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/boost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions CMake/resolve_dependency_modules/cpr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ set(curl_SOURCE BUNDLED)
resolve_dependency(curl)

resolve_dependency_url(CPR)

message(STATUS "Building cpr from source")
FetchContent_Declare(
cpr
URL ${VELOX_CPR_SOURCE_URL}
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
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/duckdb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/fmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CMake/resolve_dependency_modules/folly/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/gflags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions CMake/resolve_dependency_modules/glog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/grpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/icu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ ExternalProject_Add(
CONFIGURE_COMMAND <SOURCE_DIR>/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)
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/re2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/simdjson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion CMake/resolve_dependency_modules/stemmer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/template.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ message(STATUS "Building <PACKAGE> from source")
FetchContent_Declare(
<package>
URL ${VELOX_<PACKAGE>_SOURCE_URL}
URL_HASH ${VELOX_<PACKAGE>_BUILD_SHA256_CHECKSUM})
URL_HASH ${VELOX_<PACKAGE>_BUILD_SHA256_CHECKSUM}
CMAKE_ARGS ${CMAKE_COMPILER_SELECTION_ARGS})

FetchContent_MakeAvailable(<package>)
3 changes: 2 additions & 1 deletion CMake/resolve_dependency_modules/xsimd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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++"
59 changes: 45 additions & 14 deletions scripts/setup-centos9.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
)
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 1f4f2ce

Please sign in to comment.