From fb30e8e6221bf7831b087c0d60536517602aabae Mon Sep 17 00:00:00 2001 From: Sebastian Johnsson Date: Tue, 10 Mar 2020 04:43:11 +0700 Subject: [PATCH] [compilation] Fix -race compilation (#2432) --- Makefile | 3 +++ scripts/go_executable_build.sh | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8e8fa603c..c9db823fd 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ libs: exe: ./scripts/go_executable_build.sh +race: + ./scripts/go_executable_build.sh -r + test: ./test/debug.sh diff --git a/scripts/go_executable_build.sh b/scripts/go_executable_build.sh index 02462f55b..d76a30006 100755 --- a/scripts/go_executable_build.sh +++ b/scripts/go_executable_build.sh @@ -18,6 +18,7 @@ GOARCH=amd64 FOLDER=/${WHOAMI:-$USER} RACE= VERBOSE= +GO_GCFLAGS="all=-c 2" DEBUG=false NETWORK=main STATIC=false @@ -102,6 +103,7 @@ function build_only BUILTBY=${USER}@ local build=$1 + set_gcflags set -e for bin in "${!SRC[@]}"; do @@ -109,12 +111,12 @@ function build_only rm -f $BINDIR/$bin echo "building ${SRC[$bin]}" if [ "$DEBUG" == "true" ]; then - env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="all=-N -l -c 2" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE ${SRC[$bin]} + env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE ${SRC[$bin]} else if [ "$STATIC" == "true" ]; then - env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="all=-c 2" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY} -w -extldflags \"-static -lm\"" -o $BINDIR/$bin $RACE ${SRC[$bin]} + env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY} -w -extldflags \"-static -lm\"" -o $BINDIR/$bin $RACE ${SRC[$bin]} else - env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="all=-c 2" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE ${SRC[$bin]} + env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE ${SRC[$bin]} fi fi if [ "$(uname -s)" == "Linux" ]; then @@ -145,6 +147,21 @@ function build_only popd } +function set_gcflags +{ + if [[ ! -z "$RACE" ]]; then + if [ "$DEBUG" == "true" ]; then + GO_GCFLAGS="all=-N -l" + else + GO_GCFLAGS="" + fi + else + if [ "$DEBUG" == "true" ]; then + GO_GCFLAGS="all=-N -l -c 2" + fi + fi +} + function upload { AWSCLI=aws @@ -249,7 +266,7 @@ function upload_wallet } ################################ MAIN FUNCTION ############################## -while getopts "hp:a:o:b:f:rvsN:" option; do +while getopts "hp:a:o:b:f:rvsdN:" option; do case $option in h) usage ;; p) PROFILE=$OPTARG ;;