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 Aug 5, 2024
1 parent a2824a1 commit baea409
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 41 additions & 14 deletions scripts/setup-centos9.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
)
}

Expand Down Expand Up @@ -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
Expand All @@ -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
)
Expand Down
43 changes: 37 additions & 6 deletions scripts/setup-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
)
}

Expand Down Expand Up @@ -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}"
Expand All @@ -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
)

0 comments on commit baea409

Please sign in to comment.