diff --git a/.travis.yml b/.travis.yml index 8cb338a2..452c878d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,5 +12,5 @@ script: - _mocha -R spec --recursive cache: directories: - - build + - libbitcoind - cache diff --git a/README.md b/README.md index 81a28e6f..70684f34 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ $ node index.js ## Static Library Patch -To provide native bindings to JavaScript *(or any other language for that matter)*, Bitcoin code, itself, must be linkable. Currently, Bitcoin Core provides a JSON RPC interface to bitcoind as well as a shared library for script validation *(and hopefully more)* called libbitcoinconsensus. There is a node module, [node-libbitcoinconsensus](https://github.com/bitpay/node-libbitcoinconsensus), that exposes these methods. While these interfaces are useful for several use cases, there are additional use cases that are not fulfilled, and being able to implement customized interfaces is necessary. To be able to do this a few simple changes need to be made to Bitcoin Core to compile as a shared library. +To provide native bindings to JavaScript *(or any other language for that matter)*, Bitcoin code, itself, must be linkable. Currently, Bitcoin Core provides a JSON RPC interface to bitcoind as well as a shared library for script validation *(and hopefully more)* called libbitcoinconsensus. There is a node module, [node-libbitcoinconsensus](https://github.com/bitpay/node-libbitcoinconsensus), that exposes these methods. While these interfaces are useful for several use cases, there are additional use cases that are not fulfilled, and being able to implement customized interfaces is necessary. To be able to do this a few simple changes need to be made to Bitcoin Core to compile as a static library. The patch is located at `etc/bitcoin.patch` and adds a configure option `--enable-daemonlib` to compile all object files with `-fPIC` (Position Independent Code - needed to create a shared object), exposes leveldb variables and objects, exposes the threadpool to the bindings, and conditionally includes the main function. diff --git a/bin/build-bindings b/bin/build-bindings index 941c526d..7b535542 100755 --- a/bin/build-bindings +++ b/bin/build-bindings @@ -7,14 +7,8 @@ cd "${root_dir}" debug= if test x"$1" = x'debug'; then debug=--debug - cached_file="${root_dir}"/build/Debug/bitcoind.node -else - cached_file="${root_dir}"/build/Release/bitcoind.node fi - -if [ ! -f "${cached_file}" ]; then - node-pre-gyp ${debug} rebuild --fallback-to-build -fi +node-pre-gyp ${debug} rebuild --fallback-to-build diff --git a/bin/build-libbitcoind b/bin/build-libbitcoind index ac72bbb3..d0175da8 100755 --- a/bin/build-libbitcoind +++ b/bin/build-libbitcoind @@ -1,10 +1,10 @@ #!/bin/bash root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." options=`cat ${root_dir}/bin/config_options.sh` -depends_dir=$($root_dir/variables.sh depends_dir) -host=$(${root_dir}/variables.sh host) +depends_dir=$($root_dir/bin/variables.sh depends_dir) +host=$(${root_dir}/bin/variables.sh host) btc_dir="${root_dir}/libbitcoind" -patch_sha=$($root_dir/variables.sh patch_sha) +patch_sha=$($root_dir/bin/variables.sh patch_sha) export CPPFLAGS="-I${depends_dir}/${host}/include/boost -I${depends_dir}/${host}/include -L${depends_dir}/${host}/lib" echo "Using BTC directory: ${btc_dir}" @@ -40,6 +40,22 @@ compare_patch () { matching_patch=`diff -w /tmp/tmp.patch "${root_dir}/etc/bitcoin.patch"` } +prepare_for_caching () { + cp -r $("${root_dir}"/bin/variables.sh bitcoind) /tmp/bitcoind.tmp + cp -r $("${root_dir}"/bin/variables.sh libsecp256k1) /tmp/libsecp256k1.tmp + cp -r $("${root_dir}"/bin/variables.sh memenv) /tmp/libmemenv.tmp + cp -r $("${root_dir}"/bin/variables.sh leveldb) /tmp/leveldb.tmp + pushd "${btc_dir}" + make clean + mkdir -p "${btc_dir}"/src/.libs + mkdir -p "${btc_dir}"/src/secp256k1/.libs + cp -r /tmp/bitcoind.tmp $("${root_dir}"/bin/variables.sh bitcoind) + cp -r /tmp/libsecp256k1.tmp $("${root_dir}"/bin/variables.sh libsecp256k1) + cp -r /tmp/libmemenv.tmp $("${root_dir}"/bin/variables.sh memenv) + cp -r /tmp/leveldb.tmp $("${root_dir}"/bin/variables.sh leveldb) + popd +} + debug= if [ "${BITCORENODE_ENV}" == "debug" ]; then options=`cat ${root_dir}/bin/config_options_debug.sh` @@ -65,7 +81,7 @@ fi if [ "${shared_file_built}" = false ]; then echo "Looks like the patch to bitcoin changed since last build -or- this is the first build, so rebuilding libbitcoind itself..." - mac_response=$($root_dir/variables.sh mac_dependencies) + mac_response=$($root_dir/bin/variables.sh mac_dependencies) if [ "${mac_response}" != "" ]; then echo "${mac_response}" exit -1 @@ -133,6 +149,7 @@ apply the current patch from "${root_dir}"/etc/bitcoin.patch? (y/N): " echo "Creating the sha marker for the patching in libbitcoind..." echo "Writing patch sha file to: \"${patch_sha}\"" echo -n `shasum -a 256 "${root_dir}"/etc/bitcoin.patch | awk '{print $1}'` > "${patch_sha}" + prepare_for_caching echo 'Build finished successfully.' else echo 'Using existing shared library.' diff --git a/bin/clean b/bin/clean index be22e8e6..a36a42b1 100755 --- a/bin/clean +++ b/bin/clean @@ -3,5 +3,5 @@ root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." cd "${root_dir}" -rm -fr libbitcoind +make clean node-pre-gyp clean diff --git a/variables.sh b/bin/variables.sh similarity index 97% rename from variables.sh rename to bin/variables.sh index 6a63e8dd..7ff215ce 100755 --- a/variables.sh +++ b/bin/variables.sh @@ -2,7 +2,7 @@ exec 2> /dev/null -root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." BITCOIN_DIR="${root_dir}/libbitcoind" host=`uname -m`-`uname -a | awk '{print tolower($1)}'` diff --git a/binding.gyp b/binding.gyp index 03b2d6b1..b44ee1d8 100755 --- a/binding.gyp +++ b/binding.gyp @@ -3,9 +3,9 @@ 'target_name': "<(module_name)", 'include_dirs' : [ '