Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to compile with Clang15 #10363

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 46 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,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
)
}

Expand Down Expand Up @@ -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
Expand All @@ -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
majetideepak marked this conversation as resolved.
Show resolved Hide resolved
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
47 changes: 41 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,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we had problems with clang on Ubuntu apart from these versions ? Maybe it would just be good to add this as a warning rather than forcing the user to not use clang.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that it is more complicated to get clang 15 onto the older Ubuntu 20.04. Perhaps we should just not support it anymore and only support the last two LTS versions? Because we officially say Ubuntu 20.04+ is supported I made this check - so really only affects users of Ubuntu 20.04.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still say it should be fine to spit out a warning ; we can assume folks know what they are doing if they choose to play around with compiler versions.

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

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

Loading