Skip to content
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
69 changes: 45 additions & 24 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -259,29 +259,49 @@ fi
#
# libsecp256k1
#
libsecp256k1_CFLAGS='-I$(top_srcdir)/src/secp256k1/include'
AC_ARG_WITH([system-secp256k1],
[AS_HELP_STRING([[--with-system-secp256k1[=PKG]]],
[build using system-installed libsecp256k1 instead of bundled, passing PKG (default: libsecp256k1 or libsecp256k1_zkp, depending on --enable-standard-secp) to pkg-config (default: no)])],
[AS_IF([test "x$withval" = xyes],
[AM_COND_IF([BUILD_STANDARD_SECP], [with_system_secp256k1=libsecp256k1], [with_system_secp256k1=libsecp256k1_zkp])])],
[with_system_secp256k1=no])

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)
saved_LIBS=$LIBS
m4_ifdef([PKG_CHECK_MODULES],
[PKG_CHECK_MODULES([libsecp256k1], [$with_system_secp256k1])],
[AC_MSG_ERROR([You need to install pkg-config to use --with-system-secp256k1.])])
LIBS="$libsecp256k1_LIBS $LIBS"
missing_modules=
AC_DEFUN([CHECK_MODULE], [
AC_CHECK_FUNCS([$2], [], [missing_modules="${missing_modules} $1"])
])
CHECK_MODULE([ecdh], [secp256k1_ecdh])
CHECK_MODULE([extrakeys], [secp256k1_xonly_pubkey_parse])
CHECK_MODULE([recovery], [secp256k1_ecdsa_recover])
CHECK_MODULE([schnorrsig], [secp256k1_schnorrsig_verify])
AM_COND_IF([BUILD_STANDARD_SECP], [], [
CHECK_MODULE([ecdsa-s2c], [secp256k1_ecdsa_s2c_sign])
])
AM_COND_IF([BUILD_ELEMENTS], [
CHECK_MODULE([generator], [secp256k1_generator_parse])
CHECK_MODULE([rangeproof], [secp256k1_rangeproof_verify])
CHECK_MODULE([surjectionproof], [secp256k1_surjectionproof_initialize])
CHECK_MODULE([whitelist], [secp256k1_whitelist_sign])
])
AS_IF([test -n "${missing_modules}"], [
AC_MSG_ERROR([system-installed $with_system_secp256k1 does not support these required modules:${missing_modules}])
])
LIBS=$saved_LIBS
], [
dnl Use the secp in-tree submodule
libsecp256k1_CFLAGS='-I$(top_srcdir)/src/secp256k1/include'
libsecp256k1_LIBS='$(top_srcdir)/src/secp256k1/libsecp256k1.la'
])
AC_SUBST([libsecp256k1_CFLAGS])

# FIXME: This is needed to force libtool to use all object files from secp.
# We can only build secp properly by recursively invoking
# configure/make, and can't include it as a noinst_ library. Libtool
# assumes that such libraries will be installed along with our library
# target and so won't force all object files in the library to be
# included in ours - despite the fact that we are making a shared
# library and linking to a static one. This is broken and we work
# around it by hacking the secp objects directly into the library
# via the _LDADD variable for wallycore.
# We previously achieved this by adding the libsecp256k1.a archive,
# but changes to libtool and apples linkers mean that
# archives-within-archives no longer work.
# Because automake tries to police its users very strictly and fails
# hard when flags are passed in this way, we have to substitute the
# flags here.
# Because libtool both intercepts -Wl and arbitrarily re-orders its
# command line inputs, we have to concoct a single expression to
# enforce linking that cannot be split, hence the below expression.
LIBADD_SECP256K1="-Wl,secp256k1/src/libsecp256k1_la-secp256k1.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult_gen.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult.${OBJEXT}"
AC_SUBST([LIBADD_SECP256K1])
AC_SUBST([libsecp256k1_LIBS])

#
# Python facilities
Expand Down Expand Up @@ -407,8 +427,9 @@ export ARFLAGS
export AR_FLAGS
export LD
export LDFLAGS
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}"
AC_CONFIG_SUBDIRS([src/secp256k1])

AM_COND_IF([LINK_SYSTEM_SECP256K1], [], [
AX_SUBDIRS_CONFIGURE([src/secp256k1], [[--disable-shared], [--enable-static], [--with-pic], [--enable-experimental], [--enable-module-ecdh], [--enable-module-recovery], [--enable-module-ecdsa-s2c], [--enable-module-rangeproof], [--enable-module-surjectionproof], [--enable-module-whitelist], [--enable-module-generator], [--enable-module-extrakeys], [--enable-module-schnorrsig], [$secp256k1_test_opt], [--enable-exhaustive-tests=no], [--enable-benchmark=no], [--disable-dependency-tracking], [$secp_asm]])
])

AC_OUTPUT
47 changes: 47 additions & 0 deletions include/wally_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,53 @@ WALLY_CORE_API int wally_get_build_version(
uint32_t *value);

#ifndef SWIG
/**
* Allocate memory using the configured library allocator.
*
* :param size: Size of the memory region to allocate in bytes.
*
* The allocated memory must be freed using `wally_free`.
*/
WALLY_CORE_API void *wally_malloc(size_t size);

/**
* Allocate and zero memory using the configured library allocator.
*
* :param size: Size of the memory region to allocate in bytes.
*
* The allocated memory must be freed using `wally_free`.
*/
WALLY_CORE_API void *wally_calloc(size_t size);

/**
* Free memory allocated from the configured library allocator.
*
* :param ptr: The memory region to free.
*/
WALLY_CORE_API void wally_free(void *ptr);

/**
* Duplicate a known-length string using the configured library allocator.
*
* :param str_in: The string to duplicate.
* :param str_len: The length of '`str_in`' in bytes.
*
* This function appends a NUL terminator to the string.
* The allocated string must be freed using `wally_free`.
*/
WALLY_CORE_API char *wally_strdup_n(const char *str, size_t str_len);

/**
* Duplicate a string using the configured library allocator.
*
* :param str_in: The string to duplicate.
* :param str_len: The length of '`str_in`' in bytes.
*
* This function appends a NUL terminator to the string.
* The allocated string must be freed using `wally_free`.
*/
WALLY_CORE_API char *wally_strdup(const char *str);

/**
* Fetch the wally internal secp256k1 context object.
*
Expand Down
24 changes: 12 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import copy, os, platform, shutil
import distutils.sysconfig

CONFIGURE_ARGS = '--enable-swig-python --enable-python-manylinux'
CONFIGURE_ARGS += ' --disable-swig-java --disable-tests --disable-dependency-tracking'
CONFIGURE_ARGS = ['--disable-shared', '--enable-static', '--with-pic',
'--enable-swig-python', '--enable-python-manylinux',
'--disable-swig-java', '--disable-tests', '--disable-dependency-tracking']

distutils_env = distutils.sysconfig.get_config_vars()
configure_env = copy.deepcopy(os.environ)
Expand All @@ -26,11 +27,11 @@
if is_x86 and not is_native:
# We are cross-compiling or compiling a univeral2 binary.
# Configure our source code as a cross compile to make the build work
CONFIGURE_ARGS += ' --host x86_64-apple-darwin'
CONFIGURE_ARGS += ['--host', 'x86_64-apple-darwin']
arch = 'universal2' if len(archs) > 1 else archs[0]
CONFIGURE_ARGS += ' --target {}-apple-macos'.format(arch)
CONFIGURE_ARGS += ['--target', '{}-apple-macos'.format(arch)]
if len(archs) > 1:
CONFIGURE_ARGS += ' --with-asm=no'
CONFIGURE_ARGS += ['--with-asm=no']
if 'PY_CFLAGS' in distutils_env:
configure_env['CFLAGS'] = distutils_env['PY_CFLAGS']
configure_env['LDFLAGS'] = distutils_env['PY_LDFLAGS']
Expand All @@ -40,18 +41,17 @@
# then build using the standard Python ext module machinery.
# (Windows requires source generation to be done separately).
import multiprocessing
import os
import subprocess

abs_path = os.path.dirname(os.path.abspath(__file__)) + '/'

def call(cmd):
subprocess.check_call(cmd.split(' '), cwd=abs_path, env=configure_env)
def call(args):
subprocess.check_call(args, cwd=abs_path, env=configure_env)

call('./tools/cleanup.sh')
call('./tools/autogen.sh')
call('./configure {}'.format(CONFIGURE_ARGS))
call('make -j{}'.format(multiprocessing.cpu_count()))
call(['./tools/cleanup.sh'])
call(['./tools/autogen.sh'])
call(['./configure'] + CONFIGURE_ARGS)
call(['make', '-j{}'.format(multiprocessing.cpu_count())])

define_macros=[
('SWIG_PYTHON_BUILD', None),
Expand Down
23 changes: 16 additions & 7 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ libwallycore_la_SOURCES = \
address.c \
anti_exfil.c \
aes.c \
base58.c \
base64.c \
base_58.c \
base_64.c \
bip32.c \
bip38.c \
bip39.c \
Expand All @@ -153,7 +153,7 @@ libwallycore_la_SOURCES = \
ecdh.c \
elements.c \
blech32.c \
hex.c \
hex_.c \
hmac.c \
internal.c \
map.c \
Expand Down Expand Up @@ -193,17 +193,26 @@ libwallycore_la_INCLUDES = \
include/wally_transaction.h

if SHARED_BUILD_ENABLED
LT_VER_CURRENT = 0 # increment at every ABI change (whether breaking or non-breaking)
LT_VER_REVISION = 0 # increment at every release, but reset to 0 at every ABI change
LT_VER_AGE = 0 # increment at every ABI change, but reset to 0 if breaking
# The library filename will be "libwallycore.so.$((current-age)).$((age)).$((revision))",
# and the soname will be "libwallycore.so.$((current-age))".
# Do NOT try to make the library version-info follow the project release version number!
# Only follow the rules above, explained more fully at:
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
libwallycore_la_LDFLAGS = -version-info $(LT_VER_CURRENT):$(LT_VER_REVISION):$(LT_VER_AGE)
if IS_MINGW
libwallycore_la_LDFLAGS = -no-undefined
else
libwallycore_la_LDFLAGS =
libwallycore_la_LDFLAGS += -no-undefined
endif
endif # SHARED_BUILD_ENABLED

libwallycore_la_CFLAGS = -I$(top_srcdir) -I$(srcdir)/ccan $(libsecp256k1_CFLAGS) -DWALLY_CORE_BUILD=1 $(AM_CFLAGS)
libwallycore_la_LIBADD = $(LIBADD_SECP256K1) $(noinst_LTLIBRARIES)
libwallycore_la_LIBADD = $(libsecp256k1_LIBS) $(noinst_LTLIBRARIES)

if !LINK_SYSTEM_SECP256K1
SUBDIRS = secp256k1
endif

TESTS =
noinst_PROGRAMS =
Expand Down
6 changes: 3 additions & 3 deletions src/amalgamation/combined.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "address.c"
#include "aes.c"
#include "anti_exfil.c"
#include "base58.c"
#include "base64.c"
#include "base_58.c"
#include "base_64.c"
#include "bech32.c"
#include "blech32.c"
#include "bip32.c"
Expand All @@ -15,7 +15,7 @@
#include "descriptor.c"
#include "ecdh.c"
#include "elements.c"
#include "hex.c"
#include "hex_.c"
#include "hmac.c"
#include "map.c"
#include "mnemonic.c"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ bool mem_is_zero(const void *mem, size_t len);
/* Fetch our internal operations function pointers */
const struct wally_operations *wally_ops(void);

void *wally_malloc(size_t size);
void *wally_calloc(size_t size);
void wally_free(void *ptr);
char *wally_strdup_n(const char *str, size_t str_len);
char *wally_strdup(const char *str);

#define malloc(size) __use_wally_malloc_internally__
#define calloc(size) __use_wally_calloc_internally__
#define free(ptr) __use_wally_free_internally__
Expand Down
4 changes: 4 additions & 0 deletions tools/autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ if uname | grep "Darwin" >/dev/null 2>&1; then
done
done
fi

if [ -x src/secp256k1/autogen.sh ] ; then
cd src/secp256k1 && ./autogen.sh
fi
Loading