From 36364a5e1e4d2545a1840ab7b7e2dcf4e94301f9 Mon Sep 17 00:00:00 2001 From: Sammy Libre Date: Sat, 9 Sep 2017 22:24:42 +0500 Subject: [PATCH] Add new build system --- .gitignore | 4 ++- CMakeLists.txt | 9 ++++++- README.md | 14 ++--------- build/env.sh | 32 ++++++++++++++++++++++++ main.go | 4 +-- {go-pool/pool => pool}/pool.go | 0 {go-pool/rpc => rpc}/rpc.go | 2 +- {go-pool/stratum => stratum}/api.go | 4 +-- {go-pool/stratum => stratum}/blocks.go | 2 +- {go-pool/stratum => stratum}/handlers.go | 2 +- {go-pool/stratum => stratum}/miner.go | 6 ++--- {go-pool/stratum => stratum}/mmap.go | 0 {go-pool/stratum => stratum}/proto.go | 0 {go-pool/stratum => stratum}/stratum.go | 6 ++--- {go-pool/util => util}/util.go | 2 +- {go-pool/util => util}/util_test.go | 0 16 files changed, 59 insertions(+), 28 deletions(-) create mode 100755 build/env.sh rename {go-pool/pool => pool}/pool.go (100%) rename {go-pool/rpc => rpc}/rpc.go (98%) rename {go-pool/stratum => stratum}/api.go (98%) rename {go-pool/stratum => stratum}/blocks.go (97%) rename {go-pool/stratum => stratum}/handlers.go (98%) rename {go-pool/stratum => stratum}/miner.go (97%) rename {go-pool/stratum => stratum}/mmap.go (100%) rename {go-pool/stratum => stratum}/proto.go (100%) rename {go-pool/stratum => stratum}/stratum.go (98%) rename {go-pool/util => util}/util.go (96%) rename {go-pool/util => util}/util_test.go (100%) diff --git a/.gitignore b/.gitignore index 15a3fe5..515cf56 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,6 @@ Makefile config.json testnet.json mainnet.json -pool + +/build/_workspace/ +/build/bin/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 56c3805..da34151 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 2.8.11) -project (pool) +project(pool) if (DEFINED ENV{MONERO_DIR}) get_filename_component(MONERO_DIR $ENV{MONERO_DIR} ABSOLUTE) @@ -11,3 +11,10 @@ endif() add_subdirectory(hashing) add_subdirectory(cnutil) + +add_custom_command( + OUTPUT build/bin + COMMAND build/env.sh go get -v ./... +) + +add_custom_target(build ALL DEPENDS hashing cnutil ${CMAKE_CURRENT_BINARY_DIR}/build/bin) diff --git a/README.md b/README.md index ec2c800..20053af 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,6 @@ Compile Monero source (with shared libraries option): Install Golang and required packages: sudo apt-get install golang - export GOPATH=~/go - go get github.com/goji/httpauth - go get github.com/yvasiyarov/gorelic - go get github.com/gorilla/mux Clone stratum: @@ -52,7 +48,6 @@ Build stratum: MONERO_DIR=/path/to/monero cmake . make - go build -o pool main.go `MONERO_DIR=/path/to/monero` is optional, not needed if both `monero` and `monero-stratum` is in the same directory like `/opt/src/`. By default make will search for monero libraries in `../monero`. You can just run `cmake .`. @@ -69,10 +64,6 @@ Compile Monero source: Install Golang and required packages: brew update && brew install go - export GOPATH=~/go - go get github.com/goji/httpauth - go get github.com/yvasiyarov/gorelic - go get github.com/gorilla/mux Clone stratum: @@ -83,16 +74,15 @@ Build stratum: MONERO_DIR=/path/to/monero cmake . make - go build -o pool main.go ### Running Stratum - ./pool config.json + ./build/bin/monero-stratum config.json If you need to bind to privileged ports and don't want to run from `root`: sudo apt-get install libcap2-bin - sudo setcap 'cap_net_bind_service=+ep' pool + sudo setcap 'cap_net_bind_service=+ep' /path/to/monero-stratum ## Configuration diff --git a/build/env.sh b/build/env.sh new file mode 100755 index 0000000..903c0fe --- /dev/null +++ b/build/env.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +if [ ! -f "build/env.sh" ]; then + echo "$0 must be run from the root of the repository." + exit 2 +fi + +# Create fake Go workspace if it doesn't exist yet. +workspace="$PWD/build/_workspace" +root="$PWD" +ethdir="$workspace/src/github.com/sammy007" +if [ ! -L "$ethdir/monero-stratum" ]; then + mkdir -p "$ethdir" + cd "$ethdir" + ln -s ../../../../../. monero-stratum + cd "$root" +fi + +# Set up the environment to use the workspace. +# Also add Godeps workspace so we build using canned dependencies. +GOPATH="$workspace" +GOBIN="$PWD/build/bin" +export GOPATH GOBIN + +# Run the command inside the workspace. +cd "$ethdir/monero-stratum" +PWD="$ethdir/monero-stratum" + +# Launch the arguments with the configured environment. +exec "$@" diff --git a/main.go b/main.go index e09c944..71abda5 100644 --- a/main.go +++ b/main.go @@ -10,8 +10,8 @@ import ( "runtime" "time" - "./go-pool/pool" - "./go-pool/stratum" + "github.com/sammy007/monero-stratum/pool" + "github.com/sammy007/monero-stratum/stratum" "github.com/goji/httpauth" "github.com/gorilla/mux" diff --git a/go-pool/pool/pool.go b/pool/pool.go similarity index 100% rename from go-pool/pool/pool.go rename to pool/pool.go diff --git a/go-pool/rpc/rpc.go b/rpc/rpc.go similarity index 98% rename from go-pool/rpc/rpc.go rename to rpc/rpc.go index 40a3dc9..b26fe96 100644 --- a/go-pool/rpc/rpc.go +++ b/rpc/rpc.go @@ -11,7 +11,7 @@ import ( "sync/atomic" "time" - "../pool" + "github.com/sammy007/monero-stratum/pool" ) type RPCClient struct { diff --git a/go-pool/stratum/api.go b/stratum/api.go similarity index 98% rename from go-pool/stratum/api.go rename to stratum/api.go index 4fc8640..f7445ff 100644 --- a/go-pool/stratum/api.go +++ b/stratum/api.go @@ -6,8 +6,8 @@ import ( "sync/atomic" "time" - "../rpc" - "../util" + "github.com/sammy007/monero-stratum/rpc" + "github.com/sammy007/monero-stratum/util" ) func (s *StratumServer) StatsIndex(w http.ResponseWriter, r *http.Request) { diff --git a/go-pool/stratum/blocks.go b/stratum/blocks.go similarity index 97% rename from go-pool/stratum/blocks.go rename to stratum/blocks.go index 7259dc9..37d592d 100644 --- a/go-pool/stratum/blocks.go +++ b/stratum/blocks.go @@ -6,7 +6,7 @@ import ( "encoding/hex" "log" - "../../cnutil" + "github.com/sammy007/monero-stratum/cnutil" ) type BlockTemplate struct { diff --git a/go-pool/stratum/handlers.go b/stratum/handlers.go similarity index 98% rename from go-pool/stratum/handlers.go rename to stratum/handlers.go index 6e5faf5..f7983da 100644 --- a/go-pool/stratum/handlers.go +++ b/stratum/handlers.go @@ -6,7 +6,7 @@ import ( "strings" "sync/atomic" - "../util" + "github.com/sammy007/monero-stratum/util" ) var noncePattern *regexp.Regexp diff --git a/go-pool/stratum/miner.go b/stratum/miner.go similarity index 97% rename from go-pool/stratum/miner.go rename to stratum/miner.go index 5e0195a..e9e3177 100644 --- a/go-pool/stratum/miner.go +++ b/stratum/miner.go @@ -10,9 +10,9 @@ import ( "sync/atomic" "time" - "../../cnutil" - "../../hashing" - "../util" + "github.com/sammy007/monero-stratum/cnutil" + "github.com/sammy007/monero-stratum/hashing" + "github.com/sammy007/monero-stratum/util" ) type Job struct { diff --git a/go-pool/stratum/mmap.go b/stratum/mmap.go similarity index 100% rename from go-pool/stratum/mmap.go rename to stratum/mmap.go diff --git a/go-pool/stratum/proto.go b/stratum/proto.go similarity index 100% rename from go-pool/stratum/proto.go rename to stratum/proto.go diff --git a/go-pool/stratum/stratum.go b/stratum/stratum.go similarity index 98% rename from go-pool/stratum/stratum.go rename to stratum/stratum.go index 851e92f..5097a1b 100644 --- a/go-pool/stratum/stratum.go +++ b/stratum/stratum.go @@ -12,9 +12,9 @@ import ( "sync/atomic" "time" - "../pool" - "../rpc" - "../util" + "github.com/sammy007/monero-stratum/pool" + "github.com/sammy007/monero-stratum/rpc" + "github.com/sammy007/monero-stratum/util" ) type StratumServer struct { diff --git a/go-pool/util/util.go b/util/util.go similarity index 96% rename from go-pool/util/util.go rename to util/util.go index 2bd96d6..775264a 100644 --- a/go-pool/util/util.go +++ b/util/util.go @@ -6,7 +6,7 @@ import ( "time" "unicode/utf8" - "../../cnutil" + "github.com/sammy007/monero-stratum/cnutil" ) var Diff1 = StringToBig("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") diff --git a/go-pool/util/util_test.go b/util/util_test.go similarity index 100% rename from go-pool/util/util_test.go rename to util/util_test.go