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

cmake: Update compiler settings #685

Merged
merged 8 commits into from
Apr 18, 2023
Merged
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Checks: >
clang-analyzer-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-non-private-member-variables-in-classes,
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2016 The EVMC Authors.
# Licensed under the Apache License, Version 2.0.

cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.16...3.24)

if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ before_build:
- if "%VS%" == "2019" (call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd" -arch=amd64)
- if "%VS%" == "2017" (call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\Tools\vsdevcmd" -arch=amd64)
- if "%VS%" == "2017-32bit" (call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\Tools\vsdevcmd" -arch=x86)
- if defined VS cmake -B build -G Ninja -Wno-dev -DEVMC_TESTING=ON
- if defined VS cmake -B build -G Ninja -Wno-dev -DCMAKE_COMPILE_WARNING_AS_ERROR=TRUE -DEVMC_TESTING=ON

build_script:
- cmake --build build --target package
Expand Down
51 changes: 29 additions & 22 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ orbs:
executors:
linux-gcc-latest:
docker:
- image: ethereum/cpp-build-env:18-gcc-12
- image: ethereum/cpp-build-env:19-gcc-12
linux-clang-latest:
docker:
- image: ethereum/cpp-build-env:18-clang-14
- image: ethereum/cpp-build-env:19-clang-15


commands:
Expand Down Expand Up @@ -54,7 +54,7 @@ commands:
name: "Configure"
working_directory: ~/build
command: |
cmake ../project <<#parameters.build_type>>-DCMAKE_BUILD_TYPE=<<parameters.build_type>><</parameters.build_type>> <<#parameters.toolchain>>-DCMAKE_TOOLCHAIN_FILE=~/project/cmake/cable/toolchains/<<parameters.toolchain>>.cmake<</parameters.toolchain>> -DCMAKE_INSTALL_PREFIX=~/install -DEVMC_TESTING=ON $CMAKE_OPTIONS
cmake ../project <<#parameters.build_type>>-DCMAKE_BUILD_TYPE=<<parameters.build_type>><</parameters.build_type>> <<#parameters.toolchain>>-DCMAKE_TOOLCHAIN_FILE=~/project/cmake/cable/toolchains/<<parameters.toolchain>>.cmake<</parameters.toolchain>> -DCMAKE_INSTALL_PREFIX=~/install -DCMAKE_COMPILE_WARNING_AS_ERROR=TRUE -DEVMC_TESTING=ON $CMAKE_OPTIONS
- save_cache:
name: "Save Hunter Cache"
key: *hunter-cache-key
Expand Down Expand Up @@ -206,23 +206,30 @@ jobs:
- store_artifacts:
path: ~/build/coverage
destination: coverage
- run:
name: "Install codecov"
command: |
# TODO: This should go to cpp-build-env image
gpg --no-default-keyring --keyring trustedkeys.gpg --keyserver keyserver.ubuntu.com --recv-key ED779869

export CODECOV_VERSION=v0.4.1
curl -Os https://uploader.codecov.io/$CODECOV_VERSION/linux/codecov
curl -Os https://uploader.codecov.io/$CODECOV_VERSION/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/$CODECOV_VERSION/linux/codecov.SHA256SUM.sig

gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -c codecov.SHA256SUM

chmod +x codecov
sudo mv codecov /usr/local/bin
- run:
name: "Upload to Codecov"
command: |
# Convert to relative paths
sed -i 's|$(pwd)/||' ~/build/evmc.lcov
sudo pip3 install --upgrade --quiet --no-cache-dir codecov==2.1.11
codecov --file ~/build/evmc.lcov -X gcov


build-gcc8:
docker:
- image: ethereum/cpp-build-env:12-gcc-8
steps:
- checkout
- build
- test

build-gcc-sanitizers:
executor: linux-gcc-latest
environment:
Expand All @@ -244,7 +251,7 @@ jobs:

build-clang9-asan:
docker:
- image: ethereum/cpp-build-env:12-clang-9
- image: ethereum/cpp-build-env:15-clang-9
environment:
CMAKE_OPTIONS: -DSANITIZE=address
UBSAN_OPTIONS: halt_on_error=1
Expand All @@ -255,15 +262,15 @@ jobs:

build-gcc-min:
docker:
- image: ethereum/cpp-build-env:13-gcc-7
- image: ethereum/cpp-build-env:15-gcc-8
steps:
- checkout
- build
- test

build-clang-min:
docker:
- image: ethereum/cpp-build-env:13-clang-5
- image: ethereum/cpp-build-env:15-clang-9
steps:
- checkout
- build
Expand All @@ -280,7 +287,7 @@ jobs:

build-cmake-min:
docker:
- image: cimg/base:stable-18.04
- image: cimg/base:stable-20.04
steps:
- run:
name: "Install default CMake"
Expand All @@ -290,8 +297,9 @@ jobs:
- test

build-macos:
resource_class: macos.x86.medium.gen2
macos:
xcode: 14.0.0
xcode: 14.3.0
steps:
- run:
name: "Install System Dependencies"
Expand All @@ -318,7 +326,7 @@ jobs:
$ErrorActionPreference = "Stop"
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64
which cmake
cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install -DEVMC_TESTING=ON
cmake -S . -B ~/build -G Ninja -DCMAKE_COMPILE_WARNING_AS_ERROR=TRUE -DCMAKE_INSTALL_PREFIX=C:\install -DEVMC_TESTING=ON
- run:
name: 'Build'
shell: powershell
Expand Down Expand Up @@ -352,7 +360,7 @@ jobs:
$ErrorActionPreference = "Stop"
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch x86
which cmake
cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install -DEVMC_TESTING=ON
cmake -S . -B ~/build -G Ninja -DCMAKE_COMPILE_WARNING_AS_ERROR=TRUE -DCMAKE_INSTALL_PREFIX=C:\install -DEVMC_TESTING=ON
- run:
name: 'Build'
shell: powershell
Expand All @@ -370,7 +378,7 @@ jobs:

bindings-go-latest:
docker:
- image: cimg/go:1.19
- image: cimg/go:1.20
steps:
- go_test

Expand Down Expand Up @@ -485,7 +493,6 @@ workflows:
jobs:
- lint
- build-clang-coverage
- build-gcc8
- build-gcc-sanitizers
- build-clang-sanitizers
- build-clang9-asan
Expand All @@ -508,7 +515,7 @@ workflows:
- bindings-java
- bindings-rust:
requires:
- build-gcc8
- build-gcc-min
- bindings-rust-asan:
requires:
- build-clang9-asan
Expand Down
61 changes: 33 additions & 28 deletions cmake/cable/CableCompilerSettings.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
# Cable: CMake Bootstrap Library <https://github.com/ethereum/cable>
# Copyright 2018-2020 Pawel Bylica.
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

# Cable Compiler Settings, version 1.0.1
# Cable Compiler Settings, version 1.2.0
#
# This CMake module provides default configuration (with some options)
# for C/C++ compilers. Use cable_configure_compiler().
#
# CHANGELOG
#
# 1.2.0 - 2023-02-24
# - Do not set -Werror nor /WX. This has been standardized in CMake 3.24 as CMAKE_COMPILE_WARNING_AS_ERROR.
# - Keep compiler warnings about unknown pragmas.
# - Keep MSVC warning C5030: attribute is not recognized. It should be disabled in source code.
# - Do not try to erase MSVC default warning level /W3. This is not set since CMake 3.15 (CMP0092).
# - Drop explicit -Wimplicit-fallthrough. It is a part of -Wextra.
# - Use PROJECT_IS_TOP_LEVEL if available (or define it).
#
# 1.1.0 - 2020-06-20
# - Allow unknown C++ attributes in MSVC compiler.
# - Option -DEXCEPTIONS=OFF to disable C++ exceptions support (GCC, clang).
# - Option -DRTTI=OFF to disable RTTI support (GCC, clang).
#
# 1.0.1 - 2020-01-30
# - Do not explicitly set -mtune=generic, this is default anyway.
#
# 1.0.0 - 2019-12-20

if(cable_compiler_settings_included)
return()
endif()
set(cable_compiler_settings_included TRUE)

include_guard()
include(CheckCXXCompilerFlag)

# Adds CXX compiler flag if the flag is supported by the compiler.
Expand Down Expand Up @@ -50,15 +59,13 @@ macro(cable_configure_compiler)
message(FATAL_ERROR "cable_configure_compiler() must be used after project()")
endif()

# Determine if this is the main or a subproject. Leave this variable available for later use.
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(PROJECT_IS_MAIN TRUE)
else()
set(PROJECT_IS_MAIN FALSE)
if(NOT DEFINED PROJECT_IS_TOP_LEVEL)
# Define PROJECT_IS_TOP_LEVEL (since CMake 3.21) if not available.
string(COMPARE EQUAL ${CMAKE_SOURCE_DIR} ${PROJECT_SOURCE_DIR} PROJECT_IS_TOP_LEVEL)
endif()

if(PROJECT_IS_MAIN)
# Do this configuration only in the main project.
if(PROJECT_IS_TOP_LEVEL)
# Do this configuration only in the top level project.

cmake_parse_arguments(cable "NO_CONVERSION_WARNINGS;NO_STACK_PROTECTION;NO_PEDANTIC" "" "" ${ARGN})

Expand All @@ -84,17 +91,14 @@ macro(cable_configure_compiler)
add_compile_options(-Wpedantic)
endif()

# Enable basing warnings set and treat them as errors.
add_compile_options(-Werror -Wall -Wextra -Wshadow)
# Enable basic warnings.
add_compile_options(-Wall -Wextra -Wshadow)

if(NOT cable_NO_CONVERSION_WARNINGS)
# Enable conversion warnings if not explicitly disabled.
add_compile_options(-Wconversion -Wsign-conversion)
endif()

# Allow unknown pragmas, we don't want to wrap them with #ifdefs.
add_compile_options(-Wno-unknown-pragmas)

# Stack protection.
check_cxx_compiler_flag(-fstack-protector fstack-protector)
if(fstack-protector)
Expand All @@ -113,20 +117,21 @@ macro(cable_configure_compiler)
endif()
endif()

cable_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)

elseif(MSVC)

# Get rid of default warning level.
string(REPLACE " /W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE " /W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# Enable basic warnings.
add_compile_options(/W4)

# Enable basing warnings set and treat them as errors.
add_compile_options(/W4 /WX)
endif()

# Allow unknown pragmas, we don't want to wrap them with #ifdefs.
add_compile_options(/wd4068)
option(EXCEPTIONS "Build with exceptions support" ON)
if(NOT EXCEPTIONS)
add_compile_options(-fno-exceptions)
endif()

option(RTTI "Build with RTTI support" ON)
if(NOT RTTI)
add_compile_options(-fno-rtti)
endif()

# Option for arch=native.
Expand Down
23 changes: 13 additions & 10 deletions examples/example_precompiles_vm/example_precompiles_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "example_precompiles_vm.h"
#include <algorithm>

static evmc_result execute_identity(const evmc_message* msg)
namespace
{
evmc_result execute_identity(const evmc_message* msg)
{
auto result = evmc_result{};

Expand All @@ -31,28 +33,28 @@ static evmc_result execute_identity(const evmc_message* msg)
return result;
}

static evmc_result execute_empty(const evmc_message* msg)
evmc_result execute_empty(const evmc_message* msg)
{
auto result = evmc_result{};
result.status_code = EVMC_SUCCESS;
result.gas_left = msg->gas;
return result;
}

static evmc_result not_implemented()
evmc_result not_implemented()
{
auto result = evmc_result{};
result.status_code = EVMC_REJECTED;
return result;
}

static evmc_result execute(evmc_vm* /*vm*/,
const evmc_host_interface* /*host*/,
evmc_host_context* /*context*/,
enum evmc_revision rev,
const evmc_message* msg,
const uint8_t* /*code*/,
size_t /*code_size*/)
evmc_result execute(evmc_vm* /*vm*/,
const evmc_host_interface* /*host*/,
evmc_host_context* /*context*/,
enum evmc_revision rev,
const evmc_message* msg,
const uint8_t* /*code*/,
size_t /*code_size*/)
{
// The EIP-1352 (https://eips.ethereum.org/EIPS/eip-1352) defines
// the range 0 - 0xffff (2 bytes) of addresses reserved for precompiled contracts.
Expand Down Expand Up @@ -93,6 +95,7 @@ static evmc_result execute(evmc_vm* /*vm*/,
return execute_empty(msg);
}
}
} // namespace

evmc_vm* evmc_create_example_precompiles_vm()
{
Expand Down
4 changes: 4 additions & 0 deletions include/evmc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

#ifdef __cplusplus
extern "C" {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#endif

/**
* Returns true if the VM has a compatible ABI version.
Expand Down Expand Up @@ -306,6 +308,8 @@ static inline const char* evmc_revision_to_string(enum evmc_revision rev)
/** @} */

#ifdef __cplusplus
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
} // extern "C"
#endif
7 changes: 4 additions & 3 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ include(GoogleTest)
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)

# Disable support for std::tr1::tuple in GTest. This causes problems in Visual Studio 2015.
set_target_properties(GTest::gtest PROPERTIES INTERFACE_COMPILE_DEFINITIONS GTEST_HAS_TR1_TUPLE=0)

add_library(loader-mocked STATIC ${PROJECT_SOURCE_DIR}/lib/loader/loader.c)
target_link_libraries(loader-mocked PRIVATE evmc::evmc)
target_compile_definitions(loader-mocked PRIVATE EVMC_LOADER_MOCK=1)
Expand Down Expand Up @@ -40,6 +37,10 @@ target_link_libraries(
GTest::gtest_main
)
target_include_directories(evmc-unittests PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_options(
evmc-unittests PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:-wd4068> # allow unknown pragma
)

gtest_add_tests(TARGET evmc-unittests TEST_PREFIX ${PROJECT_NAME}/unittests/ TEST_LIST unittests)

Expand Down
Loading