github.com/dim4egster/coreth@v0.10.2/scripts/build.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -o errexit
     4  set -o nounset
     5  set -o pipefail
     6  
     7  go_version_minimum="1.18.1"
     8  
     9  go_version() {
    10      go version | sed -nE -e 's/[^0-9.]+([0-9.]+).+/\1/p'
    11  }
    12  
    13  version_lt() {
    14      # Return true if $1 is a lower version than than $2,
    15      local ver1=$1
    16      local ver2=$2
    17      # Reverse sort the versions, if the 1st item != ver1 then ver1 < ver2
    18      if  [[ $(echo -e -n "$ver1\n$ver2\n" | sort -rV | head -n1) != "$ver1" ]]; then
    19          return 0
    20      else
    21          return 1
    22      fi
    23  }
    24  
    25  if version_lt "$(go_version)" "$go_version_minimum"; then
    26      echo "Coreth requires Go >= $go_version_minimum, Go $(go_version) found." >&2
    27      exit 1
    28  fi
    29  
    30  # Avalanche root directory
    31  CORETH_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
    32  
    33  # Load the versions
    34  source "$CORETH_PATH"/scripts/versions.sh
    35  
    36  # Load the constants
    37  source "$CORETH_PATH"/scripts/constants.sh
    38  
    39  if [[ $# -eq 1 ]]; then
    40      binary_path=$1
    41  elif [[ $# -ne 0 ]]; then
    42      echo "Invalid arguments to build coreth. Requires either no arguments (default) or one arguments to specify binary location."
    43      exit 1
    44  fi
    45  
    46  # Check if CORETH_COMMIT is set, if not retrieve the last commit from the repo.
    47  # This is used in the Dockerfile to allow a commit hash to be passed in without
    48  # including the .git/ directory within the Docker image.
    49  coreth_commit=${CORETH_COMMIT:-$( git rev-list -1 HEAD )}
    50  
    51  # Build Coreth, which is run as a subprocess
    52  echo "Building Coreth Version: $coreth_version; GitCommit: $coreth_commit"
    53  go build -ldflags "-X github.com/dim4egster/coreth/plugin/evm.GitCommit=$coreth_commit -X github.com/dim4egster/coreth/plugin/evm.Version=$coreth_version" -o "$binary_path" "plugin/"*.go