Skip to content

Commit

Permalink
Merge pull request #1 from whilei/build-script
Browse files Browse the repository at this point in the history
Build script
  • Loading branch information
r8d8 authored Jan 8, 2018
2 parents d98abb2 + 8168e3f commit d5a1edd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
4 changes: 3 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env bash

set -e

LDFLAGS="$1" "$2"
BINARY="$3"
FOLDERS=$(ls cmd)

for CMD in $FOLDERS;
do
echo "Building $CMD..."
echo "Building $BINARY/$CMD..."
go build $LDFLAGS -o $BINARY/$CMD ./cmd/$CMD
done
63 changes: 51 additions & 12 deletions scripts/build_sputnikvm.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

OS='Unknown OS'
case "$(uname -s)" in
Darwin)
Expand All @@ -16,32 +18,69 @@ case "$(uname -s)" in
exit;;
esac

if ["$OS" == "Windows"]; then
if [ "$OS" == "Windows" ]; then
cd %GOPATH%\src\github.com\ethereumproject
git clone https://github.com/ethereumproject/sputnikvm-ffi
cd sputnikvm-ffi\c\ffi
# Check if git is happening in svm-ffi.
if [ -d "%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi" ]; then
cd sputnikvm-ffi
if [ -d "%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\.git" ]; then
remote_name=$(git remote -v | head -1 | awk '{print $1;}')
if [ ! "%remote_name%" == "" ]; then
echo "Updating SputnikVM FFI from branch [%remote_name%]..."
git pull %remote_name% master
fi
fi
cd c\ffi
else
git clone https://github.com/ethereumproject/sputnikvm-ffi.git
cd sputnikvm-ffi\c\ffi
fi
cargo build --release
copy %GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\c\ffi\target\release\sputnikvm.lib \
%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\c\sputnikvm.lib

cd %GOPATH%\src\github.com\ethereumproject\go-ethereum\cmd\geth
set CGO_LDFLAGS=-Wl,--allow-multiple-definition \
%GOPATH%\src\github.com\ethereumproject\sputnikvm-ffi\c\sputnikvm.lib -lws2_32 -luserenv
go build -tags=sputnikvm .
mkdir -p %GOPATH%\src\github.com\ethereumproject\go-ethereum\bin
go build -o %GOPATH%\src\github.com\ethereumproject\go-ethereum\bin\geth -tags=sputnikvm .
else
cd $GOPATH/src/github.com/ethereumproject
git clone https://github.com/ethereumproject/sputnikvm-ffi
cd sputnikvm-ffi/c/ffi
ep_gopath=$GOPATH/src/github.com/ethereumproject
sputnikffi_path="$ep_gopath/sputnikvm-ffi"

# If sputnikvmffi has already been cloned/existing
if [ -d "$sputnikffi_path" ]; then
# Ensure git is happening in svm-ffi.
# Update if .git exists, otherwise don't try updating. We could possibly handle git-initing and adding remote but seems
# like an edge case.
if [ -d "$sputnikffi_path/.git" ]; then
cd $sputnikffi_path
remote_name=$(git remote -v | head -1 | awk '{print $1;}')
if [ ! "$remote_name" == "" ]; then
echo "Updating SputnikVM FFI from branch [$remote_name]..."
git pull "$remote_name" master
fi
fi
else
echo "Cloning SputnikVM FFI..."
cd $ep_gopath
git clone https://github.com/ethereumproject/sputnikvm-ffi.git
fi
cd "$sputnikffi_path/c/ffi"
echo "Building SputnikVM FFI..."
cargo build --release
cp $GOPATH/src/github.com/ethereumproject/sputnikvm-ffi/c/ffi/target/release/libsputnikvm_ffi.a \
$GOPATH/src/github.com/ethereumproject/sputnikvm-ffi/c/libsputnikvm.a
cp $sputnikffi_path/c/ffi/target/release/libsputnikvm_ffi.a \
$sputnikffi_path/c/libsputnikvm.a

if ["$OS" == "Linux"]; then
geth_binpath="$ep_gopath/go-ethereum/bin"
echo "Building geth to $geth_binpath/geth..."
mkdir -p "$geth_binpath"
if [ "$OS" == "Linux" ]; then
cd $GOPATH/src/github.com/ethereumproject/go-ethereum/cmd/geth
CGO_LDFLAGS="$GOPATH/src/github.com/ethereumproject/sputnikvm-ffi/c/libsputnikvm.a -ldl" go build -tags=sputnikvm .
CGO_LDFLAGS="$sputnikffi_path/c/libsputnikvm.a -ldl" go build -o $geth_binpath/geth -tags=sputnikvm .
else
cd $GOPATH/src/github.com/ethereumproject/go-ethereum/cmd/geth
CGO_LDFLAGS="$GOPATH/src/github.com/ethereumproject/sputnikvm-ffi/c/libsputnikvm.a -ldl -lresolv" go build -tags=sputnikvm .
CGO_LDFLAGS="$sputnikffi_path/c/libsputnikvm.a -ldl -lresolv" go build -o $geth_binpath/geth -tags=sputnikvm .
fi
fi

0 comments on commit d5a1edd

Please sign in to comment.