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: Simplify compiler options with Cable #770

Merged
merged 2 commits into from
May 20, 2021
Merged

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented Mar 24, 2021

No description provided.

@codecov
Copy link

codecov bot commented Mar 24, 2021

Codecov Report

Merging #770 (3f4f4ad) into master (eeca732) will increase coverage by 0.13%.
The diff coverage is n/a.

❗ Current head 3f4f4ad differs from pull request most recent head 1260d7b. Consider uploading reports for the commit 1260d7b to get more accurate results

@@            Coverage Diff             @@
##           master     #770      +/-   ##
==========================================
+ Coverage   99.14%   99.28%   +0.13%     
==========================================
  Files          80       77       -3     
  Lines       12374    11953     -421     
==========================================
- Hits        12268    11867     -401     
+ Misses        106       86      -20     
Flag Coverage Δ
rust 99.89% <ø> (-0.01%) ⬇️
spectests 90.55% <ø> (+<0.01%) ⬆️
unittests 99.22% <ø> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/fizzy/execute.cpp 98.71% <0.00%> (-0.83%) ⬇️
test/unittests/capi_test.cpp 99.87% <0.00%> (-0.03%) ⬇️
bindings/rust/src/lib.rs 99.89% <0.00%> (-0.01%) ⬇️
lib/fizzy/execute.hpp 100.00% <0.00%> (ø)
lib/fizzy/instantiate.cpp 100.00% <0.00%> (ø)
lib/fizzy/instantiate.hpp 100.00% <0.00%> (ø)
test/unittests/api_test.cpp 100.00% <0.00%> (ø)
test/unittests/wasi_test.cpp 100.00% <0.00%> (ø)
test/utils/execute_helpers.hpp 100.00% <0.00%> (ø)
test/unittests/execute_test.cpp 100.00% <0.00%> (ø)
... and 11 more

-Wcast-qual
-Wcast-align
-Wmissing-declarations
$<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi>
$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast>
IF_SUPPORTED
Copy link
Member

Choose a reason for hiding this comment

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

So anything below the IF_SUPPORTED magic is only enabled if the compiler supports it?

How about ONLY_IF_SUPPORTED?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, these are optional and enabled if compiler of a particular language supports it.

-Wcast-qual
-Wcast-align
-Wmissing-declarations
$<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi>
$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast>
Copy link
Member

Choose a reason for hiding this comment

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

Does COMPILE_LANGUAGE:CXX means if the file is cpp or if the compiler is run in c++ mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It means C++ compilation determined by CMake by the source file extension (the fact that this is the same tool for C and C++ is only coincidence).

set(result_var "${lang}${flag_id}")

# Check if the flag works in the lang's compiler.
# In CMake 3.18+ cmake_language(CALL ...) can be used.
Copy link
Member

Choose a reason for hiding this comment

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

This means the file does not require 3.18+? What version is required, can we put a min version on the top?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know what the minimal CMake version required is. Hard to tell without testing it with multiple versions. And I don't think it is possible to put cmake_minimum_required() in this file because this will affect the project that loads this file.

cable_add_cxx_compiler_flag_if_supported(-Wduplicated-cond)
cable_add_cxx_compiler_flag_if_supported(-Wduplicate-enum)
cable_add_cxx_compiler_flag_if_supported(-Wlogical-op)
cable_add_cxx_compiler_flag_if_supported(-Wno-unknown-attributes)

if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
option(WEVERYTHING "Enable almost all compiler warnings" OFF)
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense having another helper/case, i.e.

cable_add_compile_option(
  -Weverything
  IF_PRESENT # If the first option(s) works try adding all these?
  -Wno-c++98-compat
  ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not very easy to guess what it does IMHO

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What exactly?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@axic's suggestion. Your change looks fine I think.

@axic
Copy link
Member

axic commented May 19, 2021

Since the holdup here is to check if this works with Solidity, there we'd need something like this:

cable_add_compile_options(
        IF_SUPPORTED
        -Wimplicit-fallthrough
        # Prevent the path of the source directory from ending up in the binary via __FILE__ macros.
        -fmacro-prefix-map=${CMAKE_SOURCE_DIR}=/solidity
        # -Wpessimizing-move warns when a call to std::move would prevent copy elision
        # if the argument was not wrapped in a call.  This happens when moving a local
        # variable in a return statement when the variable is the same type as the
        # return type or using a move to create a new object from a temporary object.
        -Wpessimizing-move
        # -Wredundant-move warns when an implicit move would already be made, so the
        # std::move call is not needed, such as when moving a local variable in a return
        # that is different from the return type.
        -Wredundant-move
)

Would this work?

@axic
Copy link
Member

axic commented May 19, 2021

And how would you simplify the following using the new option:

        eth_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support)
        if(NOT have_stack_protector_strong_support)
                eth_add_cxx_compiler_flag_if_supported(-fstack-protector)
        endif()

@chfast
Copy link
Collaborator Author

chfast commented May 19, 2021

Would this work?

This work.

And how would you simplify the following using the new option:

        eth_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support)
        if(NOT have_stack_protector_strong_support)
                eth_add_cxx_compiler_flag_if_supported(-fstack-protector)
        endif()

This cannot be replaced.

@chfast
Copy link
Collaborator Author

chfast commented May 19, 2021

This is not documented, but -fstack-protector overrides the -fstack-protector-strong. Still you can safely do -fstack-protector -fstack-protector-strong.
https://godbolt.org/z/xPsW179eK

So simplified version would be

cable_add_compile_options(IF_SUPPORTED -fstack-protector -fstack-protector-strong)

@chfast
Copy link
Collaborator Author

chfast commented May 19, 2021

Other good news is that -fstack-protector-strong is supported in all GCC/Clang versions that support -std=c++17 so you can ignore -fstack-protector if you want -fstack-protector-strong.
https://godbolt.org/z/zq1P78jMh

@axic
Copy link
Member

axic commented May 19, 2021

Here are the potential changes/simplifications in Solidity: https://github.com/ethereum/solidity/tree/cmake-options

@chfast chfast force-pushed the cable_add_compile_options branch from 3f4f4ad to c177dd3 Compare May 19, 2021 12:54
@chfast chfast marked this pull request as ready for review May 19, 2021 12:56
@chfast chfast force-pushed the cable_add_compile_options branch from c177dd3 to 1260d7b Compare May 20, 2021 11:22
@chfast chfast merged commit 2fe6f02 into master May 20, 2021
@chfast chfast deleted the cable_add_compile_options branch May 20, 2021 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants