Skip to content

Commit 26b2e7f

Browse files
committed
build: Extract the libbitcoinkernel library
I strongly recommend reviewing with the following git-diff flags: --patience --color-moved=dimmed-zebra Extract out a libbitcoinkernel library linking in all files necessary for using our consensus engine as-is. Link bitcoin-chainstate against it. See previous commit "build: Add example bitcoin-chainstate executable" for more context. We explicitly specify -fvisibility=default, which effectively overrides the effects of --enable-reduced-exports since libbitcoinkernel requires default symbol visibility When compiling for mingw-w64, specify -static in both: - ..._la_CXXFLAGS so that libtool will avoid building two versions of each object (one PIC, one non-PIC). We just need the one that is suitable for static linking. - ..._la_LDFLAGS so that libtool will create a static library. If we don't specify this, then libtool will prefer the non-static PIC version of the object, which is built with -DDLL_EXPORT -DPIC for mingw-w64 targets. This can cause symbol resolution problems when we link this library against an executable that does specify -all-static, since that will be built without the -DDLL_EXPORT flag. Unfortunately, this means that for mingw-w64 we can only build a static version of the library for now. This will be fixed. However, on other targets, the shared library creation works fine. ----- Note to users: You need to either specify: --enable-experimental-util-chainstate or, --with-experimental-kernel-lib To build the libbitcionkernel library. See the configure help for more details. build shared libbitcoinkernel where we can
1 parent 1df44dd commit 26b2e7f

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

configure.ac

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,12 @@ AC_ARG_WITH([libs],
663663
[build_bitcoin_libs=$withval],
664664
[build_bitcoin_libs=yes])
665665

666+
AC_ARG_WITH([experimental-kernel-lib],
667+
[AS_HELP_STRING([--with-experimental-kernel-lib],
668+
[build experimental bitcoinkernel library (default is to build if we're building libraries and the experimental build-chainstate executable)])],
669+
[build_experimental_kernel_lib=$withval],
670+
[build_experimental_kernel_lib=auto])
671+
666672
AC_ARG_WITH([daemon],
667673
[AS_HELP_STRING([--with-daemon],
668674
[build bitcoind daemon (default=yes)])],
@@ -1657,15 +1663,23 @@ AM_CONDITIONAL([BUILD_BITCOIN_UTIL], [test $build_bitcoin_util = "yes"])
16571663
AC_MSG_RESULT($build_bitcoin_util)
16581664

16591665
AC_MSG_CHECKING([whether to build experimental bitcoin-chainstate])
1660-
AM_CONDITIONAL([BUILD_BITCOIN_CHAINSTATE], [test $build_bitcoin_chainstate = "yes"])
1666+
if test "$build_experimental_kernel_lib" = "no"; then
1667+
AC_MSG_ERROR([experimental bitcoin-chainstate cannot be built without the experimental bitcoinkernel library. Use --with-experimental-kernel-lib]);
1668+
else
1669+
AM_CONDITIONAL([BUILD_BITCOIN_CHAINSTATE], [test $build_bitcoin_chainstate = "yes"])
1670+
fi
16611671
AC_MSG_RESULT($build_bitcoin_chainstate)
16621672

16631673
AC_MSG_CHECKING([whether to build libraries])
16641674
AM_CONDITIONAL([BUILD_BITCOIN_LIBS], [test $build_bitcoin_libs = "yes"])
1675+
16651676
if test "$build_bitcoin_libs" = "yes"; then
16661677
AC_DEFINE([HAVE_CONSENSUS_LIB], [1], [Define this symbol if the consensus lib has been built])
16671678
AC_CONFIG_FILES([libbitcoinconsensus.pc:libbitcoinconsensus.pc.in])
16681679
fi
1680+
1681+
AM_CONDITIONAL([BUILD_BITCOIN_KERNEL_LIB], [test "$build_experimental_kernel_lib" != "no" && ( test "$build_experimental_kernel_lib" = "yes" || test "$build_bitcoin_chainstate" = "yes" )])
1682+
16691683
AC_MSG_RESULT($build_bitcoin_libs)
16701684

16711685
AC_LANG_POP

src/Makefile.am

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ LIBBITCOIN_NODE=libbitcoin_node.a
2929
LIBBITCOIN_COMMON=libbitcoin_common.a
3030
LIBBITCOIN_CONSENSUS=libbitcoin_consensus.a
3131
LIBBITCOIN_CLI=libbitcoin_cli.a
32+
LIBBITCOIN_KERNEL=libbitcoin_kernel.a
3233
LIBBITCOIN_UTIL=libbitcoin_util.a
3334
LIBBITCOIN_CRYPTO_BASE=crypto/libbitcoin_crypto_base.la
3435
LIBBITCOINQT=qt/libbitcoinqt.a
@@ -40,6 +41,9 @@ endif
4041
if BUILD_BITCOIN_LIBS
4142
LIBBITCOINCONSENSUS=libbitcoinconsensus.la
4243
endif
44+
if BUILD_BITCOIN_KERNEL_LIB
45+
LIBBITCOINKERNEL=libbitcoinkernel.la
46+
endif
4347
if ENABLE_WALLET
4448
LIBBITCOIN_WALLET=libbitcoin_wallet.a
4549
LIBBITCOIN_WALLET_TOOL=libbitcoin_wallet_tool.a
@@ -798,8 +802,39 @@ bitcoin_util_LDADD = \
798802
#
799803

800804
# bitcoin-chainstate binary #
801-
bitcoin_chainstate_SOURCES = \
802-
bitcoin-chainstate.cpp \
805+
bitcoin_chainstate_SOURCES = bitcoin-chainstate.cpp
806+
bitcoin_chainstate_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
807+
bitcoin_chainstate_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
808+
bitcoin_chainstate_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
809+
bitcoin_chainstate_LDADD = $(LIBBITCOINKERNEL)
810+
#
811+
812+
# bitcoinkernel library #
813+
if BUILD_BITCOIN_KERNEL_LIB
814+
lib_LTLIBRARIES += $(LIBBITCOINKERNEL)
815+
816+
libbitcoinkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS)
817+
libbitcoinkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1)
818+
libbitcoinkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
819+
820+
# libbitcoinkernel requires default symbol visibility, explicitly specify that
821+
# here so that things still work even when user configures with
822+
# --enable-reduce-exports
823+
#
824+
# Note this is a quick hack that will be removed as we incrementally define what
825+
# to export from the library.
826+
libbitcoinkernel_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -fvisibility=default
827+
828+
# TODO: For now, Specify -static in both CXXFLAGS and LDFLAGS when building for
829+
# windows targets so libtool will only build a static version of this
830+
# library. There are unresolved problems when building dll's for mingw-w64
831+
# and attempting to statically embed libstdc++, libpthread, etc.
832+
if TARGET_WINDOWS
833+
libbitcoinkernel_la_LDFLAGS += -static
834+
libbitcoinkernel_la_CXXFLAGS += -static
835+
endif
836+
837+
libbitcoinkernel_la_SOURCES = \
803838
kernel/bitcoinkernel.cpp \
804839
arith_uint256.cpp \
805840
blockfilter.cpp \
@@ -879,19 +914,11 @@ bitcoin_chainstate_SOURCES = \
879914
validationinterface.cpp \
880915
versionbits.cpp \
881916
warnings.cpp
882-
bitcoin_chainstate_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
883-
bitcoin_chainstate_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
884-
bitcoin_chainstate_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
885-
bitcoin_chainstate_LDADD = \
886-
$(LIBBITCOIN_CRYPTO) \
887-
$(LIBUNIVALUE) \
888-
$(LIBSECP256K1) \
889-
$(LIBLEVELDB) \
890-
$(LIBMEMENV)
891917

892918
# Required for obj/build.h to be generated first.
893919
# More details: https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html
894-
bitcoin_chainstate-clientversion.$(OBJEXT): obj/build.h
920+
libbitcoinkernel_la-clientversion.l$(OBJEXT): obj/build.h
921+
endif # BUILD_BITCOIN_KERNEL_LIB
895922
#
896923

897924
# bitcoinconsensus library #

0 commit comments

Comments
 (0)