github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/buildscripts/cross-compile.sh (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  # Enable tracing if set.
     5  [ -n "$BASH_XTRACEFD" ] && set -x
     6  
     7  function _init() {
     8  	## All binaries are static make sure to disable CGO.
     9  	export CGO_ENABLED=0
    10  
    11  	## List of architectures and OS to test coss compilation.
    12  	SUPPORTED_OSARCH="linux/ppc64le linux/mips64 linux/amd64 linux/arm64 linux/s390x darwin/arm64 darwin/amd64 freebsd/amd64 windows/amd64 linux/arm linux/386 netbsd/amd64 linux/mips openbsd/amd64"
    13  }
    14  
    15  function _build() {
    16  	local osarch=$1
    17  	IFS=/ read -r -a arr <<<"$osarch"
    18  	os="${arr[0]}"
    19  	arch="${arr[1]}"
    20  	package=$(go list -f '{{.ImportPath}}')
    21  	printf -- "--> %15s:%s\n" "${osarch}" "${package}"
    22  
    23  	# go build -trimpath to build the binary.
    24  	export GOOS=$os
    25  	export GOARCH=$arch
    26  	export GO111MODULE=on
    27  	go build -trimpath -tags kqueue -o /dev/null
    28  }
    29  
    30  function main() {
    31  	echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}"
    32  	for each_osarch in ${SUPPORTED_OSARCH}; do
    33  		_build "${each_osarch}"
    34  	done
    35  }
    36  
    37  _init && main "$@"