diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f33c274b5..a98c6710e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,21 @@ jobs: run: sudo ./scripts/install-build-tools.sh - name: Lint with Pylint run: ./scripts/pylint.sh + shellcheck: + name: Shellcheck + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install Shellcheck + run: | + sudo apt-get update + sudo apt-get install -y shellcheck + - name: Lint with Shellcheck + run: | + NUM_CORES=$(nproc) + find . -name '*.sh' -print0 | xargs -0 -n 1 -P $NUM_CORES shellcheck unit-and-integration-test: name: Unit and Integration Tests runs-on: ubuntu-22.04 @@ -84,7 +99,7 @@ jobs: run: ./scripts/test.sh - name: Shorten SHA id: vars - run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - uses: actions/upload-artifact@v4 if: ${{ !env.ACT }} name: Archive Test Results diff --git a/.gitignore b/.gitignore index ebb163ae7..fddc84dfe 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ CMakeFiles/ plots/ .deps/ .libs/ +.cache/ # Database blocks.dat diff --git a/benchmarks/transactions.cpp b/benchmarks/transactions.cpp index 83aa6c5e7..0350d6f2a 100644 --- a/benchmarks/transactions.cpp +++ b/benchmarks/transactions.cpp @@ -41,21 +41,21 @@ void reset_wallets(cbdc::transaction::wallet& w1, /// @brief Time an N-in, 1-out transaction. /// @brief Note: handles benchmark timing, do not time outside function. /// @param sender -/// @param reciever +/// @param receiver /// @param n_in /// @param state /// @return inline bool generate_Nto1_tx(cbdc::transaction::wallet& sender, - cbdc::transaction::wallet& reciever, + cbdc::transaction::wallet& receiver, uint32_t n_in, benchmark::State& state) { std::optional maybe_tx{}; state.ResumeTiming(); - maybe_tx = sender.send_to(n_in * 2, reciever.generate_key(), true).value(); + maybe_tx = sender.send_to(n_in * 2, receiver.generate_key(), true).value(); state.PauseTiming(); if(maybe_tx.has_value()) { sender.confirm_transaction(*maybe_tx); - reciever.confirm_transaction(*maybe_tx); + receiver.confirm_transaction(*maybe_tx); return true; } return false; @@ -64,22 +64,22 @@ inline bool generate_Nto1_tx(cbdc::transaction::wallet& sender, /// @brief Time an N-in, 2-out transaction. /// @brief Note: handles benchmark timing, do not time outside function. /// @param sender -/// @param reciever +/// @param receiver /// @param n_in /// @param state /// @return inline bool generate_Nto2_tx(cbdc::transaction::wallet& sender, - cbdc::transaction::wallet& reciever, + cbdc::transaction::wallet& receiver, uint32_t n_in, benchmark::State& state) { std::optional maybe_tx{}; state.ResumeTiming(); maybe_tx - = sender.send_to(n_in * 2 - 1, reciever.generate_key(), true).value(); + = sender.send_to(n_in * 2 - 1, receiver.generate_key(), true).value(); state.PauseTiming(); if(maybe_tx.has_value()) { sender.confirm_transaction(*maybe_tx); - reciever.confirm_transaction(*maybe_tx); + receiver.confirm_transaction(*maybe_tx); return true; } return false; diff --git a/scripts/build.sh b/scripts/build.sh index 90d07991d..542714937 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,7 +3,7 @@ set -e help() { - if [ $# -gt 0 ]; then + if [[ $# -gt 0 ]]; then printf 'Unexpected Argument (%s)\n' "$1" fi printf 'HELP: Usage: %s [Debug|Release|Profiling]\n' "$0" @@ -13,15 +13,15 @@ help() { # Note: # CMAKE_BUILD_TYPE="Debug" adds "-O0 -g" flags by default # CMAKE_BUILD_TYPE="Release" adds "-O3 -DNDEBUG" by default -if [[ "$BUILD_DEBUG" == "1" ]]; then +if [[ "${BUILD_DEBUG}" == "1" ]]; then CMAKE_BUILD_TYPE="Debug" -elif [[ "$BUILD_RELEASE" == "1" ]]; then +elif [[ "${BUILD_RELEASE}" == "1" ]]; then CMAKE_BUILD_TYPE="Release" -elif [[ "$BUILD_PROFILING" == "1" ]]; then +elif [[ "${BUILD_PROFILING}" == "1" ]]; then CMAKE_BUILD_TYPE="Profiling" fi -if [ $# -gt 0 ]; then +if [[ $# -gt 0 ]]; then case "$1" in Release|--release|-r) CMAKE_BUILD_TYPE="Release";; Profiling|--profiling|-p) CMAKE_BUILD_TYPE="Profiling";; @@ -36,29 +36,30 @@ echo "Building..." # see PREFIX in ./scripts/setup-dependencies.sh PREFIX="$(cd "$(dirname "$0")"/.. && pwd)/prefix" -if [ -z ${BUILD_DIR+x} ]; then +if [[ -z ${BUILD_DIR+x} ]]; then export BUILD_DIR=build fi -mkdir -p $BUILD_DIR -cd $BUILD_DIR +mkdir -p "${BUILD_DIR}" +cd "${BUILD_DIR}" CMAKE_FLAGS=-DCMAKE_PREFIX_PATH="${PREFIX}" CPUS=1 -if [[ "$OSTYPE" == "linux-gnu"* ]]; then +if [[ "${OSTYPE}" == "linux-gnu"* ]]; then CPUS=$(grep -c ^processor /proc/cpuinfo) -elif [[ "$OSTYPE" == "darwin"* ]]; then +elif [[ "${OSTYPE}" == "darwin"* ]]; then CPUS=$(sysctl -n hw.ncpu) XCODE_CMDLINE_DIR=$(xcode-select -p) CMAKE_FLAGS+=" -DCMAKE_C_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang -DCMAKE_CXX_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang++ -DCMAKE_CXX_FLAGS=-isystem\ /usr/local/include -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" fi -if [[ -z $CMAKE_BUILD_TYPE ]]; then +if [[ -z "${CMAKE_BUILD_TYPE}" ]]; then echo "CMAKE_BUILD_TYPE not set, defaulting to debug" CMAKE_BUILD_TYPE="Debug" fi -echo "Building $CMAKE_BUILD_TYPE" +echo "Building ${CMAKE_BUILD_TYPE}" eval "cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${CMAKE_FLAGS} .." -make -j$CPUS +make "-j${CPUS}" +echo; echo "Build complete"; echo diff --git a/scripts/install-build-tools.sh b/scripts/install-build-tools.sh index 523789d99..c8aba49e1 100755 --- a/scripts/install-build-tools.sh +++ b/scripts/install-build-tools.sh @@ -36,7 +36,7 @@ ENV_NAME=".py_venv" # make a virtual environement to install python packages create_venv_install_python() { PY_LOC=$1 - if [[ -z "$PY_LOC" ]]; then + if [[ -z "${PY_LOC}" ]]; then echo "Python path not provided" exit 1 fi @@ -57,14 +57,14 @@ create_venv_install_python() { fi # install pip for linux if [[ "$OSTYPE" == "linux-gnu"* ]]; then - if ! $SUDO apt install -y python3-pip; then + if ! ${SUDO} apt install -y python3-pip; then echo "Failed to install python3-pip" wget https://bootstrap.pypa.io/get-pip.py - $SUDO python${PY_VERSION} get-pip.py + ${SUDO} python${PY_VERSION} get-pip.py rm get-pip.py fi # add deadsnakes to download the python venv module - $SUDO add-apt-repository -y ppa:deadsnakes/ppa + ${SUDO} add-apt-repository -y ppa:deadsnakes/ppa # make sure deadsnakes is available DEADSNAKES_AVAIL=$(wget -q --spider http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/dists/focal/Release; echo $?) if [[ $DEADSNAKES_AVAIL -ne 0 ]]; then @@ -72,7 +72,7 @@ create_venv_install_python() { exit 1 fi # install python3 venv module for linux - if ! $SUDO apt install -y "python${PY_VERSION}-venv"; then + if ! ${SUDO} apt install -y "python${PY_VERSION}-venv"; then echo "Failed to install python${PY_VERSION}-venv" exit 1 else @@ -102,9 +102,9 @@ create_venv_install_python() { deactivate } -echo "OS Type: $OSTYPE" +echo "OS Type: ${OSTYPE}" # macOS install with homebrew -if [[ "$OSTYPE" == "darwin"* ]]; then +if [[ "${OSTYPE}" == "darwin"* ]]; then # macOS does not support running shell scripts as root with homebrew if [[ $EUID -eq 0 ]]; then @@ -112,9 +112,10 @@ if [[ "$OSTYPE" == "darwin"* ]]; then exit 1 fi + # either use $CPUS for parallelization or delete from this script CPUS=$(sysctl -n hw.ncpu) # ensure development environment is set correctly for clang - $SUDO xcode-select -switch /Library/Developer/CommandLineTools + ${SUDO} xcode-select -switch /Library/Developer/CommandLineTools if ! brew --version &>/dev/null; then echo -e "${cyan}Homebrew is required to install dependencies.${end}" @@ -127,21 +128,21 @@ if [[ "$OSTYPE" == "darwin"* ]]; then BREW_ROOT=$(brew --prefix) CLANG_TIDY=/usr/local/bin/clang-tidy - if [[ ! -L "$CLANG_TIDY" ]]; then - $SUDO ln -s "${BREW_ROOT}/opt/llvm@14/bin/clang-tidy" /usr/local/bin/clang-tidy + if [[ ! -L "${CLANG_TIDY}" ]]; then + ${SUDO} ln -s "${BREW_ROOT}/opt/llvm@14/bin/clang-tidy" /usr/local/bin/clang-tidy fi GMAKE=/usr/local/bin/gmake - if [[ ! -L "$GMAKE" ]]; then - $SUDO ln -s $(xcode-select -p)/usr/bin/gnumake /usr/local/bin/gmake + if [[ ! -L "${GMAKE}" ]]; then + ${SUDO} ln -s $(xcode-select -p)/usr/bin/gnumake /usr/local/bin/gmake fi # install valid python version if not installed yet - if [[ -z "$PY_INSTALLED" ]]; then + if [[ -z "${PY_INSTALLED}" ]]; then PY_VERS=${PYTHON_VERSIONS[0]} FULL_PY="python${PY_VERS}" MAX_RETRIES=2 - while [[ $MAX_RETRIES -gt 0 ]]; do + while [[ ${MAX_RETRIES} -gt 0 ]]; do # try to install python version from homebrew and verify installation if brew install "${FULL_PY}"; then echo "${FULL_PY} installed successfully" @@ -151,50 +152,50 @@ if [[ "$OSTYPE" == "darwin"* ]]; then MAX_RETRIES=$((MAX_RETRIES - 1)) sleep 1 done - if [[ $MAX_RETRIES -eq 0 ]]; then + if [[ ${MAX_RETRIES} -eq 0 ]]; then echo "Python3 install with homebrew failed, attempted on ${FULL_PY}" exit 1 fi fi # Linux install with apt -elif [[ "$OSTYPE" == "linux-gnu"* ]]; then +elif [[ "${OSTYPE}" == "linux-gnu"* ]]; then # avoids getting stuck on interactive prompts which is essential for CI/CD export DEBIAN_FRONTEND=noninteractive - $SUDO apt update -y - $SUDO apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev \ + ${SUDO} apt update -y + ${SUDO} apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev \ lcov git software-properties-common rsync unzip bc # Add LLVM GPG key (apt-key is deprecated in Ubuntu 21.04+ so using gpg) wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | \ gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" | \ - $SUDO tee /etc/apt/sources.list.d/llvm.list + ${SUDO} tee /etc/apt/sources.list.d/llvm.list - $SUDO apt update -y - $SUDO apt install -y clang-format-14 clang-tidy-14 - $SUDO ln -sf $(which clang-format-14) /usr/local/bin/clang-format - $SUDO ln -sf $(which clang-tidy-14) /usr/local/bin/clang-tidy + ${SUDO} apt update -y + ${SUDO} apt install -y clang-format-14 clang-tidy-14 + ${SUDO} ln -sf "$(which clang-format-14)" /usr/local/bin/clang-format + ${SUDO} ln -sf "$(which clang-tidy-14)" /usr/local/bin/clang-tidy # install valid python version if not installed yet - if [[ -z "$PY_INSTALLED" ]]; then + if [[ -z "${PY_INSTALLED}" ]]; then PY_VERS=${PYTHON_VERSIONS[0]} FULL_PY="python${PY_VERS}" # try to install python version from apt and verify installation - $SUDO apt install -y software-properties-common - $SUDO add-apt-repository -y ppa:deadsnakes/ppa - $SUDO apt update -y + ${SUDO} apt install -y software-properties-common + ${SUDO} add-apt-repository -y ppa:deadsnakes/ppa + ${SUDO} apt update -y DEADSNAKES_AVAIL=$(wget -q --spider http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/dists/focal/Release; echo $?) - if [[ $DEADSNAKES_AVAIL -ne 0 ]]; then + if [[ ${DEADSNAKES_AVAIL} -ne 0 ]]; then echo "Failed to add deadsnakes which is needed to install python3" exit 1 fi MAX_RETRIES=2 - while [[ $MAX_RETRIES -gt 0 ]]; do + while [[ ${MAX_RETRIES} -gt 0 ]]; do # install python3 valid version and venv module - if $SUDO apt install -y ${FULL_PY}; then + if ${SUDO} apt install -y "${FULL_PY}"; then echo "${FULL_PY} installed successfully" PY_INSTALLED=${PY_VERS} break @@ -202,7 +203,7 @@ elif [[ "$OSTYPE" == "linux-gnu"* ]]; then MAX_RETRIES=$((MAX_RETRIES - 1)) sleep 1 done - if [[ $MAX_RETRIES -eq 0 ]]; then + if [[ ${MAX_RETRIES} -eq 0 ]]; then echo "Python3 install with apt and deadsnakes failed, attempted on ${FULL_PY}" exit 1 fi @@ -216,7 +217,7 @@ if ! which "python${PY_INSTALLED}" &> /dev/null; then else # create virtual environment and install python packages for the valid python version PYTHON_PATH=$(which "python${PY_INSTALLED}") - create_venv_install_python "${PYTHON_PATH}" ${PY_INSTALLED} + create_venv_install_python "${PYTHON_PATH}" "${PY_INSTALLED}" fi echo "To activate the virtual env to run python, run 'source ./scripts/activate-venv.sh'" @@ -224,8 +225,8 @@ PYTHON_TIDY=/usr/local/bin/run-clang-tidy.py if [[ ! -f "${PYTHON_TIDY}" ]]; then echo -e "${green}Copying run-clang-tidy to /usr/local/bin${end}" wget https://raw.githubusercontent.com/llvm/llvm-project/e837ce2a32369b2e9e8e5d60270c072c7dd63827/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py - $SUDO mv run-clang-tidy.py /usr/local/bin + ${SUDO} mv run-clang-tidy.py /usr/local/bin fi -echo "Build environment setup complete." -echo "Next run './scripts/setup-dependencies.sh'." +echo; echo "Build environment setup complete." +echo "Next run './scripts/setup-dependencies.sh'"; echo diff --git a/scripts/lint.sh b/scripts/lint.sh index c6e4b0936..ee1e6d81d 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -4,30 +4,41 @@ set -e # Usage: ./scripts/lint.sh echo "Linting..." -check_files=$(git ls-files \ - | grep -v -E ".jpg|.svg|3rdparty" | cat) +# GIT_FILES=$(git ls-files) +CHECK_FILES=$(git ls-files | grep -v -E ".jpg|.svg|3rdparty" | cat) -whitespace_files=$(printf '%s' "${check_files[@]}" | xargs egrep -l " +$" | grep -v -E ".md" | cat) +WHITESPACE_FILES=$(printf '%s' "${check_files[@]}" | xargs egrep -l " +$" | grep -v -E ".md" | cat) -if [ -n "$whitespace_files" ]; then +if [[ -n "${WHITESPACE_FILES}" ]]; then echo "The following files have trailing whitespace:" - printf '%s\n' "${whitespace_files[@]}" + printf '%s\n' "${WHITESPACE_FILES[@]}" fi -newline_files=$(printf '%s' "${check_files[@]}" | xargs -r -I {} bash -c 'test "$(tail -c 1 "{}" | wc -l)" -eq 0 && echo {}' | cat) +NEWLINE_FILES=$(printf '%s' "${CHECK_FILES[@]}" | \ + xargs -r -I {} bash -c 'test "$(tail -c 1 "{}" | wc -l)" -eq 0 && echo {}' | cat) -if [ -n "$newline_files" ] ; then +if [[ -n "${NEWLINE_FILES}" ]] ; then echo "The following files need an EOF newline:" - printf '%s\n' "${newline_files[@]}" + printf '%s\n' "${NEWLINE_FILES[@]}" fi -if [ -n "$whitespace_files" ] || [ -n "$newline_files" ] ; then +if [[ -n "${WHITESPACE_FILES}" ]] || [[ -n "${NEWLINE_FILES}" ]] ; then exit 1 fi -check_format_files=$(git ls-files | grep -E "tools|tests|src|cmake-tests" \ - | grep -E "\..*pp") -clang-format --style=file --Werror --dry-run ${check_format_files[@]} +# enable parallelization for clang-format and clang-tidy +NUM_CORES=1 +if [[ "${OSTYPE}" == "linux-gnu"* ]]; then + NUM_CORES=$(grep -c ^processor /proc/cpuinfo) +elif [[ "${OSTYPE}" == "darwin"* ]]; then + NUM_CORES=$(sysctl -n hw.ncpu) +fi + +CHECK_FORMAT_FILES=$(git ls-files \ + | grep -E "tools|tests|src|cmake-tests" \ + | grep -E "\..*pp") +echo "${CHECK_FORMAT_FILES}" | \ + xargs -n1 -P"${NUM_CORES}" -I{} clang-format --style=file --Werror --dry-run {} if ! command -v clang-tidy &>/dev/null; then echo "clang-tidy does not appear to be installed" @@ -35,10 +46,10 @@ if ! command -v clang-tidy &>/dev/null; then exit 1 fi -if [ -z ${BUILD_DIR+x} ]; then +if [[ -z "${BUILD_DIR+x}" ]]; then echo "BUILD_DIR environment variable not found. Assuming default: build" export BUILD_DIR=build - if [ ! -d "${BUILD_DIR}" ]; then + if [[ ! -d "${BUILD_DIR}" ]]; then echo "${BUILD_DIR} directory not found. Please set BUILD_DIR or run \`export BUILD_DIR=${BUILD_DIR}; build.sh\` before linting." exit 1 fi @@ -46,6 +57,6 @@ fi # use python from the virtual environment for clang-tidy if source "./scripts/activate-venv.sh"; then - python /usr/local/bin/run-clang-tidy.py -p ${BUILD_DIR} "tests/.*/.*\.cpp|src/.*/.*\.cpp|tools/.*/.*\.cpp" + python /usr/local/bin/run-clang-tidy.py -j "${NUM_CORES}" -p "${BUILD_DIR}" "tests/.*/.*\.cpp|src/.*/.*\.cpp|tools/.*/.*\.cpp" deactivate fi diff --git a/scripts/setup-dependencies.sh b/scripts/setup-dependencies.sh index ea4b4c771..e8978403c 100755 --- a/scripts/setup-dependencies.sh +++ b/scripts/setup-dependencies.sh @@ -11,44 +11,44 @@ set -e # install in a custom prefix rather than /usr/local. by default, this # chooses "prefix" directory alongside "scripts" directory. PREFIX="$(cd "$(dirname "$0")"/.. && pwd)/prefix" -echo "Will install local dependencies in the following prefix: $PREFIX" -mkdir -p "$PREFIX"/{lib,include} +echo "Will install local dependencies in the following prefix: ${PREFIX}" +mkdir -p "${PREFIX}"/{lib,include} CMAKE_BUILD_TYPE="Debug" -if [[ "$BUILD_RELEASE" == "1" ]]; then +if [[ "${BUILD_RELEASE}" == "1" ]]; then CMAKE_BUILD_TYPE="Release" fi CPUS=1 -if [[ "$OSTYPE" == "linux-gnu"* ]]; then +if [[ "${OSTYPE}" == "linux-gnu"* ]]; then CPUS=$(grep -c ^processor /proc/cpuinfo) -elif [[ "$OSTYPE" == "darwin"* ]]; then +elif [[ "${OSTYPE}" == "darwin"* ]]; then CPUS=$(sysctl -n hw.ncpu) fi LEVELDB_VERSION="1.23" echo -e "${green}Building LevelDB from sources...${end}" -wget https://github.com/google/leveldb/archive/${LEVELDB_VERSION}.tar.gz +wget "https://github.com/google/leveldb/archive/${LEVELDB_VERSION}.tar.gz" rm -rf "leveldb-${LEVELDB_VERSION}-${CMAKE_BUILD_TYPE}" -tar xzvf ${LEVELDB_VERSION}.tar.gz -rm -rf ${LEVELDB_VERSION}.tar.gz -mv leveldb-${LEVELDB_VERSION} "leveldb-${LEVELDB_VERSION}-${CMAKE_BUILD_TYPE}" +tar xzvf "${LEVELDB_VERSION}.tar.gz" +rm -rf "${LEVELDB_VERSION}.tar.gz" +mv "leveldb-${LEVELDB_VERSION}" "leveldb-${LEVELDB_VERSION}-${CMAKE_BUILD_TYPE}" cd "leveldb-${LEVELDB_VERSION}-${CMAKE_BUILD_TYPE}" -cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DLEVELDB_BUILD_TESTS=0 -DLEVELDB_BUILD_BENCHMARKS=0 -DBUILD_SHARED_LIBS=0 -DHAVE_SNAPPY=0 . -make -j$CPUS +cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" -DLEVELDB_BUILD_TESTS=0 -DLEVELDB_BUILD_BENCHMARKS=0 -DBUILD_SHARED_LIBS=0 -DHAVE_SNAPPY=0 . +make "-j${CPUS}" make install cd .. NURAFT_VERSION="1.3.0" echo -e "${green}Building NuRaft from sources...${end}" -wget https://github.com/eBay/NuRaft/archive/v${NURAFT_VERSION}.tar.gz +wget "https://github.com/eBay/NuRaft/archive/v${NURAFT_VERSION}.tar.gz" rm -rf "NuRaft-${NURAFT_VERSION}-${CMAKE_BUILD_TYPE}" -tar xzvf v${NURAFT_VERSION}.tar.gz -rm v${NURAFT_VERSION}.tar.gz -mv NuRaft-${NURAFT_VERSION} "NuRaft-${NURAFT_VERSION}-${CMAKE_BUILD_TYPE}" +tar xzvf "v${NURAFT_VERSION}.tar.gz" +rm "v${NURAFT_VERSION}.tar.gz" +mv "NuRaft-${NURAFT_VERSION}" "NuRaft-${NURAFT_VERSION}-${CMAKE_BUILD_TYPE}" cd "NuRaft-${NURAFT_VERSION}-${CMAKE_BUILD_TYPE}" ./prepare.sh -if [[ "$BUILD_RELEASE" == "1" ]]; then +if [[ "${BUILD_RELEASE}" == "1" ]]; then # If we're doing a release build, remove the examples and tests rm -rf examples tests mkdir examples @@ -58,12 +58,12 @@ if [[ "$BUILD_RELEASE" == "1" ]]; then fi mkdir -p build cd build -cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DDISABLE_SSL=1 .. -make -j$CPUS static_lib +cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" -DDISABLE_SSL=1 .. +make "-j${CPUS}" static_lib -echo -e "${green}Copying nuraft to $PREFIX/lib and $PREFIX/include${end}" -cp libnuraft.a $PREFIX/lib -cp -r ../include/libnuraft $PREFIX/include +echo -e "${green}Copying nuraft to \"${PREFIX}/lib\" and ${PREFIX}/include${end}" +cp libnuraft.a "${PREFIX}/lib" +cp -r ../include/libnuraft "${PREFIX}/include" cd ../.. @@ -72,63 +72,63 @@ rm -rf lua-5.4.3 tar zxf lua-5.4.3.tar.gz rm -rf lua-5.4.3.tar.gz cd lua-5.4.3 -make -j$CPUS -make INSTALL_TOP=$PREFIX install +make "-j${CPUS}" +make "INSTALL_TOP=${PREFIX}" install cd .. -if [[ "$OSTYPE" != "darwin"* ]]; then +if [[ "${OSTYPE}" != "darwin"* ]]; then # For Mac Silicon: this curl install creates problems for building tools/bench/parsec/evm/ CURL_VERSION="7.83.1" - wget https://curl.se/download/curl-${CURL_VERSION}.tar.gz - rm -rf curl-${CURL_VERSION} - tar xzvf curl-${CURL_VERSION}.tar.gz - rm -rf curl-${CURL_VERSION}.tar.gz - mkdir -p curl-${CURL_VERSION}/build - cd curl-${CURL_VERSION}/build + wget "https://curl.se/download/curl-${CURL_VERSION}.tar.gz" + rm -rf "curl-${CURL_VERSION}" + tar xzvf "curl-${CURL_VERSION}.tar.gz" + rm -rf "curl-${CURL_VERSION}.tar.gz" + mkdir -p "curl-${CURL_VERSION}/build" + cd "curl-${CURL_VERSION}/build" ../configure --prefix="${PREFIX}" --disable-shared --without-ssl --without-libpsl --without-libidn2 --without-brotli --without-zstd --without-zlib - make -j$CPUS + make "-j${CPUS}" make install cd ../.. fi JSONCPP_VERSION="1.9.5" wget https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/${JSONCPP_VERSION}.tar.gz -rm -rf jsoncpp-${JSONCPP_VERSION} -tar xzvf ${JSONCPP_VERSION}.tar.gz -rm -rf ${JSONCPP_VERSION}.tar.gz -mkdir -p jsoncpp-${JSONCPP_VERSION}/build -cd jsoncpp-${JSONCPP_VERSION}/build +rm -rf "jsoncpp-${JSONCPP_VERSION}" +tar xzvf "${JSONCPP_VERSION}.tar.gz" +rm -rf "${JSONCPP_VERSION}.tar.gz" +mkdir -p "jsoncpp-${JSONCPP_VERSION}/build" +cd "jsoncpp-${JSONCPP_VERSION}/build" cmake .. -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DBUILD_SHARED_LIBS=NO -DBUILD_STATIC_LIBS=YES -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF -make -j$CPUS +make "-j${CPUS}" make install cd ../.. # NOTE: evmc v10.0.0 requires evmone v0.9.0 # evmc v10.1.1 requires evmone v0.10.0 (which requires c++20) EVMC_VER=10.0.0 -wget https://github.com/ethereum/evmc/archive/refs/tags/v${EVMC_VER}.zip -rm -rf evmc-${EVMC_VER} -unzip v${EVMC_VER}.zip -rm v${EVMC_VER}.zip -cd evmc-${EVMC_VER} +wget "https://github.com/ethereum/evmc/archive/refs/tags/v${EVMC_VER}.zip" +rm -rf "evmc-${EVMC_VER}" +unzip "v${EVMC_VER}.zip" +rm "v${EVMC_VER}.zip" +cd "evmc-${EVMC_VER}" mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" .. -make -j$CPUS +make "-j${CPUS}" make install cd ../.. # NOTE: updating evmone to v0.10.0 requires c++20 EVMONE_VER=0.9.1 -wget https://github.com/ethereum/evmone/archive/refs/tags/v${EVMONE_VER}.zip -rm -rf evmone-${EVMONE_VER} -unzip v${EVMONE_VER}.zip -rm v${EVMONE_VER}.zip -cd evmone-${EVMONE_VER} +wget "https://github.com/ethereum/evmone/archive/refs/tags/v${EVMONE_VER}.zip" +rm -rf "evmone-${EVMONE_VER}" +unzip "v${EVMONE_VER}.zip" +rm "v${EVMONE_VER}.zip" +cd "evmone-${EVMONE_VER}" rm -rf evmc -mv ../evmc-${EVMC_VER} ./evmc +mv "../evmc-${EVMC_VER}" ./evmc mkdir ./evmc/.git -if [[ "$OSTYPE" == "darwin"* ]]; then +if [[ "${OSTYPE}" == "darwin"* ]]; then # Mac Silicon: clang 'ar' does not allow empty member list, fails w/ -DBUILD_SHARED_LIBS=OFF cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${PREFIX}" else @@ -138,7 +138,7 @@ cmake --build build --parallel cd build make install cd ../.. -rm -rf evmone-${EVMONE_VER} +rm -rf "evmone-${EVMONE_VER}" wget https://github.com/chfast/ethash/archive/e3e002ecc25ca699349aa62fa38e7b7cc5f653af.zip rm -rf ethash-e3e002ecc25ca699349aa62fa38e7b7cc5f653af @@ -149,8 +149,8 @@ mkdir build cd build cmake -DETHASH_BUILD_ETHASH=OFF -DETHASH_BUILD_TESTS=OFF .. cmake --build . --parallel -cp ./lib/keccak/libkeccak.a $PREFIX/lib -cp -r ../include/ethash $PREFIX/include +cp ./lib/keccak/libkeccak.a "${PREFIX}/lib" +cp -r ../include/ethash "${PREFIX}/include" cd ../.. wget https://gnu.askapache.com/libmicrohttpd/libmicrohttpd-0.9.75.tar.gz @@ -160,8 +160,11 @@ rm libmicrohttpd-0.9.75.tar.gz cd libmicrohttpd-0.9.75 mkdir build cd build -../configure --prefix="${PREFIX}" --disable-curl --disable-examples --disable-doc --disable-shared --disable-https -make -j $CPUS +../configure "--prefix=${PREFIX}" --disable-curl --disable-examples --disable-doc --disable-shared --disable-https +make -j "${CPUS}" make install cd ../../ rm -rf libmicrohttpd-0.9.75 + +echo; echo "Setup dependencies complete." +echo "Next run './scripts/build.sh'"; echo