Skip to content

Commit

Permalink
Merge pull request #338 from fioprotocol/develop
Browse files Browse the repository at this point in the history
Ubuntu 20 and 22 Upgrade (BD-4617)
  • Loading branch information
misterleet authored Jun 4, 2024
2 parents ea07cd9 + f7b2423 commit 1d8717d
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 20 deletions.
20 changes: 20 additions & 0 deletions .build_vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CMAKE
export CMAKE_BUILD_TYPE=Release
export CMAKE_VERSION_MAJOR=3
export CMAKE_VERSION_MINOR=21
export CMAKE_VERSION_PATCH=7
export CMAKE_VERSION=${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}.${CMAKE_VERSION_PATCH}
export CMAKE_INSTALL_DIR=${FIO_CNTRX_APTS_DIR}

# FIO.CDT
export CDT_VERSION_MAJOR=1
export CDT_VERSION_MINOR=5
export CDT_VERSION_PATCH=0
export CDT_VERSION=${CDT_VERSION_MAJOR}.${CDT_VERSION_MINOR}.${CDT_VERSION_PATCH}

export FIO_CDT_INSTALL_DIR=${FIO_CDT_INSTALL_DIR:-/usr/local}

# GENERAL
export CURRENT_USER=${CURRENT_USER:-$(whoami)}
export DRYRUN=${DRYRUN:-false}
export VERBOSE=${VERBOSE:-false}
21 changes: 21 additions & 0 deletions .environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export REPO_ROOT=$(realpath "${SCRIPT_DIR}")
export BUILD_DIR="${REPO_ROOT}/build"

export CMAKE_REQUIRED_VERSION=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*cmake_minimum_required[[:blank:]]*\([[:blank:]]*VERSION" | tail -1 | sed 's/.*VERSION //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1)

export FIO_CNTRX_VERSION_MAJOR=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_MAJOR" | tail -1 | sed 's/.*VERSION_MAJOR //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1)
export FIO_CNTRX_VERSION_MINOR=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_MINOR" | tail -1 | sed 's/.*VERSION_MINOR //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1)
export FIO_CNTRX_VERSION_PATCH=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_PATCH" | tail -1 | sed 's/.*VERSION_PATCH //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1)
export FIO_CNTRX_VERSION_SUFFIX=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_SUFFIX" | tail -1 | sed 's/.*VERSION_SUFFIX //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1)
export FIO_CNTRX_VERSION="${FIO_CNTRX_VERSION_MAJOR}.${FIO_CNTRX_VERSION_MINOR}"
if [[ -z $FIO_CNTRX_VERSION_SUFFIX ]]; then
export FIO_CNTRX_VERSION_FULL="${FIO_CNTRX_VERSION_MAJOR}.${FIO_CNTRX_VERSION_MINOR}.${FIO_CNTRX_VERSION_PATCH}"
else
export FIO_CNTRX_CNTRX_VERSION_FULL="${FIO_CNTRX_VERSION_MAJOR}.${FIO_CNTRX_VERSION_MINOR}.${FIO_CNTRX_VERSION_PATCH}-${FIO_CNTRX_VERSION_SUFFIX}"
fi

export TEMP_DIR="${TEMP_DIR:-${HOME}/tmp}"
export FIO_CNTRX_APTS_DIR="${FIO_APTS_DIR:-${TEMP_DIR}/fio/apts}"

. ./.build_vars
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The included icons are provided under the same terms as the software and accompa
## Build Information
The build script is located in main directory. Note that smart contracts are NOT installed per say; they are uploaded to the chain via clio, if a development chain, or via a multi-sig if a production chain.

### Build FIO smart contract
### Build
The build script is straight-forward; it checks for any dependencies, then builds the contracts, putting the artifacts into the build directory.

To build, first change to the `~/fioprotocol/fio.contracts` folder, then execute the script as follows:
Expand All @@ -52,7 +52,7 @@ The build process writes all content to the `build` folder.

### Dependencies:
[fio.cdt](https://github.com/fioprotocol/fio.cdt/tree/release/1.5.x)
fio.cdt, version 1.5.x, must be installed onto the build machine in order for the contracts to successfully build. This can be done by cloning the fio.cdt repo, then running build.sh and install.sh. Note that the fio.cdt artifacts are installed into `/usr/local` under the folder eosio.cdt and links are created to these artifacts in `/usr/local/bin`. Note: fio.cdt is a customized version of eosio.cdt but as such any installed artifacts retain the prefix of eosio.
fio.cdt, version 1.5.x, must be installed onto the build machine in order for the contracts to successfully build. As such, the fio.contracts build script will automatically install the cdt (contract development toolkit), however, a manual build may be done by cloning the fio.cdt repo, then running build.sh and install.sh. Note that the fio.cdt artifacts are installed into `/usr/local` under the folder eosio.cdt and links are created to these artifacts in `/usr/local/bin`. Note: fio.cdt is a customized version of eosio.cdt but as such any installed artifacts retain the prefix of eosio.

[fio](https://github.com/fioprotocol/fio/)
While the FIO core blockchain is not a direct dependency of fio.contracts, in order to successfully execute contract functionality, getters may be called that are part of the blockchain. FIO contracts are backward compatible* to multiple versions of the blockchain. The latest release of fio.contracts aligns to the latest release of the fio.blockchain. The latest release may be found [here](https://github.com/fioprotocol/fio/releases).
Expand Down
177 changes: 159 additions & 18 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,165 @@
#! /bin/bash
#!/usr/bin/env bash

printf "\t=========== Building FIO system contracts ===========\n\n"
function usage() {
printf "Usage: $0 OPTION...
-c DIR Directory where CMAKE install is located
\\n" "$0" 1>&2
exit 1
}

CLEAN=${CLEAN:-false}
DEBUG=${DEBUG:-false}
VERBOSE=${VERBOSE:-false}

TIME_BEGIN=$(date -u +%s)
if [ $# -ne 0 ]; then
while getopts "a:cdhv" opt; do
case "${opt}" in
a)
APTS_DIR=$OPTARG
;;
c)
CLEAN=true
;;
d)
DEBUG=true
set -x
;;
v)
VERBOSE=true
;;
h)
usage
;;
?)
echo "Invalid Option!" 1>&2
usage
;;
:)
echo "Invalid Option: -${OPTARG} requires an argument." 1>&2
usage
;;
*)
usage
;;
esac
done
fi

SCRIPT_VERSION=2.10

export CURRENT_WORKING_DIR=$(pwd) # relative path support

export CLEAN
export DEBUG
export VERBOSE

# Obtain dependency versions; Must come first in the script
. ./.environment

# Load general helpers
. ./utils.sh

echo
echo "FIO Contracts Build Script Version: ${SCRIPT_VERSION}"
echo "FIO Contracts Version: ${FIO_CNTRX_VERSION_FULL}"
echo "$(date -u)"
echo "User: ${CURRENT_USER}"
# echo "git head id: %s" "$( cat .git/refs/heads/master )"
echo "Current branch: $(execute git rev-parse --abbrev-ref HEAD 2>/dev/null)"

# Checks for Arch and OS + Support for tests setting them manually
## Necessary for linux exclusion while running bats tests/bash-bats/*.sh
[[ -z "${ARCH}" ]] && export ARCH=$(uname)
if [[ -z "${NAME}" ]]; then
if [[ $ARCH == "Linux" ]]; then
[[ ! -e /etc/os-release ]] && echo "${COLOR_RED} - /etc/os-release not found! It seems you're attempting to use an unsupported Linux distribution.${COLOR_NC}" && exit 1
# Obtain OS NAME, and VERSION
. /etc/os-release
elif [[ $ARCH == "Darwin" ]]; then
export NAME=$(sw_vers -productName)
else
echo " ${COLOR_RED}- FIO is not supported for your Architecture!${COLOR_NC}" && exit 1
fi
set-system-vars
fi

echo
echo "Performing OS/System Validation..."
([[ $NAME == "Ubuntu" ]] && ([[ "$(echo ${VERSION_ID})" == "18.04" ]] || [[ "$(echo ${VERSION_ID})" == "20.04" ]] || [[ "$(echo ${VERSION_ID})" == "22.04" ]])) || (echo " - You must be running 18.04.x, 20.04.x, or 22.04 to build the FIO Contracts." && exit 1)

# Set up the working directories for build, etc
setup

# CMAKE Installation
# cmake may have been passed as arg to build or previously installed in local apts dir, check these and set if appropriate
export CMAKE=
([[ -z "${CMAKE}" ]] && [[ -d ${APTS_DIR} ]] && [[ -x ${APTS_DIR}/bin/cmake ]]) && export CMAKE=${APTS_DIR}/bin/cmake
([[ -z "${CMAKE}" ]] && [[ -d ${FIO_CNTRX_APTS_DIR} ]] && [[ -x ${FIO_CNTRX_APTS_DIR}/bin/cmake ]]) && export CMAKE=${FIO_CNTRX_APTS_DIR}/bin/cmake && export APTS_DIR=${FIO_CNTRX_APTS_DIR}
if [[ $ARCH == "Darwin" ]]; then
([[ -z "${CMAKE}" ]] && [[ ! -z $(command -v cmake 2>/dev/null) ]]) && export CMAKE=$(command -v cmake 2>/dev/null) && export CMAKE_CURRENT_VERSION=$($CMAKE --version | grep -E "cmake version[[:blank:]]*" | sed 's/.*cmake version //g')

# If it exists, check that it's > required version +
if [[ ! -z $CMAKE_CURRENT_VERSION ]] && [[ $((10#$(echo $CMAKE_CURRENT_VERSION | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'))) -lt $((10#$(echo $CMAKE_REQUIRED_VERSION | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'))) ]]; then
echo "${COLOR_RED}The currently installed cmake version ($CMAKE_CURRENT_VERSION) is less than the required version ($CMAKE_REQUIRED_VERSION). Cannot proceed."
exit 1
fi
fi
ensure-cmake
[[ ! -x "${CMAKE}" ]] && echo "CMake not found! Exiting..." && exit 1

ensure-cdt
if ! hash eosio-cpp 2>/dev/null; then
echo "The FIO Contract Development Toolkit is not installed (not found in PATH)! Either update PATH or"
echo "perform the following steps to clone, build and install the fio.cdt suite;"
echo " git clone https://www.github.com/fioprotocol/fio.cdt.git"
echo " cd fio.cdt"
echo " git submodule update --init --recursive"
echo " ./build.sh"
echo " sudo ./install.sh"
echo
exit 1
fi

echo
printf "\t=========== Building FIO Contracts ===========\n\n"

RED='\033[0;31m'
NC='\033[0m'

CORES=`getconf _NPROCESSORS_ONLN`
mkdir -p build
pushd build &> /dev/null
cmake ../
make -j${CORES}
popd &> /dev/null

printf "\t=========== Copying FIO source abi ===========\n\n"
cp contracts/fio.address/fio.address.abi build/contracts/fio.address/
cp contracts/fio.fee/fio.fee.abi build/contracts/fio.fee/
cp contracts/fio.request.obt/fio.request.obt.abi build/contracts/fio.request.obt/
cp contracts/fio.tpid/fio.tpid.abi build/contracts/fio.tpid/
cp contracts/fio.treasury/fio.treasury.abi build/contracts/fio.treasury/
cp contracts/fio.escrow/fio.escrow.abi build/contracts/fio.escrow/
cp contracts/fio.staking/fio.staking.abi build/contracts/fio.staking/
cp contracts/fio.oracle/fio.oracle.abi build/contracts/fio.oracle/
cp contracts/fio.perms/fio.perms.abi build/contracts/fio.perms/
pushd build

${CMAKE} ../
make -j${JOBS}
popd

printf "\t=========== Copying FIO Contracts ABIs ===========\n\n"

execute cp contracts/fio.address/fio.address.abi build/contracts/fio.address/
execute cp contracts/fio.fee/fio.fee.abi build/contracts/fio.fee/
execute cp contracts/fio.request.obt/fio.request.obt.abi build/contracts/fio.request.obt/
execute cp contracts/fio.tpid/fio.tpid.abi build/contracts/fio.tpid/
execute cp contracts/fio.treasury/fio.treasury.abi build/contracts/fio.treasury/
execute cp contracts/fio.escrow/fio.escrow.abi build/contracts/fio.escrow/
execute cp contracts/fio.staking/fio.staking.abi build/contracts/fio.staking/
execute cp contracts/fio.oracle/fio.oracle.abi build/contracts/fio.oracle/
execute cp contracts/fio.perms/fio.perms.abi build/contracts/fio.perms/
echo
printf "\t=========== FIO Contracts Build Complete ===========\n\n"
echo
printf "${bldred}\n"
printf " ___ ___ \n"
printf " /\\__\\ /\\ \\ \n"
printf " /:/ _/_ ___ /::\\ \\ \n"
printf " /:/ /\\__\\ /\\__\\ /:/\\:\\ \\ \n"
printf " /:/ /:/ / /:/__/ /:/ \\:\\ \\ \n"
printf " /:/_/:/ / /::\\ \\ /:/__/ \\:\\__\\ \n"
printf " \\:\\/:/ / \\/\\:\\ \\__ \\:\\ \\ /:/ / \n"
printf " \\::/__/ \\:\\/\\__\\ \\:\\ /:/ / \n"
printf " \\:\\ \\ \\::/ / \\:\\/:/ / \n"
printf " \\:\\__\\ /:/ / \\::/ / \n"
printf " \\/__/ \\/__/ \\/__/ \n\n${txtrst}"

printf "\\tFor more information:\\n"
printf "\\tFIO website: https://fio.net\\n"
Loading

0 comments on commit 1d8717d

Please sign in to comment.