Skip to content

Commit

Permalink
Upgrade toolchain to LLVM17 & Support C++23 (#8899)
Browse files Browse the repository at this point in the history
close #7193, close #8898

Co-authored-by: JaySon <tshent@qq.com>
  • Loading branch information
Lloyd-Pottiger and JaySon-Huang authored Jun 25, 2024
1 parent b03d747 commit 06427c4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
18 changes: 18 additions & 0 deletions .toolchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 PingCAP, Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Hi, there!
# This is passed via jenkins podTemplate argument.
# Instead of trying injections, take a look at https://en.pingcap.com/careers/.
image_tag_suffix: -llvm-17.0.6
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ endif ()

include (cmake/cpu_features.cmake)

set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD 23)
set (CMAKE_CXX_EXTENSIONS 1) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html#prop_tgt:CXX_EXTENSIONS
set (CMAKE_CXX_STANDARD_REQUIRED ON)

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ And the following operating systems:
The following packages are required:

- CMake 3.21.0+
- Clang 13.0.6+
- Clang 17.0.0+ under Linux or AppleClang 15.0.0+ under MacOS
- Rust
- Python 3.0+
- Ninja-Build or GNU Make
Expand All @@ -56,10 +56,10 @@ curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none
source $HOME/.cargo/env

# Install LLVM, see https://apt.llvm.org for details
# Clang will be available as /usr/bin/clang++-13
# Clang will be available as /usr/bin/clang++-17
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 13 all
sudo ./llvm.sh 17 all

# Install other dependencies
sudo apt install -y cmake ninja-build zlib1g-dev libcurl4-openssl-dev ccache
Expand Down Expand Up @@ -128,10 +128,10 @@ brew install ninja cmake openssl@1.1 ccache
If your MacOS is higher or equal to 13.0, it should work out of the box because by default Apple clang is 14.0.0. But if your MacOS is lower than 13.0, you should install llvm clang manually.

```shell
brew install llvm@15
brew install llvm@17

# check llvm version
clang --version # should be 15.0.0 or higher
clang --version # should be 17.0.0 or higher
```

</details>
Expand Down Expand Up @@ -162,8 +162,8 @@ Note: In Linux, usually you need to explicitly specify to use LLVM.
```shell
# In cmake-build-debug directory:
cmake .. -GNinja -DCMAKE_BUILD_TYPE=DEBUG \
-DCMAKE_C_COMPILER=/usr/bin/clang-13 \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-13
-DCMAKE_C_COMPILER=/usr/bin/clang-17 \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-17
```

In MacOS, if you install llvm clang, you need to explicitly specify to use llvm clang.
Expand Down
4 changes: 4 additions & 0 deletions contrib/grpc-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# We want to use C++23, but GRPC is not ready
set (CMAKE_CXX_STANDARD 20)

set(_gRPC_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/grpc")
set(_gRPC_BINARY_DIR "${TiFlash_BINARY_DIR}/contrib/grpc")

Expand Down Expand Up @@ -65,6 +68,7 @@ endif ()
# reject to start w/o it. While this is completelly different library.
#
# [3]: https://packages.debian.org/bullseye/libnsl2

if (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
set(HAVE_LIBNSL OFF CACHE BOOL "" FORCE)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ function bake_llvm_base_aarch64() {

# CMake
source $SCRIPTPATH/install_cmake.sh
install_cmake "3.22.1" "aarch64"
install_cmake "3.24.2" "aarch64"

# LLVM
source $SCRIPTPATH/bootstrap_llvm.sh
bootstrap_llvm "13.0.0"
bootstrap_llvm "17.0.6"
export CC=clang
export CXX=clang++
export LD=ld.lld

# OpenSSL
source $SCRIPTPATH/install_openssl.sh
install_openssl "1_1_1t"
install_openssl "1_1_1w"
export OPENSSL_ROOT_DIR="/usr/local/opt/openssl"

# Git
Expand Down
6 changes: 3 additions & 3 deletions release-centos7-llvm/dockerfiles/misc/bake_llvm_base_amd64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ function bake_llvm_base_amd64() {

# CMake
source $SCRIPTPATH/install_cmake.sh
install_cmake "3.22.1" "x86_64"
install_cmake "3.24.2" "x86_64"

# LLVM
source $SCRIPTPATH/bootstrap_llvm.sh
bootstrap_llvm "13.0.0"
bootstrap_llvm "17.0.6"
export CC=clang
export CXX=clang++
export LD=ld.lld

# OpenSSL
source $SCRIPTPATH/install_openssl.sh
install_openssl "1_1_1t"
install_openssl "1_1_1w"
export OPENSSL_ROOT_DIR="/usr/local/opt/openssl"

# Git
Expand Down
6 changes: 4 additions & 2 deletions release-centos7-llvm/dockerfiles/misc/bootstrap_llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.


INSTALL_PREFIX=${INSTALL_PREFIX:-"/usr/local"}

# Boostrap LLVM envriroment for CI/CD.
# Require: git, ninja, cmake, compiler(devtoolset-10)
Expand All @@ -29,6 +29,7 @@ function bootstrap_llvm() {

cmake -DCMAKE_BUILD_TYPE=Release \
-GNinja \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
-DLLVM_TARGETS_TO_BUILD=Native \
Expand All @@ -44,7 +45,8 @@ function bootstrap_llvm() {

cmake -DCMAKE_BUILD_TYPE=Release \
-GNinja \
-DLLVM_ENABLE_PROJECTS="clang;lld;polly;clang-tools-extra" \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DLLVM_ENABLE_PROJECTS="clang;lld;polly;clang-tools-extra;bolt" \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;openmp;compiler-rt" \
-DLLVM_TARGETS_TO_BUILD=Native \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
Expand Down

0 comments on commit 06427c4

Please sign in to comment.