cmake: Switch to libsecp256k1 upstream build system#192
Conversation
|
For CMake-based projects, it is not common to print the summary at the end of the configuration stage. Printing summaries by subprojects--libsecp256k1 in this PR and minisketch in the future--makes them less useful for the user due to their verbosity. |
I'd say that atleast half of the projects we are (going to) build in depends with CMake print some sort of configuration? So I don't think it's uncommon.
I'm not exactly sure what you're trying to say here. It's not less useful if you actually want to see how things have been configured / are going to be compiled, which, if the plan is to use the CMake build systems of our subtrees, we definitely do. This is useful for developers, in CI etc etc. |
| option(SECP256K1_BUILD_TESTS "" OFF) | ||
| option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "" OFF) | ||
| option(SECP256K1_BUILD_CTIME_TESTS "" OFF) | ||
| add_subdirectory(secp256k1) |
There was a problem hiding this comment.
Does this need EXCLUDE_FROM_ALL to keep it from installing?
There was a problem hiding this comment.
There was a problem hiding this comment.
I think it still makes sense to go ahead and set that option though, since this is what it's meant for. We could remove the SECP256K1_BUILD_* options and not have to worry about any new binaries being added in the future.
There was a problem hiding this comment.
See also bitcoin-core/secp256k1#1545 (comment).
real-or-random
left a comment
There was a problem hiding this comment.
Concept ACK
The libsecp256k1 config looks good to me.
e5e8304 to
b44d5fb
Compare
|
Rebased on top of the #93. |
37ab6d2 to
9f4bf00
Compare
9f4bf00 to
e6d1796
Compare
035c96d to
44a172c
Compare
|
Friendly ping @TheCharlatan @real-or-random @theuni @fanquake :) |
44a172c to
dd47ca9
Compare
dd47ca9 to
d7e2989
Compare
|
Rebased. |
There was a problem hiding this comment.
What are the flags added on various platforms?
There was a problem hiding this comment.
The core_c_flags variable holds the COMPILE_OPTIONS property of the core_base_interface library, which contains:
There are no compile options that are specific to other platforms.
Also it includes sanitizer flags: https://github.com/hebasto/bitcoin/blob/d7e2989666d5a8eab1e0f5ae0c3399b96814747b/CMakeLists.txt#L324-L327
There was a problem hiding this comment.
The core_c_flags variable holds the COMPILE_OPTIONS property of the core_base_interface library, which contains:
There are no compile options that are specific to other platforms.
Why are we adding that flag specifically, into cflags, for mingw, and no other similar flags on different platforms?
There was a problem hiding this comment.
re offline discussion: why do we have a core_c_flags variable, if we aren't otherwise loading or using a c compiler (and how are things ending up in it).
There was a problem hiding this comment.
-
And these are cxx_flags, so they shouldn't apply to libsecp256k1? Or is it just that
try_append_cxx_flagsis a bit of a misleading name (in the end it's just COMPILE_OPTIONS?) I'm not sure after looking at https://github.com/hebasto/bitcoin/blob/cmake-staging/cmake/module/TryAppendCXXFlags.cmake . -
Anyway, I wonder if this flag should be part of the
core_base_interface. Just because it's useful for core, doesn't mean we should pass it also when building the dependencies.
There was a problem hiding this comment.
re offline discussion: why do we have a
core_c_flagsvariable, if we aren't otherwise loading or using a c compiler (and how are things ending up in it).
Not sure if this answers your question, but the variable is defined only in the get_target_interface(core_c_flags ... It's just a local variable in this file and unset further below.
There was a problem hiding this comment.
Or is it just that
try_append_cxx_flagsis a bit of a misleading name (in the end it's just COMPILE_OPTIONS?) I'm not sure after looking atcmake-staging/cmake/module/TryAppendCXXFlags.cmake .
I still think that this is a bit confusing. Okay, the sanitizer flags are typically the same for the C++ compiler and the C compiler. If we make this assumption, would it be a good idea to state it explicitly? Something like this:
# -fsanitize and related flags apply to both C++ and C, so we can pass them down to libsecp256k1 as CFLAGS
get_target_interface(core_sanitizier_cxx_flags "" sanitize_interface COMPILE_OPTIONS)
set(SECP256K1_LATE_CFLAGS ${core_sanitizer_cxx_flags} CACHE STRING "" FORCE)
d7e2989 to
b3766a3
Compare
6fb9b31 to
669b611
Compare
|
Addressed @real-or-random's #192 (comment). |
This change mirrors behavior in the master branch.
This change ensures that both summaries—secp256k1's and Bitcoin Core's— are displayed without interleaving of the `find_package(Doxygen)` output from the `doc` subdirectory.
669b611 to
458d54c
Compare
|
Rebased to resolve a conflict. |
real-or-random
left a comment
There was a problem hiding this comment.
utACK 458d54c as far as the secp256k1 config is concerned
|
I've updated the PR descriptions with possible ways to test this PR. |
dc32026 cmake: Fix `clang-tidy` CI task (Hennadii Stepanov) Pull request description: #192 introduced a regression in the "clang-tidy" CI task. For instance, see https://cirrus-ci.com/task/6601636905222144 from bitcoin#29790. The reason is that disabling `EXPORT_COMPILE_COMMANDS` for `secp256k1` target only is not enough because the subtree's build system has other intermediate build targets internally. ACKs for top commit: TheCharlatan: ACK dc32026 Tree-SHA512: 134e7106c18abd7f07c15742edd73a16847f09452646ed4408d8cd35f7bca9f8501028f94b718720720c7ecc330a91dfd94680c091d010be88952ce4f4ef4c4e
| deduplicate_flags(CMAKE_EXE_LINKER_FLAGS) | ||
| endif() | ||
|
|
||
| if(BUILD_TESTS) |
There was a problem hiding this comment.
Why is this needed for secp256k1 specifically?
There was a problem hiding this comment.
It is not secp256k1-specific change. As a part of the "[FIXUP] cmake: Enable tests before adding subdirectories" commit this change adjusts the moment when enable_testing() being called. Previously, it was done implicitly via include(CTest) command after processing the src subdirectory. Now it done explicitly and before processing the src subdirectory. Which activates any add_test commands within the src subdirectory including the src/secp256k1 subdirectory as well.
| set(SECP256K1_BUILD_CTIME_TESTS OFF CACHE BOOL "" FORCE) | ||
| set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) | ||
| include(GetTargetInterface) | ||
| # -fsanitize and related flags apply to both C++ and C, |
There was a problem hiding this comment.
Shouldn't this also be passing down LDFLAGS? Or is that being done somwhere else?
There was a problem hiding this comment.
Shouldn't this also be passing down LDFLAGS?
Why? libsecp256k1 is a static library, and no linker is used to produce it, right?
There was a problem hiding this comment.
| get_target_interface(core_sanitizer_cxx_flags "" sanitize_interface COMPILE_OPTIONS) | ||
| set(SECP256K1_LATE_CFLAGS ${core_sanitizer_cxx_flags} CACHE STRING "" FORCE) | ||
| unset(core_sanitizer_cxx_flags) | ||
| # We want to build libsecp256k1 with the most tested RelWithDebInfo configuration. |
There was a problem hiding this comment.
We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
Not sure this comment adds much value, and the CMake config is not really the most relevant thing? I'd say what matters more is the secp256k1 configuration, which currently, diverges from upstream, and isn't extensively tested.
There was a problem hiding this comment.
Can you suggest an improved comment or other approach?
| set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE) | ||
| set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE) | ||
| set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE) | ||
| set(SECP256K1_BUILD_CTIME_TESTS OFF CACHE BOOL "" FORCE) |
There was a problem hiding this comment.
I thought we landed on that running the ctime tests would actually be valuable? If not, or if it's waiting on something else, it'd be good to have a comment here explaining why these tests are being skipped.
There was a problem hiding this comment.
I'm sorry if I misunderstood the previous discussion, but I thought that the idea was to mirror the master branch behaviour during migration to CMake.
There was a problem hiding this comment.
I thought that the idea was to mirror the master branch behaviour during migration to CMake.
Ok, but the ctime tests are currently compiled, and runnable there.
d2ab006 cmake: Do not disable libsecp's constant time tests (Hennadii Stepanov) Pull request description: This PR addresses #192 (comment): > Ok, but the ctime tests are currently compiled, and runnable there. and mirrors the behavior of the master branch. Assuming the Valgrind is installed, after building the user can tun: ``` $ valgrind ./build/src/secp256k1/src/ctime_tests ``` ACKs for top commit: TheCharlatan: ACK d2ab006 Tree-SHA512: c4dd4967473fecb7297e1b60b02001a08bc4f302266512fcb76e8742e12305b2f3a4aa29a7fb72489fee68548199c9c87e5750ee4184b5eb64f8788083efeef3
… summaries 2995f0f cmake: Move `FUZZ_BINARY_LINKS_WITHOUT_MAIN_FUNCTION` check (Hennadii Stepanov) 2296161 cmake: Use `TYPE` property to tell Qt libraries type (Hennadii Stepanov) 69afb91 cmake: Move Qt checks (Hennadii Stepanov) 9afe0c8 cmake: Fix `translate` target when `ENABLE_WALLET=OFF` (Hennadii Stepanov) Pull request description: This PR addresses #192 (comment). Additionally, fixed a bug in the `translate` target for the `-DBUILD_GUI=ON -DENABLE_WALLET=OFF` configuration. ACKs for top commit: m3dwards: ACK 2995f0f Tree-SHA512: 03aad0a81077112ee26e04b6faa78abe0bde854faa706b22352f5dd8b0a1be65be5942fad985ec0277eca93227ef005e3a02712059858e6dd6e09ccc5c664e49
77876ca cmake: Move `CMAKE_C_FLAGS` deduplication after enabling C language (Hennadii Stepanov) 56d3878 cmake: Use C++ rather than C in `test-security-check` target (Hennadii Stepanov) 64dd87c contrib: c++ify test stubs after switching to c++ compilers (Cory Fields) 2ea2f53 contrib: rename cc to cxx in binary checking scripts (Cory Fields) 19307f5 contrib: use c++ rather than c for binary tests (Cory Fields) 439ceb0 guix: use glibc 2.31 (fanquake) Pull request description: #192 introduced a regression in the Guix build. For instance, `env HOSTS=x86_64-w64-mingw32 ./contrib/guix/guix-build` for 1eb1250. The C language must be enabled _before_ any reference to `CMAKE_C_*` variables and _in the scope_ of those references (in case of non-cache variables). However, this is not the case on the staging branch at present for the following references: https://github.com/hebasto/bitcoin/blob/1eb125095fc5578d8faf7501f2cf023237b14d59/CMakeLists.txt#L573-L575 and https://github.com/hebasto/bitcoin/blob/1eb125095fc5578d8faf7501f2cf023237b14d59/cmake/module/Maintenance.cmake#L39-L46 This PR fixes this issue by moving the `enable_language(C)` to the top of the root listfile. Top commit has no ACKs. Tree-SHA512: 246745f84973ee38a88fec5dc99887f4b8065bc837b7eb8fd0db44aaded7ea24ece3a2b54baf89df5f5a42a9206ca93690d54733946c9b01e345e4485103493e
To test this PR, one can compare the ouputs of the following commands:
Also sets of the libsecp256k1-specific tests can be compared between
make checkandctest.