github.com/MetalBlockchain/metalgo@v1.11.9/scripts/build_metal.sh (about) 1 #!/usr/bin/env bash 2 3 set -euo pipefail 4 5 print_usage() { 6 printf "Usage: build_metal [OPTIONS] 7 8 Build metalgo 9 10 Options: 11 12 -r Build with race detector 13 " 14 } 15 16 race='' 17 while getopts 'r' flag; do 18 case "${flag}" in 19 r) race='-race' ;; 20 *) print_usage 21 exit 1 ;; 22 esac 23 done 24 25 # Changes to the minimum golang version must also be replicated in 26 # scripts/build_metal.sh (here) 27 # Dockerfile 28 # README.md 29 # go.mod 30 go_version_minimum="1.21.8" 31 32 go_version() { 33 go version | sed -nE -e 's/[^0-9.]+([0-9.]+).+/\1/p' 34 } 35 36 version_lt() { 37 # Return true if $1 is a lower version than than $2, 38 local ver1=$1 39 local ver2=$2 40 # Reverse sort the versions, if the 1st item != ver1 then ver1 < ver2 41 if [[ $(echo -e -n "$ver1\n$ver2\n" | sort -rV | head -n1) != "$ver1" ]]; then 42 return 0 43 else 44 return 1 45 fi 46 } 47 48 if version_lt "$(go_version)" "$go_version_minimum"; then 49 echo "MetalGo requires Go >= $go_version_minimum, Go $(go_version) found." >&2 50 exit 1 51 fi 52 53 # MetalGo root folder 54 METAL_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) 55 # Load the constants 56 source "$METAL_PATH"/scripts/constants.sh 57 58 build_args="$race" 59 echo "Building MetalGo..." 60 go build $build_args -ldflags "-X github.com/MetalBlockchain/metalgo/version.GitCommit=$git_commit $static_ld_flags" -o "$metalgo_path" "$METAL_PATH/main/"*.go