Auto merge of #2183 - ebfull:rust-introduction, r=ebfull

Introduce Rust/librustzcash into the zcash build system

Introduces Rust into the build system and brings a trivial xor operation into the code (near where we will likely be working).
This commit is contained in:
zkbot 2017-03-21 03:40:12 +00:00
commit 3b11e24f92
7 changed files with 80 additions and 5 deletions

View File

@ -88,6 +88,12 @@ AC_ARG_ENABLE([mining],
[enable_mining=$enableval], [enable_mining=$enableval],
[enable_mining=yes]) [enable_mining=yes])
AC_ARG_ENABLE([rust],
[AS_HELP_STRING([--enable-rust],
[enable rust (default is yes)])],
[enable_rust=$enableval],
[enable_rust=yes])
AC_ARG_WITH([miniupnpc], AC_ARG_WITH([miniupnpc],
[AS_HELP_STRING([--with-miniupnpc], [AS_HELP_STRING([--with-miniupnpc],
[enable UPNP (default is yes if libminiupnpc is found)])], [enable UPNP (default is yes if libminiupnpc is found)])],
@ -751,7 +757,12 @@ CPPFLAGS="-I$LIBSNARK_INCDIR $CPPFLAGS"
AC_CHECK_HEADER([libsnark/gadgetlib1/gadget.hpp],,AC_MSG_ERROR(libsnark headers missing)) AC_CHECK_HEADER([libsnark/gadgetlib1/gadget.hpp],,AC_MSG_ERROR(libsnark headers missing))
AC_CHECK_LIB([snark],[main],LIBSNARK_LIBS=-lsnark, [AC_MSG_ERROR(libsnark missing)], [-lgmpxx]) AC_CHECK_LIB([snark],[main],LIBSNARK_LIBS=-lsnark, [AC_MSG_ERROR(libsnark missing)], [-lgmpxx])
LIBZCASH_LIBS="-lsnark -lgmp -lgmpxx -lboost_system-mt -lcrypto -lsodium -fopenmp" RUST_LIBS=""
if test x$enable_rust != xno; then
RUST_LIBS="-lrustzcash"
fi
LIBZCASH_LIBS="-lsnark -lgmp -lgmpxx -lboost_system-mt -lcrypto -lsodium -fopenmp $RUST_LIBS"
CXXFLAGS_TEMP="$CXXFLAGS" CXXFLAGS_TEMP="$CXXFLAGS"
LIBS_TEMP="$LIBS" LIBS_TEMP="$LIBS"
@ -819,6 +830,16 @@ else
AC_MSG_RESULT(no) AC_MSG_RESULT(no)
fi fi
dnl enable rust
AC_MSG_CHECKING([if rust should be enabled])
if test x$enable_rust != xno; then
AC_MSG_RESULT(yes)
AC_DEFINE(ENABLE_RUST, 1, [Define to 1 to enable Rust language dependent functions])
else
AC_MSG_RESULT(no)
fi
dnl enable upnp support dnl enable upnp support
AC_MSG_CHECKING([whether to build with support for UPnP]) AC_MSG_CHECKING([whether to build with support for UPnP])
if test x$have_miniupnpc = xno; then if test x$have_miniupnpc = xno; then
@ -873,6 +894,7 @@ AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows]) AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes]) AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
AM_CONDITIONAL([ENABLE_MINING],[test x$enable_mining = xyes]) AM_CONDITIONAL([ENABLE_MINING],[test x$enable_mining = xyes])
AM_CONDITIONAL([ENABLE_RUST],[test x$enable_rust = xyes])
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes]) AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes]) AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
AM_CONDITIONAL([USE_COMPARISON_TOOL],[test x$use_comparison_tool != xno]) AM_CONDITIONAL([USE_COMPARISON_TOOL],[test x$use_comparison_tool != xno])

View File

@ -72,10 +72,11 @@ include builders/$(build_os).mk
include builders/default.mk include builders/default.mk
include packages/packages.mk include packages/packages.mk
rust_packages_$(NO_RUST) = $(rust_packages)
wallet_packages_$(NO_WALLET) = $(wallet_packages) wallet_packages_$(NO_WALLET) = $(wallet_packages)
upnp_packages_$(NO_UPNP) = $(upnp_packages) upnp_packages_$(NO_UPNP) = $(upnp_packages)
packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(wallet_packages_) $(upnp_packages_) packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(rust_packages_) $(wallet_packages_) $(upnp_packages_)
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages) native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)
all_packages = $(packages) $(native_packages) all_packages = $(packages) $(native_packages)

View File

@ -0,0 +1,19 @@
package=librustzcash
$(package)_version=0.1
$(package)_download_path=https://github.com/zcash/$(package)/archive/
$(package)_file_name=$(package)-$($(package)_git_commit).tar.gz
$(package)_download_file=$($(package)_git_commit).tar.gz
$(package)_sha256_hash=a5760a90d4a1045c8944204f29fa2a3cf2f800afee400f88bf89bbfe2cce1279
$(package)_git_commit=91348647a86201a9482ad4ad68398152dc3d635e
$(package)_dependencies=rust
define $(package)_build_cmds
cargo build --release
endef
define $(package)_stage_cmds
mkdir $($(package)_staging_dir)$(host_prefix)/lib/ && \
mkdir $($(package)_staging_dir)$(host_prefix)/include/ && \
cp target/release/librustzcash.a $($(package)_staging_dir)$(host_prefix)/lib/ && \
cp include/librustzcash.h $($(package)_staging_dir)$(host_prefix)/include/
endef

View File

@ -1,3 +1,4 @@
rust_packages := rust librustzcash
zcash_packages := libsnark libgmp libsodium zcash_packages := libsnark libgmp libsodium
packages := boost openssl zeromq $(zcash_packages) googletest googlemock packages := boost openssl zeromq $(zcash_packages) googletest googlemock
native_packages := native_ccache native_packages := native_ccache

9
depends/packages/rust.mk Normal file
View File

@ -0,0 +1,9 @@
package=rust
$(package)_version=1.16.0
$(package)_download_path=https://static.rust-lang.org/dist
$(package)_file_name=rust-$($(package)_version)-x86_64-unknown-linux-gnu.tar.gz
$(package)_sha256_hash=48621912c242753ba37cad5145df375eeba41c81079df46f93ffb4896542e8fd
define $(package)_stage_cmds
./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig
endef

View File

@ -16,6 +16,10 @@
#include "sodium.h" #include "sodium.h"
#ifdef ENABLE_RUST
#include "librustzcash.h"
#endif // ENABLE_RUST
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{ {
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
@ -96,6 +100,14 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param
// H(I||V||... // H(I||V||...
crypto_generichash_blake2b_update(&state, (unsigned char*)&ss[0], ss.size()); crypto_generichash_blake2b_update(&state, (unsigned char*)&ss[0], ss.size());
#ifdef ENABLE_RUST
// Ensure that our Rust interactions are working in production builds. This is
// temporary and should be removed.
{
assert(librustzcash_xor(0x0f0f0f0f0f0f0f0f, 0x1111111111111111) == 0x1e1e1e1e1e1e1e1e);
}
#endif // ENABLE_RUST
bool isValid; bool isValid;
EhIsValidSolution(n, k, state, pblock->nSolution, isValid); EhIsValidSolution(n, k, state, pblock->nSolution, isValid);
if (!isValid) if (!isValid)

View File

@ -33,7 +33,7 @@ Usage:
$0 --help $0 --help
Show this help message and exit. Show this help message and exit.
$0 [ --enable-lcov || --disable-tests ] [ --disable-mining ] [ MAKEARGS... ] $0 [ --enable-lcov || --disable-tests ] [ --disable-mining ] [ --disable-rust ] [ MAKEARGS... ]
Build Zcash and most of its transitive dependencies from Build Zcash and most of its transitive dependencies from
source. MAKEARGS are applied to both dependencies and Zcash itself. source. MAKEARGS are applied to both dependencies and Zcash itself.
@ -43,6 +43,9 @@ $0 [ --enable-lcov || --disable-tests ] [ --disable-mining ] [ MAKEARGS... ]
If --disable-mining is passed, Zcash is configured to not build any mining If --disable-mining is passed, Zcash is configured to not build any mining
code. It must be passed after the test arguments, if present. code. It must be passed after the test arguments, if present.
If --disable-rust is passed, Zcash is configured to not build any Rust language
assets. It must be passed after mining/test arguments, if present.
EOF EOF
exit 0 exit 0
fi fi
@ -73,9 +76,17 @@ then
shift shift
fi fi
# If --disable-rust is the next argument, disable Rust code:
RUST_ARG=''
if [ "x${1:-}" = 'x--disable-rust' ]
then
RUST_ARG='--enable-rust=no'
shift
fi
PREFIX="$(pwd)/depends/$BUILD/" PREFIX="$(pwd)/depends/$BUILD/"
HOST="$HOST" BUILD="$BUILD" "$MAKE" "$@" -C ./depends/ V=1 HOST="$HOST" BUILD="$BUILD" NO_RUST="$RUST_ARG" "$MAKE" "$@" -C ./depends/ V=1
./autogen.sh ./autogen.sh
CC="$CC" CXX="$CXX" ./configure --prefix="${PREFIX}" --host="$HOST" --build="$BUILD" "$HARDENING_ARG" "$LCOV_ARG" "$TEST_ARG" "$MINING_ARG" CXXFLAGS='-fwrapv -fno-strict-aliasing -Werror -g' CC="$CC" CXX="$CXX" ./configure --prefix="${PREFIX}" --host="$HOST" --build="$BUILD" "$RUST_ARG" "$HARDENING_ARG" "$LCOV_ARG" "$TEST_ARG" "$MINING_ARG" CXXFLAGS='-fwrapv -fno-strict-aliasing -Werror -g'
"$MAKE" "$@" V=1 "$MAKE" "$@" V=1