From be5e54c99b586ede2b9055b4756b18b1a7b6c4a6 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 18 Jun 2025 23:16:34 +1200 Subject: [PATCH 1/4] build: avoid exposing internal defines in the amalgamation code This allows for easier inclusion of the source file directly in an existing projects source, rather than compiling it as a separate file. --- src/amalgamation/combined.c | 8 ++++++++ src/internal.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/amalgamation/combined.c b/src/amalgamation/combined.c index 3f1f7659d..b4c604b0e 100644 --- a/src/amalgamation/combined.c +++ b/src/amalgamation/combined.c @@ -38,6 +38,7 @@ * config.h (which must be provided by the amalgamation user) * is included. */ +#define BUILD_AMALGAMATION 1 #include "src/internal.h" /* The amalgamation user can provide their own defines and skip @@ -121,3 +122,10 @@ void wally_silence_unused_warnings(void) assert_bip38_assumptions(); assert_tx_assumptions(); } + +/* Undefine our internal macros */ +#undef BYTES_VALID +#undef BYTES_INVALID +#undef BYTES_INVALID_N +#undef OUTPUT_CHECK +#undef OUTPUT_ALLOC diff --git a/src/internal.h b/src/internal.h index 1b17f7def..bc07f5163 100644 --- a/src/internal.h +++ b/src/internal.h @@ -73,6 +73,7 @@ bool mem_is_zero(const void *mem, size_t len); /* Fetch our internal operations function pointers */ const struct wally_operations *wally_ops(void); +#ifndef BUILD_AMALGAMATION #define malloc(size) __use_wally_malloc_internally__ #define calloc(size) __use_wally_calloc_internally__ #define free(ptr) __use_wally_free_internally__ @@ -80,6 +81,7 @@ const struct wally_operations *wally_ops(void); #undef strdup #endif #define strdup(ptr) __use_wally_strdup_internally__ +#endif #define NUM_ELEMS(a) (sizeof(a) / sizeof(a[0])) From f71c85fbd40acf3ec1c50f9da33add186e04c171 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 18 Jun 2025 23:16:44 +1200 Subject: [PATCH 2/4] build: allow skipping amalgamation code with WALLY_NO_AMALGAMATION This can be useful in some usage scenarios such as including the code from multiple places. --- src/amalgamation/combined.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/amalgamation/combined.c b/src/amalgamation/combined.c index b4c604b0e..7952e1652 100644 --- a/src/amalgamation/combined.c +++ b/src/amalgamation/combined.c @@ -1,3 +1,4 @@ +#ifndef WALLY_NO_AMALGAMATION /* * secp2556k1-zkp configuration */ @@ -129,3 +130,5 @@ void wally_silence_unused_warnings(void) #undef BYTES_INVALID_N #undef OUTPUT_CHECK #undef OUTPUT_ALLOC + +#endif /* WALLY_NO_AMALGAMATION */ From b136526c520b65dd76873162ee5ba2fb91966950 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 18 Jun 2025 23:17:23 +1200 Subject: [PATCH 3/4] build: prevent using minimal mode without elements support or with a system secp Minimal mode assumes the in-tree secp is being used, so enforce this. --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 039a8243f..d1c154c34 100644 --- a/configure.ac +++ b/configure.ac @@ -149,6 +149,9 @@ if test "x$standard_secp" = "xyes"; then fi if test "x$minimal" = "xyes"; then + if test "x$elements" = "xno"; then + AC_MSG_FAILURE([ERROR: Minimal mode requires Elements support to be enabled]) + fi AX_CHECK_COMPILE_FLAG([-DBUILD_MINIMAL=1], [AM_CFLAGS="$AM_CFLAGS -DBUILD_MINIMAL=1"]) fi @@ -271,6 +274,9 @@ AC_ARG_WITH([system-secp256k1], AM_CONDITIONAL([LINK_SYSTEM_SECP256K1], [test "x$with_system_secp256k1" != xno]) AM_COND_IF([LINK_SYSTEM_SECP256K1], [ dnl Use the secp installed system-wide (after checking it for suitability) + if test "x$minimal" = "xyes"; then + AC_MSG_ERROR([Minimal mode cannot be used with --with-system-secp256k1]) + fi saved_LIBS=$LIBS m4_ifdef([PKG_CHECK_MODULES], [PKG_CHECK_MODULES([libsecp256k1], [$with_system_secp256k1])], From 12ab3fa22cbdc26040a9900d02cdb03da5164c85 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Thu, 19 Jun 2025 09:18:43 +1200 Subject: [PATCH 4/4] ci: add minimal amalgamated build tests --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b7bf99bdb..11156350e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -101,8 +101,10 @@ test_amalgamation: - touch config.h - gcc -Wall -W -Wextra -Werror -I. -I./src -I./src/ccan -I./src/secp256k1/include src/ctest/amalgamation_compile_test.c - gcc -DBUILD_ELEMENTS -Wall -W -Wextra -Werror -I. -I./src -I./src/ccan -I./src/secp256k1/include src/ctest/amalgamation_compile_test.c + - gcc -DBUILD_ELEMENTS -DBUILD_MINIMAL -Wall -W -Wextra -Werror -I. -I./src -I./src/ccan -I./src/secp256k1/include src/ctest/amalgamation_compile_test.c - clang -Wall -W -Wextra -Werror -I. -I./src -I./src/ccan -I./src/secp256k1/include src/ctest/amalgamation_compile_test.c - clang -DBUILD_ELEMENTS -Wall -W -Wextra -Werror -I. -I./src -I./src/ccan -I./src/secp256k1/include src/ctest/amalgamation_compile_test.c + - clang -DBUILD_ELEMENTS -DBUILD_MINIMAL -Wall -W -Wextra -Werror -I. -I./src -I./src/ccan -I./src/secp256k1/include src/ctest/amalgamation_compile_test.c test_mingw_static_build: stage: test