github.com/minio/mc@v0.0.0-20240507152021-646712d5e5fb/buildscripts/cross-compile.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2015-2021 MinIO, Inc.
     4  #
     5  # This file is part of MinIO Object Storage stack
     6  #
     7  # This program is free software: you can redistribute it and/or modify
     8  # it under the terms of the GNU Affero General Public License as published by
     9  # the Free Software Foundation, either version 3 of the License, or
    10  # (at your option) any later version.
    11  #
    12  # This program is distributed in the hope that it will be useful
    13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  # GNU Affero General Public License for more details.
    16  #
    17  # You should have received a copy of the GNU Affero General Public License
    18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  #
    20  
    21  set -e
    22  
    23  # Enable tracing if set.
    24  [ -n "$BASH_XTRACEFD" ] && set -x
    25  
    26  function _init() {
    27      ## All binaries are static make sure to disable CGO.
    28      export CGO_ENABLED=0
    29  
    30      ## List of architectures and OS to test coss compilation.
    31      SUPPORTED_OSARCH="linux/ppc64le linux/s390x linux/mips64 linux/amd64 windows/amd64 darwin/amd64 darwin/arm64 linux/arm64 linux/arm"
    32  }
    33  
    34  function _build() {
    35      local osarch=$1
    36      IFS=/ read -r -a arr <<<"$osarch"
    37      os="${arr[0]}"
    38      arch="${arr[1]}"
    39      package=$(go list -f '{{.ImportPath}}')
    40      printf -- "--> %15s:%s\n" "${osarch}" "${package}"
    41  
    42      # Go build to build the binary.
    43      export GOOS=$os
    44      export GOARCH=$arch
    45      export GO111MODULE=on
    46      export CGO_ENABLED=0
    47      go build -tags kqueue -o /dev/null
    48  }
    49  
    50  function main() {
    51      echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}"
    52      for each_osarch in ${SUPPORTED_OSARCH}; do
    53          _build "${each_osarch}"
    54      done
    55  }
    56  
    57  _init && main "$@"