Skip to content

Commit

Permalink
cmake: upgrade to Conan 2 (#2318)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr committed Dec 13, 2024
1 parent a1a0807 commit 01c2d87
Show file tree
Hide file tree
Showing 39 changed files with 869 additions and 1,332 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ commands:
- run:
name: "Install Conan"
command: |
pip3 install --user --no-warn-script-location conan==1.64.1
pip3 install --user --no-warn-script-location conan==2.8.1
conan_path="$(python -m site --user-base)/bin"
echo "export \"PATH=$conan_path:\$PATH\"" >> "$BASH_ENV"
"$conan_path/conan" --version
Expand Down Expand Up @@ -128,7 +128,7 @@ commands:
name: "Save Conan cache"
key: *conan-cache-key
paths:
- ~/.conan
- ~/.conan2

build_fuzzer:
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/fuzzer-common-steps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ runs:
- name: Preinstall Conan packages
shell: bash
working-directory: ${{runner.workspace}}/silkworm
run: CC=clang-16 CXX=clang++-16 conan install --install-folder=build/conan --build=missing --profile=cmake/profiles/experimental/linux_x64_clang_16_release .
run: CC=clang-16 CXX=clang++-16 conan install --output-folder=build/conan --build=missing --profile:all=cmake/profiles/experimental/linux_x64_clang_16_release .

- name: Configure CMake
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Install Prerequisites
run: |
pip3 install --user --break-system-packages --no-warn-script-location conan==1.64.1 chardet
pip3 install --user --break-system-packages --no-warn-script-location conan==2.8.1 chardet
conan_path="$(python -m site --user-base)/bin"
echo "$conan_path" >> $GITHUB_PATH
"$conan_path/conan" --version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
id: conan
uses: turtlebrowser/get-conan@main
with:
version: 1.64.1
version: 2.8.1

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
Expand Down
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
]]

cmake_minimum_required(VERSION 3.19.0)
cmake_minimum_required(VERSION 3.24.0)

if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/evmone/evmone/evmc/.git)
message(FATAL_ERROR "Git submodules not initialized, execute:\n git submodule update --init --recursive")
Expand All @@ -33,6 +33,8 @@ if(NOT SILKWORM_HAS_PARENT)
)
include("${CMAKE_TOOLCHAIN_FILE}")
endif()

include(cmake/conan.cmake)
endif()

project(silkworm)
Expand Down Expand Up @@ -70,10 +72,6 @@ option(SILKWORM_FUZZER_SANITIZERS "CLang sanitizer options for fuzzers" OFF)
option(SILKWORM_USE_MIMALLOC "Enable using mimalloc for dynamic memory management" ON)
option(SILKWORM_ALLOW_UNUSED_VAR_WARNINGS "Turn unused variable errors into warnings" OFF)

if(NOT SILKWORM_HAS_PARENT)
include(cmake/conan.cmake)
endif()

set_property(
DIRECTORY
APPEND
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ or AppleClang ([Xcode](https://developer.apple.com/xcode/) >= 15)

Conan requires Python, and can be installed using:

pip3 install --user conan==1.64.1 chardet
pip3 install --user conan==2.8.1 chardet

On Linux the conan binary gets installed into `$HOME/.local/bin` which is typically in PATH already.
On macOS need to add the binary to PATH manually:
Expand All @@ -124,7 +124,7 @@ See available profiles in [cmake/profiles](cmake/profiles).

The conan packages could also be pre-installed using [conan install](https://docs.conan.io/1/reference/commands/consumer/install.html):

conan install --install-folder=build/conan --build=missing --profile=cmake/profiles/macos_arm64_clang_13_debug .
conan install --output-folder=build/conan --build=missing --profile:all=cmake/profiles/macos_arm64_clang_13_release .


Then run the build itself
Expand Down
10 changes: 0 additions & 10 deletions cmake/compiler_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang$")
link_libraries(c++abi)
endif()

# cmake-format: off
# abseil in conan is prebuilt with clang 13 (see profiles),
# linking absl::log with clang 18+ produces an error due to an ABI change:
# https://github.com/abseil/abseil-cpp/issues/1747
# https://github.com/llvm/llvm-project/issues/102443
# cmake-format: on
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18)
add_compile_options(-fclang-abi-compat=17)
endif()

else()
message(WARNING "${CMAKE_CXX_COMPILER_ID} is not a supported compiler. Use at your own risk.")
endif()
Expand Down
81 changes: 57 additions & 24 deletions cmake/conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
include(${CMAKE_CURRENT_LIST_DIR}/compiler_settings_sanitize.cmake)

function(guess_conan_profile)
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "" AND CMAKE_HOST_UNIX)
execute_process(
COMMAND uname -m
OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL LAST
)
endif()

if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "")
set(ARCH_NAME "")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL x86_64)
Expand Down Expand Up @@ -49,43 +57,54 @@ function(guess_conan_profile)
)
endfunction()

set(CONAN_BINARY_DIR "${CMAKE_BINARY_DIR}/conan")
list(APPEND CMAKE_MODULE_PATH ${CONAN_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CONAN_BINARY_DIR})

# disable verbose logging from FindXXX.cmake files
set(CONAN_CMAKE_SILENT_OUTPUT ON)
function(get_conan_build_type profile_path var)
file(READ "${profile_path}" CONTENTS)
string(REGEX MATCH "build_type=[A-Za-z0-9]+" VALUE "${CONTENTS}")
string(SUBSTRING "${VALUE}" 11 -1 VALUE)
set(${var}
"${VALUE}"
PARENT_SCOPE
)
endfunction()

include("${CMAKE_SOURCE_DIR}/third_party/cmake-conan/conan.cmake")
find_program(
CONAN_COMMAND "conan"
PATHS /opt/conan2/bin
NO_DEFAULT_PATH
)
if(NOT CONAN_COMMAND)
find_program(CONAN_COMMAND "conan" PATHS ~/.local/bin REQUIRED)
endif()

# provide a static conanfile.py instead of generating it with conan_cmake_configure()
file(COPY "${CMAKE_SOURCE_DIR}/conanfile.py" DESTINATION "${CONAN_BINARY_DIR}")
set(CONAN_BINARY_DIR "${CMAKE_BINARY_DIR}/conan2")

if(NOT DEFINED CONAN_PROFILE)
guess_conan_profile()
endif()
message(STATUS "CONAN_PROFILE: ${CONAN_PROFILE}")
set(CONAN_PROFILE_PATH "${CMAKE_SOURCE_DIR}/cmake/profiles/${CONAN_PROFILE}")
set(CONAN_HOST_PROFILE "${CONAN_PROFILE_PATH}")
set(CONAN_BUILD_PROFILE "${CONAN_PROFILE_PATH}")
get_conan_build_type("${CONAN_PROFILE_PATH}" CONAN_BUILD_TYPE)

set(CONAN_BUILD "missing")
set(CONAN_CXXFLAGS_ARG)
set(CONAN_OPTIONS)
set(CONAN_CXXFLAGS "")
set(CONAN_OPTIONS "")

if(SILKWORM_SANITIZE_COMPILER_OPTIONS)
set(CONAN_CXXFLAGS ${SILKWORM_SANITIZE_COMPILER_OPTIONS})
foreach(VALUE IN LISTS SILKWORM_SANITIZE_COMPILER_OPTIONS)
list(APPEND CONAN_CXXFLAGS ${VALUE})
endforeach()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND CONAN_CXXFLAGS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

list(JOIN CONAN_CXXFLAGS "\", \"" CONAN_CXXFLAGS_STR)
set(CONAN_CXXFLAGS_STR "[\"${CONAN_CXXFLAGS_STR}\"]")
set(CONAN_CXXFLAGS_ARG "tools.build:cxxflags=${CONAN_CXXFLAGS_STR}")

list(APPEND CONAN_OPTIONS "boost:zlib=False")

# libraries that needs to be rebuilt with sanitize flags
# cmake-format: off
set(CONAN_BUILD
list(APPEND CONAN_BUILD
abseil
boost
grpc
Expand All @@ -104,11 +123,25 @@ if(SILKWORM_USE_MIMALLOC)
endif()
endif()

conan_cmake_install(
PATH_OR_REFERENCE "${CONAN_BINARY_DIR}"
INSTALL_FOLDER "${CONAN_BINARY_DIR}"
BUILD ${CONAN_BUILD}
OPTIONS ${CONAN_OPTIONS}
PROFILE "${CMAKE_SOURCE_DIR}/cmake/profiles/${CONAN_PROFILE}"
CONF "${CONAN_CXXFLAGS_ARG}"
set(CONAN_INSTALL_ARGS
--output-folder "${CONAN_BINARY_DIR}"
# https://github.com/conan-io/cmake-conan/issues/607
--settings:all "&:build_type=${CMAKE_BUILD_TYPE}"
)

foreach(VALUE IN LISTS CONAN_BUILD)
list(APPEND CONAN_INSTALL_ARGS --build=${VALUE})
endforeach()

foreach(VALUE IN LISTS CONAN_OPTIONS)
list(APPEND CONAN_INSTALL_ARGS --options:all=${VALUE})
endforeach()

if(CONAN_CXXFLAGS)
list(JOIN CONAN_CXXFLAGS "\",\"" CONAN_CXXFLAGS_STR)
set(CONAN_CXXFLAGS_STR "[\"${CONAN_CXXFLAGS_STR}\"]")
set(CONAN_CXXFLAGS_ARG "tools.build:cxxflags=${CONAN_CXXFLAGS_STR}")
list(APPEND CONAN_INSTALL_ARGS --conf:all=${CONAN_CXXFLAGS_ARG})
endif()

set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_SOURCE_DIR}/third_party/cmake-conan/conan_provider.cmake")
6 changes: 1 addition & 5 deletions cmake/profiles/experimental/linux_arm64_gcc_12_debug
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Linux
os_build=Linux
arch=armv8
arch_build=armv8
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Debug
[options]
[build_requires]
[env]
6 changes: 1 addition & 5 deletions cmake/profiles/experimental/linux_arm64_gcc_12_release
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Linux
os_build=Linux
arch=armv8
arch_build=armv8
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Release
[options]
[build_requires]
[env]
6 changes: 1 addition & 5 deletions cmake/profiles/experimental/linux_x64_gcc_12_debug
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Debug
[options]
[build_requires]
[env]
6 changes: 1 addition & 5 deletions cmake/profiles/experimental/linux_x64_gcc_12_release
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Release
[options]
[build_requires]
[env]
8 changes: 2 additions & 6 deletions cmake/profiles/experimental/macos_arm64_clang_14_debug
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Macos
os_build=Macos
arch=armv8
arch_build=armv8
compiler=apple-clang
compiler.version=14.0
compiler.version=14
compiler.libcxx=libc++
compiler.cppstd=17
build_type=Debug
[options]
[build_requires]
[env]
8 changes: 2 additions & 6 deletions cmake/profiles/experimental/macos_arm64_clang_14_release
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Macos
os_build=Macos
arch=armv8
arch_build=armv8
compiler=apple-clang
compiler.version=14.0
compiler.version=14
compiler.libcxx=libc++
compiler.cppstd=17
build_type=Release
[options]
[build_requires]
[env]
8 changes: 2 additions & 6 deletions cmake/profiles/experimental/macos_x64_clang_14_debug
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Macos
os_build=Macos
arch=x86_64
arch_build=x86_64
compiler=apple-clang
compiler.version=14.0
compiler.version=14
compiler.libcxx=libc++
compiler.cppstd=17
build_type=Debug
[options]
[build_requires]
[env]
8 changes: 2 additions & 6 deletions cmake/profiles/experimental/macos_x64_clang_14_release
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Macos
os_build=Macos
arch=x86_64
arch_build=x86_64
compiler=apple-clang
compiler.version=14.0
compiler.version=14
compiler.libcxx=libc++
compiler.cppstd=17
build_type=Release
[options]
[build_requires]
[env]
2 changes: 1 addition & 1 deletion cmake/profiles/experimental/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ There are very few binary packages for gcc 12 and clang 14 on ConanCenter.

Test using this command:

conan install . --profile cmake/profiles/experimental/linux_x64_gcc_12_release
conan install . --profile:all cmake/profiles/experimental/linux_x64_gcc_12_release

It shows which packages need "Download" of binaries or "Build" from sources.
6 changes: 1 addition & 5 deletions cmake/profiles/experimental/windows_msvc_17_debug
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=17
compiler.runtime=MDd
compiler.cppstd=17
build_type=Debug
[options]
[build_requires]
[env]
6 changes: 1 addition & 5 deletions cmake/profiles/experimental/windows_msvc_17_release
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=17
compiler.runtime=MD
compiler.cppstd=17
build_type=Release
[options]
[build_requires]
[env]
Loading

0 comments on commit 01c2d87

Please sign in to comment.