Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate ain-grpc and metachain #1598

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ build
*.tmp
.DS_Store

# Codegen
libain_rpc.cpp
libain_rpc.h
libmc.cpp
libmc.h

# Build directory.
build/
out/
Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

2 changes: 1 addition & 1 deletion ci/test/00_setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export BASE_BUILD_DIR=${BASE_BUILD_DIR:-${TRAVIS_BUILD_DIR:-$BASE_ROOT_DIR}}
export BASE_OUTDIR=${BASE_OUTDIR:-$BASE_BUILD_DIR/out/$HOST}
export SDK_URL=${SDK_URL:-https://bitcoincore.org/depends-sources/sdks}
export WINEDEBUG=${WINEDEBUG:-fixme-all}
export DOCKER_PACKAGES=${DOCKER_PACKAGES:-build-essential libtool autotools-dev automake pkg-config bsdmainutils curl ca-certificates ccache python3}
export DOCKER_PACKAGES=${DOCKER_PACKAGES:-build-essential libtool autotools-dev automake pkg-config bsdmainutils curl ca-certificates ccache python3 git unzip}
export GOAL=${GOAL:-install}
export DIR_QA_ASSETS=${DIR_QA_ASSETS:-${BASE_BUILD_DIR}/qa-assets}
export PATH=${BASE_ROOT_DIR}/ci/retry:$PATH
Expand Down
12 changes: 12 additions & 0 deletions ci/test/04_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ DOCKER_EXEC echo "Number of CPUs \(nproc\): $(nproc)"
${CI_RETRY_EXE} DOCKER_EXEC apt-get update
${CI_RETRY_EXE} DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES $DOCKER_PACKAGES

# Install Rust toolchain
DOCKER_EXEC "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y"
DOCKER_EXEC ln -s /root/.cargo/bin/cargo /usr/bin/cargo
DOCKER_EXEC ln -s /root/.cargo/bin/rustc /usr/bin/rustc
DOCKER_EXEC ln -s /root/.cargo/bin/rustup /usr/bin/rustup
DOCKER_EXEC rustup target add x86_64-unknown-linux-gnu

DOCKER_EXEC "curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protoc-3.20.0-linux-x86_64.zip -o /tmp/proto.zip"
DOCKER_EXEC "unzip -o /tmp/proto.zip -d /tmp/proto"
DOCKER_EXEC "chmod 755 -R /tmp/proto/bin"
DOCKER_EXEC "cp /tmp/proto/bin/protoc /usr/local/bin/"
DOCKER_EXEC "cp -R /tmp/proto/include/* /usr/local/include/"
2 changes: 2 additions & 0 deletions ci/test/05_before_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ fi
if [ -z "$NO_DEPENDS" ]; then
DOCKER_EXEC CONFIG_SHELL= make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS
fi

TARGET=${HOST} ./make.sh patch_codegen
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ case $host in
AC_CHECK_LIB([shlwapi], [main],, AC_MSG_ERROR(libshlwapi missing))
AC_CHECK_LIB([iphlpapi], [main],, AC_MSG_ERROR(libiphlpapi missing))
AC_CHECK_LIB([crypt32], [main],, AC_MSG_ERROR(libcrypt32 missing))
AC_CHECK_LIB([bcrypt], [main],, AC_MSG_ERROR(libbcrypt missing))
AC_CHECK_LIB([userenv], [main],, AC_MSG_ERROR(libuserenv missing))

# -static is interpreted by libtool, where it has a different meaning.
# In libtool-speak, it's -all-static.
Expand Down Expand Up @@ -620,6 +622,9 @@ case $host in
;;
esac

AC_CHECK_LIB([ain_grpc],[main],AIN_GRPC_LIBS=-lain_grpc,AC_MSG_ERROR(libain_grpc missing))
AC_CHECK_LIB([metachain],[main],METACHAIN_LIBS=-lmetachain,AC_MSG_ERROR(libmetachain missing))

if test x$use_pkgconfig = xyes; then
m4_ifndef([PKG_PROG_PKG_CONFIG], [AC_MSG_ERROR(PKG_PROG_PKG_CONFIG macro not found. Please install pkg-config and re-run autogen.sh.)])
m4_ifdef([PKG_PROG_PKG_CONFIG], [
Expand Down Expand Up @@ -1417,7 +1422,9 @@ fi

AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
AM_CONDITIONAL([BUILD_NOT_DARWIN], [test x$BUILD_OS != xdarwin])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
AM_CONDITIONAL([TARGET_NOT_WINDOWS], [test x$TARGET_OS != xwindows])
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
Expand Down Expand Up @@ -1487,6 +1494,8 @@ AC_SUBST(MINIUPNPC_CPPFLAGS)
AC_SUBST(MINIUPNPC_LIBS)
AC_SUBST(EVENT_LIBS)
AC_SUBST(EVENT_PTHREADS_LIBS)
AC_SUBST(AIN_GRPC_LIBS)
AC_SUBST(METACHAIN_LIBS)
AC_SUBST(ZMQ_LIBS)
AC_SUBST(QR_LIBS)
AC_SUBST(HAVE_GMTIME_R)
Expand Down
17 changes: 15 additions & 2 deletions contrib/dockerfiles/x86_64-apple-darwin18.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@ RUN apt update && apt dist-upgrade -y
RUN apt install -y software-properties-common build-essential git libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev \
curl cmake \
libminiupnpc-dev libzmq3-dev libqrencode-dev curl cmake unzip \
python3-dev python3-pip libcap-dev libbz2-dev libz-dev fonts-tuffy librsvg2-bin libtiff-tools imagemagick

# install protobuf
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protoc-3.20.0-linux-x86_64.zip
RUN unzip -o protoc-3.20.0-linux-x86_64.zip -d ./proto
RUN chmod 755 -R ./proto/bin
RUN cp ./proto/bin/protoc /usr/local/bin/
RUN cp -R ./proto/include/* /usr/local/include/

# install rustlang
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- --default-toolchain stable -y
ENV PATH=/root/.cargo/bin:$PATH
RUN rustup target add x86_64-apple-darwin

# For Berkeley DB - but we don't need as we do a depends build.
# RUN apt install -y libdb-dev

Expand All @@ -43,6 +55,7 @@ WORKDIR /work
COPY --from=depends-builder /work/depends ./depends
COPY . .

RUN ./make.sh patch_codegen ${TARGET}
RUN ./autogen.sh

# XREF: #make-configure
Expand Down
15 changes: 14 additions & 1 deletion contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ COPY ./make.sh .
RUN apt update && apt install -y apt-transport-https
RUN export DEBIAN_FRONTEND=noninteractive && ./make.sh pkg-install-deps-x86_64

# install protobuf
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protoc-3.20.0-linux-x86_64.zip
RUN unzip -o protoc-3.20.0-linux-x86_64.zip -d ./proto
RUN chmod 755 -R ./proto/bin
RUN cp ./proto/bin/protoc /usr/local/bin/
RUN cp -R ./proto/include/* /usr/local/include/

# install rustlang
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- --default-toolchain stable -y
ENV PATH=/root/.cargo/bin:$PATH
RUN rustup target add x86_64-unknown-linux-gnu

# -----------
FROM builder-base as depends-builder
ARG TARGET
Expand All @@ -36,7 +49,7 @@ WORKDIR /work
COPY . .
RUN ./make.sh purge && rm -rf ./depends
COPY --from=depends-builder /work/depends ./depends

RUN ./make.sh patch_codegen ${TARGET}
RUN export MAKE_COMPILER="CC=gcc CXX=g++" && \
./make.sh build-conf && ./make.sh build-make

Expand Down
20 changes: 18 additions & 2 deletions contrib/dockerfiles/x86_64-w64-mingw32.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ RUN apt update && apt dist-upgrade -y
RUN apt install -y software-properties-common build-essential git libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev \
curl cmake \
libminiupnpc-dev libzmq3-dev libqrencode-dev curl cmake unzip \
g++-mingw-w64-x86-64 mingw-w64-x86-64-dev nsis

# install protobuf
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protoc-3.20.0-linux-x86_64.zip
RUN unzip -o protoc-3.20.0-linux-x86_64.zip -d ./proto
RUN chmod 755 -R ./proto/bin
RUN cp ./proto/bin/protoc /usr/local/bin/
RUN cp -R ./proto/include/* /usr/local/include/

# install rustlang
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- --default-toolchain stable -y
ENV PATH=/root/.cargo/bin:$PATH
RUN rustup target add x86_64-pc-windows-gnu
RUN printf '\n\
[target.x86_64-pc-windows-gnu]\n\
linker = "x86_64-w64-mingw32-gcc"\n\
ar = "x86_64-w64-mingw32-ar"\n' > /root/.cargo/config

# Set the default mingw32 g++ compiler option to posix.
RUN update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix

Expand Down
2 changes: 1 addition & 1 deletion depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ zmq_packages_$(NO_ZMQ) = $(zmq_packages)

rapidcheck_packages_$(RAPIDCHECK) = $(rapidcheck_packages)

packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(wallet_packages_) $(upnp_packages_)
packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(wallet_packages_) $(upnp_packages_) $(libmc_packages) $(libain_packages)
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)

ifneq ($(zmq_packages_),)
Expand Down
30 changes: 30 additions & 0 deletions depends/packages/libain.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package=libain
$(package)_version=master
$(package)_git_path=https://github.com/DeFiCh/libain-rs

define $(package)_fetch_cmds
if [ ! -z ${LIBAIN_PATH} ]; then \
echo "Using local path for libain-rs"; \
mkdir -p $$(base_build_dir)/$$(host)/$(package); \
ln -s $(LIBAIN_PATH) $$($(package)_extract_dir); \
else \
echo "Cloning from Git repository for libain-rs"; \
git clone --single-branch --branch master $$($(package)_git_path) $$($(package)_extract_dir); \
fi
endef

define $(package)_extract_cmds
echo "Skipping extraction for libain source"
endef

# Perform target substitutions for Rust
LIBAIN_TARGET := $(HOST)
LIBAIN_TARGET := $(shell ../depends/rust_target.sh $(LIBAIN_TARGET) )

define $(package)_build_cmds
$(MAKE) build-grpc-pkg TARGET=$(LIBAIN_TARGET)
endef

define $(package)_stage_cmds
cp -r pkg/ain-grpc/* $($(package)_staging_dir)$(host_prefix)/
endef
31 changes: 31 additions & 0 deletions depends/packages/libmc.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package=libmc
$(package)_version=master
$(package)_git_path=https://github.com/DeFiCh/metachain

define $(package)_fetch_cmds
if [ ! -z ${LIBMC_PATH} ]; then \
echo "Using local path for metachain"; \
mkdir -p $$(base_build_dir)/$$(host)/$(package); \
ln -s $(LIBMC_PATH) $$($(package)_extract_dir); \
else \
echo "Cloning from Git repository for metachain"; \
git clone --single-branch --branch libmc $$($(package)_git_path) $$($(package)_extract_dir); \
fi
endef

define $(package)_extract_cmds
echo "Skipping extraction for metachain source"
endef


# Perform target substitutions for Rust
LIBMC_TARGET := $(HOST)
LIBMC_TARGET := $(shell ../depends/rust_target.sh $(LIBMC_TARGET) )

define $(package)_build_cmds
$(MAKE) build-native-pkg TARGET=$(LIBMC_TARGET)
endef

define $(package)_stage_cmds
cp -r pkg/metachain/* $($(package)_staging_dir)$(host_prefix)/
endef
4 changes: 4 additions & 0 deletions depends/packages/packages.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ zmq_packages=zeromq

upnp_packages=miniupnpc

libain_packages = libain

libmc_packages = libmc

darwin_native_packages = native_biplist native_ds_store native_mac_alias

ifneq ($(build_os),darwin)
Expand Down
31 changes: 31 additions & 0 deletions depends/rust_target.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#! /bin/bash

TARGET=$1

case ${TARGET} in

"x86_64-pc-linux-gnu")
echo "x86_64-unknown-linux-gnu"
;;

"arm-linux-gnueabihf")
echo "arm-unknown-linux-gnueabihf"
;;

"x86_64-w64-mingw32")
echo "x86_64-pc-windows-gnu"
;;

"x86_64-apple-darwin18")
arch=$(uname -m)
if [[ "${arch}" == "arm64" ]]; then
echo "aarch64-apple-darwin"
else
echo "x86_64-apple-darwin18"
fi
;;
*)
echo "${TARGET}"
;;

esac
21 changes: 20 additions & 1 deletion doc/build-osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ You can monitor the download process by looking at the debug.log file:
tail -f $HOME/Library/Application\ Support/Bitcoin/debug.log
```

## Installing the rust toolchain (MacOS M1)
```shell
# default installation
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
# custom installation
curl https://sh.rustup.rs -sSf | sh

PATH=$PATH:~/.cargo/bin/cargo
rustup target add aarch64-apple-darwin
```

## Installing the protobuf compiler
```shell
brew install protobuf@3.20

# ensure installation was successful by running
protoc --version
```

## Other commands:
```shell
./src/defid -daemon # Starts the defi daemon.
Expand All @@ -112,7 +131,7 @@ tail -f $HOME/Library/Application\ Support/Bitcoin/debug.log

## Notes
* Tested on OS X 10.10 Yosemite through macOS 10.14 Mojave on 64-bit Intel
processors only.
processors only.

## Deterministic macOS DMG Notes
Working macOS DMGs are created in Linux by combining a recent `clang`, the Apple
Expand Down
18 changes: 17 additions & 1 deletion make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ build_deps() {
popd >/dev/null
}

patch_codegen() {
local target=${1:-${TARGET}}
# Required for patching C++ glue emitted from Rust build
printf "#ifndef DEFI_RUST_RPC_H\n#define DEFI_RUST_RPC_H\n\n" > "$(pwd)/src/libain_rpc.h"
cat "$(pwd)/depends/${target}/include/libain_rpc.hpp" >> "$(pwd)/src/libain_rpc.h"
printf "\n#endif // DEFI_RUST_RPC_H" >> "$(pwd)/src/libain_rpc.h"
printf "#include <libain_rpc.h>\n" > "$(pwd)/src/libain_rpc.cpp"
cat "$(pwd)/depends/${target}/libain_rpc.cpp" >> "$(pwd)/src/libain_rpc.cpp"
printf "#ifndef DEFI_METACHAIN_H\n#define DEFI_METACHAIN_H\n\n" > "$(pwd)/src/libmc.h"
cat "$(pwd)/depends/${target}/include/libmc.hpp" >> "$(pwd)/src/libmc.h"
printf "\n#endif // DEFI_METACHAIN_H" >> "$(pwd)/src/libmc.h"
printf "#include <libmc.h>\n" > "$(pwd)/src/libmc.cpp"
cat "$(pwd)/depends/${target}/libmc.cpp" >> "$(pwd)/src/libmc.cpp"
}

build_conf() {
local target=${1:-${TARGET}}
local make_conf_opts=${MAKE_CONF_ARGS:-}
Expand All @@ -138,6 +153,7 @@ build_make() {

build() {
build_deps "$@"
patch_codegen "$@"
build_conf "$@"
build_make "$@"
}
Expand Down Expand Up @@ -389,7 +405,7 @@ pkg_install_deps_x86_64() {
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev wget \
libdb-dev libdb++-dev libdb5.3 libdb5.3-dev libdb5.3++ libdb5.3++-dev \
curl cmake
curl cmake unzip
}

pkg_install_llvm() {
Expand Down
Loading