Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from sergmetelin/master
Browse files Browse the repository at this point in the history
Merge build.sh and eoscpp.
  • Loading branch information
satyapravin authored Sep 13, 2017
2 parents eec8b9f + 45ead96 commit 2a0ce3b
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 38 deletions.
71 changes: 71 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

##########################################################################
# This is EOS bootstrapper script for Linux and OS X.
# This file was downloaded from https://github.com/EOSIO/eos
# Feel free to change this file to fit your needs.
##########################################################################

VERSION=1.0

# Define directories.
WORK_DIR=$PWD
BUILD_DIR=${WORK_DIR}/build
TEMP_DIR=/tmp
BINARYEN_BIN=/opt/binaryen/bin/
OPENSSL_ROOT_DIR=/usr/local/opt/openssl
OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
WASM_LLVM_CONFIG=/opt/wasm/bin/llvm-config

# Target architectures
ARCH=$1
TARGET_ARCHS="ubuntu darwin"

# Check ARCH
if [[ $# > 1 ]]; then
echo ""
echo "Error: too many arguments"
exit 1
fi

if [[ $# < 1 ]]; then
echo ""
echo "Usage: bash build.sh TARGET"
echo ""
echo "Targets: $TARGET_ARCHS"
exit 1
fi

if [[ $ARCH =~ [[:space:]] || ! $TARGET_ARCHS =~ (^|[[:space:]])$ARCH([[:space:]]|$) ]]; then
echo ""
echo ">>> WRONG ARCHITECTURE \"$ARCH\""
exit 1
fi

echo ""
echo ">>> ARCHITECTURE \"$ARCH\""

# Debug flags
INSTALL_DEPS=1
COMPILE_EOS=1
COMPILE_CONTRACTS=1

# Define default arguments.
CMAKE_BUILD_TYPE=Debug

# Install dependencies
if [ ${INSTALL_DEPS} == "1" ]; then

print ">> Install dependencies"
. ${WORK_DIR}/scripts/install_dependencies.sh

fi

# Create the build dir
cd ${WORK_DIR}
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}

# Build EOS
cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DWASM_LLVM_CONFIG=${WASM_LLVM_CONFIG} -DBINARYEN_BIN=${BINARYEN_BIN} -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES} ..
make -j4
106 changes: 106 additions & 0 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Install dependencies script

if [ $ARCH == "ubuntu" ]; then
# install dev toolkit
sudo apt-get update
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get install clang-4.0 lldb-4.0 cmake make \
libbz2-dev libssl-dev libgmp3-dev \
autotools-dev build-essential \
libbz2-dev libicu-dev python-dev \
autoconf libtool git
OPENSSL_ROOT_DIR=/usr/local/opt/openssl
OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib

# install boost
cd ${TEMP_DIR}
export BOOST_ROOT=${HOME}/opt/boost_1_64_0
curl -L https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.bz2 > boost_1.64.0.tar.bz2
tar xvf boost_1.64.0.tar.bz2
cd boost_1_64_0/
./bootstrap.sh "--prefix=$BOOST_ROOT"
./b2 install
rm -rf ${TEMP_DIR}/boost_1_64_0/

# install secp256k1-zkp (Cryptonomex branch)
cd ${TEMP_DIR}
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install
rm -rf cd ${TEMP_DIR}/secp256k1-zkp

# install binaryen
cd ${TEMP_DIR}
git clone https://github.com/WebAssembly/binaryen
cd binaryen
git checkout tags/1.37.14
cmake . && make
mkdir -p ${HOME}/opt/binaryen/
mv ${TEMP_DIR}/binaryen/bin ${HOME}/opt/binaryen/
rm -rf ${TEMP_DIR}/binaryen
BINARYEN_BIN=${HOME}/opt/binaryen/bin

# build llvm with wasm build target:
cd ${TEMP_DIR}
mkdir wasm-compiler
cd wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=${HOME}/opt/wasm -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install
rm -rf ${TEMP_DIR}/wasm-compiler
WASM_LLVM_CONFIG=${HOME}/opt/wasm/bin/llvm-config
fi

if [ $ARCH == "darwin" ]; then
DEPS="git automake libtool boost openssl llvm@4 gmp wget"
brew update
brew install --force $DEPS
brew unlink $DEPS && brew link --force $DEPS
# LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm

# install secp256k1-zkp (Cryptonomex branch)
cd ${TEMP_DIR}
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install
rm -rf cd ${TEMP_DIR}/secp256k1-zkp

# Install binaryen v1.37.14:
cd ${TEMP_DIR}
git clone https://github.com/WebAssembly/binaryen
cd binaryen
git checkout tags/1.37.14
cmake . && make
mkdir /usr/local/binaryen
mv ${TEMP_DIR}/binaryen/bin /usr/local/binaryen
ln -s /usr/local/binaryen/bin/* /usr/local
rm -rf ${TEMP_DIR}/binaryen
BINARYEN_BIN=/usr/local/binaryen/bin/

# Build LLVM and clang for WASM:
cd ${TEMP_DIR}
mkdir wasm-compiler
cd wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local/wasm -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install
rm -rf ${TEMP_DIR}/wasm-compiler
WASM_LLVM_CONFIG=/usr/local/wasm/bin/llvm-config

fi
72 changes: 34 additions & 38 deletions tools/eoscpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

function copy_skeleton {
cp -r /home/ubuntu/eos/contracts/skeleton/. $newname
cp -r @CMAKE_SOURCE_DIR@/contracts/skeleton/. $newname

for file in $(find ./$newname -name 'skeleton.*')
do
Expand All @@ -11,9 +11,6 @@ function copy_skeleton {
}

function build_contract {
output=$1
shift

workdir=`mktemp -d`
mkdir $workdir/built

Expand All @@ -26,60 +23,59 @@ function build_contract {

@WASM_LLVM_LINK@ -o $workdir/linked.bc $workdir/built/*
@WASM_LLC@ --asm-verbose=false -o $workdir/assembly.s $workdir/linked.bc
@BINARYEN_BIN@/s2wasm -o $output -s 16384 $workdir/assembly.s
@BINARYEN_BIN@/s2wasm -o $outname -s 16384 $workdir/assembly.s

rm -rf $workdir
}

function print_help {
echo "Usage: $0 output.wast contract.cpp [other.cpp ...]"
echo "Usage: $0 -o output.wast contract.cpp [other.cpp ...]"
echo " OR"
echo " $0 -n mycontract"
echo
echo "Options:"
echo " -n | --newcontract [name]"
echo " Create a new contract in the [name] folder, based on the example contract"
echo " OR"
echo " -o | --outname [output.wast] [input.cpp ...]"
echo " Generate the wast output file based on input cpp files"
}

OPTIONS=$(getopt --options=hn: --longoptions=help,newcontract: --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
# getopt failed
exit 2
fi

eval set -- "$OPTIONS"
command=""

while true; do
case "$1" in
-n|--newcontract)
newname=$2
shift 2
;;
-h|--help)
print_help
exit 1
;;
--)
shift
break
;;
*)
echo "Unrecognized option: $1"
exit 1
;;
esac
done
while [[ $# -gt 1 ]]
do
key="$1"

if [[ "x" == "x$newname" ]]; then
if [[ $# -le 1 ]]; then
case $key in
-n|--newcontract)
newname="$2"
command="newcontract"
shift 2
;;
-h|--help)
print_help
;;
-o|--outname)
outname="$2"
command="outname"
shift 2
break
;;
*)
echo "Unrecognized option: $1"
exit 1
fi
;;
esac
done

if [[ "outname" == "$command" ]]; then
build_contract $@
else
if [[ $# -ne 0 ]]; then
if [[ "newcontract" == "$command" ]]; then
copy_skeleton
else
print_help
exit 1
fi
copy_skeleton $newname
fi

0 comments on commit 2a0ce3b

Please sign in to comment.