Skip to content

Commit

Permalink
cmake: build conan libs with sanitizer options
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr committed Jun 14, 2024
1 parent b412051 commit 27a65af
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cmake/cmake_format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ parse:
PATH_OR_REFERENCE: '*'
INSTALL_FOLDER: '*'
BUILD: '*'
OPTIONS: '*'
PROFILE: '*'
CONF: '*'
silkworm_library:
flags:
- NO_TEST
Expand Down
7 changes: 3 additions & 4 deletions cmake/compiler_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
limitations under the License.
]]

include(${CMAKE_CURRENT_LIST_DIR}/compiler_settings_sanitize.cmake)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")

message("MSVC_VERSION = ${MSVC_VERSION}")
Expand Down Expand Up @@ -91,10 +93,7 @@ else()
message(WARNING "${CMAKE_CXX_COMPILER_ID} is not a supported compiler. Use at your own risk.")
endif()

if(SILKWORM_SANITIZE)
set(SILKWORM_SANITIZE_COMPILER_OPTIONS -fno-omit-frame-pointer -fno-sanitize-recover=all
-fsanitize=${SILKWORM_SANITIZE}
)
if(SILKWORM_SANITIZE_COMPILER_OPTIONS)
add_compile_options(${SILKWORM_SANITIZE_COMPILER_OPTIONS})
add_link_options(${SILKWORM_SANITIZE_COMPILER_OPTIONS})
add_compile_definitions(SILKWORM_SANITIZE)
Expand Down
25 changes: 25 additions & 0 deletions cmake/compiler_settings_sanitize.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[[
Copyright 2024 The Silkworm Authors

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.
]]

if(SILKWORM_SANITIZE)
# cmake-format: off
set(SILKWORM_SANITIZE_COMPILER_OPTIONS
-fno-omit-frame-pointer
-fno-sanitize-recover=all
-fsanitize=${SILKWORM_SANITIZE}
)
# cmake-format: on
endif()
36 changes: 34 additions & 2 deletions cmake/conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
limitations under the License.
]]

include(${CMAKE_CURRENT_LIST_DIR}/compiler_settings_sanitize.cmake)

function(guess_conan_profile)
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "")
set(ARCH_NAME "")
Expand Down Expand Up @@ -64,9 +66,39 @@ if(NOT DEFINED CONAN_PROFILE)
endif()
message(STATUS "CONAN_PROFILE: ${CONAN_PROFILE}")

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

if(SILKWORM_SANITIZE_COMPILER_OPTIONS)
set(CONAN_CXXFLAGS ${SILKWORM_SANITIZE_COMPILER_OPTIONS})

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
abseil
boost
grpc
protobuf
)
# cmake-format: on
endif()

conan_cmake_install(
PATH_OR_REFERENCE "${CONAN_BINARY_DIR}"
INSTALL_FOLDER "${CONAN_BINARY_DIR}"
BUILD missing
PROFILE "${CMAKE_SOURCE_DIR}/cmake/profiles/${CONAN_PROFILE}" OPTIONS "${CMAKE_CONAN_OPTIONS}"
BUILD ${CONAN_BUILD}
OPTIONS ${CONAN_OPTIONS}
PROFILE "${CMAKE_SOURCE_DIR}/cmake/profiles/${CONAN_PROFILE}"
CONF "${CONAN_CXXFLAGS_ARG}"
)
2 changes: 2 additions & 0 deletions silkworm/rpc/http/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ std::string Connection::get_date_time() {
Task<void> Connection::compress(const std::string& clear_data, std::string& compressed_data) {
boost::iostreams::filtering_ostream out;
co_await async_task(workers_.executor(), [&]() -> void {
#ifndef SILKWORM_SANITIZE
out.push(boost::iostreams::gzip_compressor());
#endif
out.push(boost::iostreams::back_inserter(compressed_data));
boost::iostreams::copy(boost::make_iterator_range(clear_data), out);
});
Expand Down

0 comments on commit 27a65af

Please sign in to comment.