Skip to content

Commit 3bf4d68

Browse files
Merge bitcoin-core/secp256k1#1482: build: Clean up handling of module dependencies
e682267 build: Error if required module explicitly off (Tim Ruffing) 89ec583 build: Clean up handling of module dependencies (Tim Ruffing) Pull request description: This is a cleanup which makes it easier to add further modules with dependencies, e.g., in #1452. The diff looks larger than it is because I also reordered the modules and made the order consistent between CMake and autotools. (We noticed that the current logic could be improved in BlockstreamResearch#275.) ACKs for top commit: jonasnick: ACK e682267 hebasto: ACK e682267. Tree-SHA512: 040e791e5b5b9b8845a39632633a45ca759391455910bdefba2b7b77c6340e65df6eda18199ae2ad65c30ee2fc6630471437aec143c26fe09ae4c11409a37622
2 parents 4437886 + e682267 commit 3bf4d68

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

CMakeLists.txt

+22-11
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,40 @@ endif()
5151

5252
option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})
5353

54-
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
55-
if(SECP256K1_ENABLE_MODULE_ECDH)
56-
add_compile_definitions(ENABLE_MODULE_ECDH=1)
57-
endif()
54+
## Modules
5855

56+
# We declare all options before processing them, to make sure we can express
57+
# dependendencies while processing.
58+
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
5959
option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)
60-
if(SECP256K1_ENABLE_MODULE_RECOVERY)
61-
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
62-
endif()
63-
6460
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
6561
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
62+
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
63+
64+
# Processing must be done in a topological sorting of the dependency graph
65+
# (dependent module first).
66+
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
67+
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
68+
endif()
69+
6670
if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
71+
if(DEFINED SECP256K1_ENABLE_MODULE_EXTRAKEYS AND NOT SECP256K1_ENABLE_MODULE_EXTRAKEYS)
72+
message(FATAL_ERROR "Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.")
73+
endif()
6774
set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON)
6875
add_compile_definitions(ENABLE_MODULE_SCHNORRSIG=1)
6976
endif()
77+
7078
if(SECP256K1_ENABLE_MODULE_EXTRAKEYS)
7179
add_compile_definitions(ENABLE_MODULE_EXTRAKEYS=1)
7280
endif()
7381

74-
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
75-
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
76-
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
82+
if(SECP256K1_ENABLE_MODULE_RECOVERY)
83+
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
84+
endif()
85+
86+
if(SECP256K1_ENABLE_MODULE_ECDH)
87+
add_compile_definitions(ENABLE_MODULE_ECDH=1)
7788
endif()
7889

7990
option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF)

configure.ac

+16-13
Original file line numberDiff line numberDiff line change
@@ -387,29 +387,32 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
387387
### Handle module options
388388
###
389389

390-
if test x"$enable_module_ecdh" = x"yes"; then
391-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1"
392-
fi
393-
394-
if test x"$enable_module_recovery" = x"yes"; then
395-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1"
390+
# Processing must be done in a reverse topological sorting of the dependency graph
391+
# (dependent module first).
392+
if test x"$enable_module_ellswift" = x"yes"; then
393+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
396394
fi
397395

398396
if test x"$enable_module_schnorrsig" = x"yes"; then
399-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1"
397+
if test x"$enable_module_extrakeys" = x"no"; then
398+
AC_MSG_ERROR([Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.])
399+
fi
400400
enable_module_extrakeys=yes
401+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1"
401402
fi
402403

403-
if test x"$enable_module_ellswift" = x"yes"; then
404-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
405-
fi
406-
407-
# Test if extrakeys is set after the schnorrsig module to allow the schnorrsig
408-
# module to set enable_module_extrakeys=yes
409404
if test x"$enable_module_extrakeys" = x"yes"; then
410405
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_EXTRAKEYS=1"
411406
fi
412407

408+
if test x"$enable_module_recovery" = x"yes"; then
409+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1"
410+
fi
411+
412+
if test x"$enable_module_ecdh" = x"yes"; then
413+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1"
414+
fi
415+
413416
if test x"$enable_external_default_callbacks" = x"yes"; then
414417
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_DEFAULT_CALLBACKS=1"
415418
fi

0 commit comments

Comments
 (0)