github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/bin/build_xgo (about)

     1  #!/bin/bash
     2  
     3  # Usage:
     4  #> bin/build_xgo <os>/<arch>..
     5  #
     6  # Cross compile (Unix):
     7  #> bin/build_xgo linux/amd64
     8  #
     9  # Cross compile (OSX + Windows):
    10  #> bin/build_xgo darwin/amd64 windows/amd64
    11  #
    12  # Check if program has dynamic libraries:
    13  #> brew install readelf
    14  #> readelf -d build/node/mysterium_node
    15  
    16  set -e
    17  source bin/helpers/functions.sh
    18  source bin/helpers/output.sh
    19  
    20  XGO_TARGETS=`IFS=','; echo "$*"`
    21  if [ -z "$XGO_TARGETS" ]; then
    22      print_error "Missing targets!"
    23      exit 1
    24  fi
    25  
    26  DIR_BUILD="build/myst"
    27  mkdir -p ${DIR_BUILD}
    28  DIR_TEMP=`mktemp -d ${DIR_BUILD}/${tempname}.XXXXXX`
    29  
    30  IMAGE="mysteriumnetwork/xgo:1.20.2"
    31  
    32  docker run --rm \
    33      -v "$PWD"/$DIR_TEMP:/build \
    34      -v "$GOPATH"/xgo-cache:/deps-cache:ro \
    35      -v "$PWD":/source \
    36      -e OUT=myst \
    37      -e FLAG_V=false \
    38      -e FLAG_X=false \
    39      -e FLAG_RACE=false \
    40      -e FLAG_LDFLAGS="-w -s $(get_linker_ldflags)" \
    41      -e FLAG_BUILDMODE=default \
    42      -e TARGETS="$XGO_TARGETS" \
    43      "$IMAGE" ./cmd/mysterium_node
    44  
    45  # Remove version from binary name:
    46  #  - myst-darwin-10.6-amd64 -> myst_darwin_amd64
    47  #  - myst-linux-amd64       -> myst_linux_amd64
    48  for BINARY in `ls ${DIR_TEMP}`; do
    49      BINARY_RENAMED=`echo ${BINARY} | sed -nE 's/myst-([a-z]*)(-[0-9.]*)?-([0-z]*)(-[0-9]*)?/myst_\1_\3/p'`
    50      mv ${DIR_TEMP}/${BINARY} ${DIR_BUILD}/${BINARY_RENAMED}
    51  done
    52  rm -rf ${DIR_TEMP}