Fix: support low bash version

pull/194/head
zijiren233 2 years ago
parent 3a2bfdc62a
commit befd9a7dcf

@ -26,7 +26,7 @@ jobs:
declare -a arr=() declare -a arr=()
OIFS="$IFS" OIFS="$IFS"
IFS=$'\n,' IFS=$'\n,'
for line in $(BUILD_CONFIG=script/build.config.sh bash script/build.sh --show-all-targets); do for line in $(BUILD_CONFIG=script/build.config.sh bash script/build.sh --show-all-platforms); do
arr+=("$line") arr+=("$line")
done done
IFS="$OIFS" IFS="$OIFS"

@ -21,7 +21,7 @@ jobs:
declare -a arr=() declare -a arr=()
OIFS="$IFS" OIFS="$IFS"
IFS=$'\n,' IFS=$'\n,'
for line in $(BUILD_CONFIG=script/build.config.sh bash script/build.sh --show-all-targets); do for line in $(BUILD_CONFIG=script/build.config.sh bash script/build.sh --show-all-platforms); do
arr+=("$line") arr+=("$line")
done done
IFS="$OIFS" IFS="$OIFS"

@ -19,7 +19,7 @@ jobs:
declare -a arr=() declare -a arr=()
OIFS="$IFS" OIFS="$IFS"
IFS=$'\n,' IFS=$'\n,'
for line in $(BUILD_CONFIG=script/build.config.sh bash script/build.sh --show-all-targets); do for line in $(BUILD_CONFIG=script/build.config.sh bash script/build.sh --show-all-platforms); do
arr+=("$line") arr+=("$line")
done done
IFS="$OIFS" IFS="$OIFS"

@ -0,0 +1 @@
source script/build.config.sh

@ -1,6 +1,6 @@
function parseDepArgs() { function parseDepArgs() {
for i in "$@"; do while [[ $# -gt 0 ]]; do
case ${i,,} in case "${1}" in
--version=*) --version=*)
VERSION="${i#*=}" VERSION="${i#*=}"
shift shift

@ -59,8 +59,8 @@ function printEnvHelp() {
echo -e " ${COLOR_CYAN}HOST_CXX${COLOR_RESET} - Set the host C++ compiler (default: ${DEFAULT_CXX})." echo -e " ${COLOR_CYAN}HOST_CXX${COLOR_RESET} - Set the host C++ compiler (default: ${DEFAULT_CXX})."
echo -e " ${COLOR_CYAN}FORCE_CC${COLOR_RESET} - Force the use of a specific C compiler." echo -e " ${COLOR_CYAN}FORCE_CC${COLOR_RESET} - Force the use of a specific C compiler."
echo -e " ${COLOR_CYAN}FORCE_CXX${COLOR_RESET} - Force the use of a specific C++ compiler." echo -e " ${COLOR_CYAN}FORCE_CXX${COLOR_RESET} - Force the use of a specific C++ compiler."
echo -e " ${COLOR_CYAN}*_ALLOWED_PLATFORM${COLOR_RESET} - Set allowed platforms for a specific OS (e.g., LINUX_ALLOWED_PLATFORM=\"linux/amd64\")." echo -e " ${COLOR_CYAN}CGO_FLAGS${COLOR_RESET} - Set CGO flags (default: ${DEFAULT_CGO_FLAGS})."
echo -e " ${COLOR_CYAN}CGO_*_ALLOWED_PLATFORM${COLOR_RESET} - Set allowed platforms for CGO for a specific OS (e.g., CGO_LINUX_ALLOWED_PLATFORM=\"linux/amd64\")." echo -e " ${COLOR_CYAN}CGO_LDFLAGS${COLOR_RESET} - Set CGO linker flags (default: ${DEFAULT_CGO_LDFLAGS})."
echo -e " ${COLOR_CYAN}GH_PROXY${COLOR_RESET} - Set the GitHub proxy mirror (e.g., https://mirror.ghproxy.com/)." echo -e " ${COLOR_CYAN}GH_PROXY${COLOR_RESET} - Set the GitHub proxy mirror (e.g., https://mirror.ghproxy.com/)."
if declare -f printDepEnvHelp >/dev/null; then if declare -f printDepEnvHelp >/dev/null; then
@ -83,15 +83,15 @@ function printHelp() {
echo -e " ${COLOR_BLUE}--more-go-cmd-args='<args>'${COLOR_RESET} - Pass additional arguments to the 'go build' command." echo -e " ${COLOR_BLUE}--more-go-cmd-args='<args>'${COLOR_RESET} - Pass additional arguments to the 'go build' command."
echo -e " ${COLOR_BLUE}--disable-micro${COLOR_RESET} - Disable building micro architecture variants." echo -e " ${COLOR_BLUE}--disable-micro${COLOR_RESET} - Disable building micro architecture variants."
echo -e " ${COLOR_BLUE}--ldflags='<flags>'${COLOR_RESET} - Set linker flags (default: \"${DEFAULT_LDFLAGS}\")." echo -e " ${COLOR_BLUE}--ldflags='<flags>'${COLOR_RESET} - Set linker flags (default: \"${DEFAULT_LDFLAGS}\")."
echo -e " ${COLOR_BLUE}--platforms=<platforms>${COLOR_RESET} - Specify target platform(s) (default: host platform, supports: all, linux, linux/arm*, ...)." echo -e " ${COLOR_BLUE}-p=<platforms>, --platforms=<platforms>${COLOR_RESET} - Specify target platform(s) (default: host platform, supports: all, linux, linux/arm*, ...)."
echo -e " ${COLOR_BLUE}--result-dir=<dir>${COLOR_RESET} - Specify the build result directory (default: ${DEFAULT_RESULT_DIR})." echo -e " ${COLOR_BLUE}--result-dir=<dir>${COLOR_RESET} - Specify the build result directory (default: ${DEFAULT_RESULT_DIR})."
echo -e " ${COLOR_BLUE}--tags='<tags>'${COLOR_RESET} - Set build tags." echo -e " ${COLOR_BLUE}--tags='<tags>'${COLOR_RESET} - Set build tags."
echo -e " ${COLOR_BLUE}--show-all-targets${COLOR_RESET} - Display all supported target platforms." echo -e " ${COLOR_BLUE}--show-all-platforms${COLOR_RESET} - Display all supported target platforms."
echo -e " ${COLOR_BLUE}--github-proxy-mirror=<url>${COLOR_RESET} - Use a GitHub proxy mirror (e.g., https://mirror.ghproxy.com/)." echo -e " ${COLOR_BLUE}--github-proxy-mirror=<url>${COLOR_RESET} - Use a GitHub proxy mirror (e.g., https://mirror.ghproxy.com/)."
echo -e " ${COLOR_BLUE}--force-gcc=<path>${COLOR_RESET} - Force the use of a specific C compiler." echo -e " ${COLOR_BLUE}--force-gcc=<path>${COLOR_RESET} - Force the use of a specific C compiler."
echo -e " ${COLOR_BLUE}--force-g++=<path>${COLOR_RESET} - Force the use of a specific C++ compiler." echo -e " ${COLOR_BLUE}--force-g++=<path>${COLOR_RESET} - Force the use of a specific C++ compiler."
echo -e " ${COLOR_BLUE}--host-cc=<path>${COLOR_RESET} - Specify the host C compiler (default: ${DEFAULT_CC})." echo -e " ${COLOR_BLUE}--host-gcc=<path>${COLOR_RESET} - Specify the host C compiler (default: ${DEFAULT_CC})."
echo -e " ${COLOR_BLUE}--host-cxx=<path>${COLOR_RESET} - Specify the host C++ compiler (default: ${DEFAULT_CXX})." echo -e " ${COLOR_BLUE}--host-g++=<path>${COLOR_RESET} - Specify the host C++ compiler (default: ${DEFAULT_CXX})."
if declare -f printDepHelp >/dev/null; then if declare -f printDepHelp >/dev/null; then
echo -e "${COLOR_PURPLE}$(getSeparator)${COLOR_RESET}" echo -e "${COLOR_PURPLE}$(getSeparator)${COLOR_RESET}"
@ -160,6 +160,8 @@ function fixArgs() {
setDefault "LDFLAGS" "${DEFAULT_LDFLAGS}" setDefault "LDFLAGS" "${DEFAULT_LDFLAGS}"
setDefault "BUILD_ARGS" "" setDefault "BUILD_ARGS" ""
setDefault "CGO_DEPS_VERSION" "${DEFAULT_CGO_DEPS_VERSION}" setDefault "CGO_DEPS_VERSION" "${DEFAULT_CGO_DEPS_VERSION}"
setDefault "CGO_FLAGS" "${DEFAULT_CGO_FLAGS}"
setDefault "CGO_LDFLAGS" "${DEFAULT_CGO_LDFLAGS}"
} }
# Checks if CGO is enabled. # Checks if CGO is enabled.
@ -217,124 +219,64 @@ function downloadAndUnzip() {
# --- Platform Management --- # --- Platform Management ---
declare -A allowed_platforms # Removes duplicate platforms from a comma-separated list.
allowed_platforms=( # Arguments:
["linux"]="linux/386,linux/amd64,linux/arm,linux/arm64,linux/loong64,linux/mips,linux/mips64,linux/mips64le,linux/mipsle,linux/ppc64,linux/ppc64le,linux/riscv64,linux/s390x" # $1: Comma-separated list of platforms.
["darwin"]="darwin/amd64,darwin/arm64" # Returns:
["windows"]="windows/386,windows/amd64,windows/arm,windows/arm64" # Comma-separated list of platforms with duplicates removed.
) function removeDuplicatePlatforms() {
local all_platforms="$1"
declare -A cgo_allowed_platforms all_platforms="$(echo "${all_platforms}" | tr ',' '\n' | sort | uniq | paste -s -d ',' -)"
cgo_allowed_platforms=( all_platforms="${all_platforms#,}"
["linux"]="linux/386,linux/amd64,linux/arm,linux/arm64,linux/loong64,linux/mips,linux/mips64,linux/mips64le,linux/mipsle,linux/ppc64le,linux/riscv64,linux/s390x" all_platforms="${all_platforms%,}"
["windows"]="windows/386,windows/amd64" echo "${all_platforms}"
) }
# Adds platforms to the allowed platforms list. # Adds platforms to the allowed platforms list.
# Arguments: # Arguments:
# $1: Comma-separated list of platforms to add. # $1: Comma-separated list of platforms to add.
function addToAllowedPlatforms() { function addToAllowedPlatforms() {
local platforms="$1" [[ -z "$ALLOWED_PLATFORMS" ]] && ALLOWED_PLATFORMS="$1" || ALLOWED_PLATFORMS=$(removeDuplicatePlatforms "$ALLOWED_PLATFORMS,$1")
local platform=""
for platform in ${platform//,/ }; do
local os="${platform%%/*}"
if [[ -z "${allowed_platforms[${os}]}" ]]; then
allowed_platforms[${os}]="${platform}"
else
allowed_platforms[${os}]="${allowed_platforms[${os}]},${platform}"
fi
done
} }
# Adds platforms to the CGO allowed platforms list. # Adds platforms to the CGO allowed platforms list.
# Arguments: # Arguments:
# $1: Comma-separated list of platforms to add. # $1: Comma-separated list of platforms to add.
function addToCGOAllowedPlatforms() { function addToCGOAllowedPlatforms() {
local platforms="$1" [[ -z "$CGO_ALLOWED_PLATFORMS" ]] && CGO_ALLOWED_PLATFORMS="$1" || CGO_ALLOWED_PLATFORMS=$(removeDuplicatePlatforms "$CGO_ALLOWED_PLATFORMS,$1")
local platform=""
for platform in ${platforms//,/ }; do
local os="${platform%%/*}"
if [[ -z "${cgo_allowed_platforms[${os}]}" ]]; then
cgo_allowed_platforms[${os}]="${platform}"
else
cgo_allowed_platforms[${os}]="${cgo_allowed_platforms[${os}]},${platform}"
fi
done
} }
# Removes platforms from the allowed platforms list. # Removes platforms from the allowed platforms list.
# Arguments: # Arguments:
# $1: Comma-separated list of platforms to remove. # $1: Comma-separated list of platforms to remove.
function deleteFromAllowedPlatforms() { function deleteFromAllowedPlatforms() {
local platforms="$1" ALLOWED_PLATFORMS=$(echo "${ALLOWED_PLATFORMS}" | sed "s|${1}$||g" | sed "s|${1},||g")
local platform=""
for platform in ${platforms//,/ }; do
local os="${platform%%/*}"
if [[ -n "${allowed_platforms[${os}]}" ]]; then
allowed_platforms[${os}]=$(echo "${allowed_platforms[${os}]}" | sed "s|${platform}$||g" | sed "s|${platform},||g")
fi
done
} }
# Removes platforms from the CGO allowed platforms list. # Removes platforms from the CGO allowed platforms list.
# Arguments: # Arguments:
# $1: Comma-separated list of platforms to remove. # $1: Comma-separated list of platforms to remove.
function deleteFromCGOAllowedPlatforms() { function deleteFromCGOAllowedPlatforms() {
local platforms="$1" CGO_ALLOWED_PLATFORMS=$(echo "${CGO_ALLOWED_PLATFORMS}" | sed "s|${1}$||g" | sed "s|${1},||g")
local platform=""
for platform in ${platforms//,/ }; do
local os="${platform%%/*}"
if [[ -n "${cgo_allowed_platforms[${os}]}" ]]; then
cgo_allowed_platforms[${os}]=$(echo "${cgo_allowed_platforms[${os}]}" | sed "s|${platform}$||g" | sed "s|${platform},||g")
fi
done
} }
# Initializes the host platforms. addToAllowedPlatforms "linux/386,linux/amd64,linux/arm,linux/arm64,linux/loong64,linux/mips,linux/mips64,linux/mips64le,linux/mipsle,linux/ppc64,linux/ppc64le,linux/riscv64,linux/s390x"
function initHostPlatforms() { addToAllowedPlatforms "darwin/amd64,darwin/arm64"
addToAllowedPlatforms "${GOHOSTOS}/${GOHOSTARCH}" addToAllowedPlatforms "windows/386,windows/amd64,windows/arm,windows/arm64"
addToCGOAllowedPlatforms "${GOHOSTOS}/${GOHOSTARCH}"
}
# Removes duplicate platforms from a comma-separated list. addToCGOAllowedPlatforms "linux/386,linux/amd64,linux/arm,linux/arm64,linux/loong64,linux/mips,linux/mips64,linux/mips64le,linux/mipsle,linux/ppc64le,linux/riscv64,linux/s390x"
# Arguments: addToCGOAllowedPlatforms "windows/386,windows/amd64"
# $1: Comma-separated list of platforms.
# Returns: addToAllowedPlatforms "${GOHOSTOS}/${GOHOSTARCH}"
# Comma-separated list of platforms with duplicates removed. addToCGOAllowedPlatforms "${GOHOSTOS}/${GOHOSTARCH}"
function removeDuplicatePlatforms() {
local all_platforms="$1"
all_platforms="$(echo "${all_platforms}" | tr ',' '\n' | sort | uniq | paste -s -d ',' -)"
all_platforms="${all_platforms#,}"
all_platforms="${all_platforms%,}"
echo "${all_platforms}"
}
# Initializes the platforms based on environment variables and allowed platforms. # Initializes the platforms based on environment variables and allowed platforms.
function initPlatforms() { function initPlatforms() {
setDefault "CGO_ENABLED" "${DEFAULT_CGO_ENABLED}" setDefault "CGO_ENABLED" "${DEFAULT_CGO_ENABLED}"
unset -v CURRENT_ALLOWED_PLATFORM unset -v CURRENT_ALLOWED_PLATFORMS
ALLOWED_PLATFORM=""
CGO_ALLOWED_PLATFORM=""
for os in "${!allowed_platforms[@]}"; do
ALLOWED_PLATFORM="${ALLOWED_PLATFORM},${allowed_platforms[${os}]}"
if [[ -n "${cgo_allowed_platforms[${os}]}" ]]; then
CGO_ALLOWED_PLATFORM="${CGO_ALLOWED_PLATFORM},${cgo_allowed_platforms[${os}]}"
fi
done
ALLOWED_PLATFORM=$(removeDuplicatePlatforms "${ALLOWED_PLATFORM}")
CGO_ALLOWED_PLATFORM=$(removeDuplicatePlatforms "${CGO_ALLOWED_PLATFORM}")
isCGOEnabled && CURRENT_ALLOWED_PLATFORM="${CGO_ALLOWED_PLATFORM}" || CURRENT_ALLOWED_PLATFORM="${ALLOWED_PLATFORM}" isCGOEnabled && CURRENT_ALLOWED_PLATFORMS="${CGO_ALLOWED_PLATFORMS}" || CURRENT_ALLOWED_PLATFORMS="${ALLOWED_PLATFORMS}"
for os in "${!allowed_platforms[@]}"; do
local var="${os^^}_ALLOWED_PLATFORM"
local cgo_var="CGO_${var}"
eval "CURRENT_${var}=\"${!var}\""
eval "CURRENT_${cgo_var}=\"${!cgo_var}\""
done
if declare -f initDepPlatforms >/dev/null; then if declare -f initDepPlatforms >/dev/null; then
initDepPlatforms initDepPlatforms
@ -344,14 +286,14 @@ function initPlatforms() {
# Checks if a platform is allowed. # Checks if a platform is allowed.
# Arguments: # Arguments:
# $1: Target platform to check. # $1: Target platform to check.
# $2: Optional. List of allowed platforms. If not provided, CURRENT_ALLOWED_PLATFORM is used. # $2: Optional. List of allowed platforms. If not provided, CURRENT_ALLOWED_PLATFORMS is used.
# Returns: # Returns:
# 0: Platform is allowed. # 0: Platform is allowed.
# 1: Platform is not allowed. # 1: Platform is not allowed.
# 2: Platform is not allowed for CGO. # 2: Platform is not allowed for CGO.
function checkPlatform() { function checkPlatform() {
local target_platform="$1" local target_platform="$1"
local current_allowed_platform="${2:-${CURRENT_ALLOWED_PLATFORM}}" local current_allowed_platform="${2:-${CURRENT_ALLOWED_PLATFORMS}}"
if [[ "${current_allowed_platform}" =~ (^|,)${target_platform}($|,) ]]; then if [[ "${current_allowed_platform}" =~ (^|,)${target_platform}($|,) ]]; then
return 0 return 0
@ -371,9 +313,7 @@ function checkPlatform() {
# 2: At least one platform is not allowed for CGO. # 2: At least one platform is not allowed for CGO.
# 3: Error checking platforms. # 3: Error checking platforms.
function checkPlatforms() { function checkPlatforms() {
local platforms="$1" for platform in ${1//,/ }; do
for platform in ${platforms//,/ }; do
case $( case $(
checkPlatform "${platform}" checkPlatform "${platform}"
echo $? echo $?
@ -400,14 +340,13 @@ function checkPlatforms() {
# --- CGO Dependencies --- # --- CGO Dependencies ---
declare -A cgo_deps function resetCGO() {
cgo_deps=( CC=""
["CC"]="" CXX=""
["CXX"]="" MORE_CGO_CFLAGS=""
["MORE_CGO_CFLAGS"]="" MORE_CGO_CXXFLAGS=""
["MORE_CGO_CXXFLAGS"]="" MORE_CGO_LDFLAGS=""
["MORE_CGO_LDFLAGS"]="" }
)
# Initializes CGO dependencies based on the target operating system and architecture. # Initializes CGO dependencies based on the target operating system and architecture.
# Arguments: # Arguments:
@ -418,13 +357,14 @@ cgo_deps=(
# 0: CGO dependencies initialized successfully. # 0: CGO dependencies initialized successfully.
# 1: Error initializing CGO dependencies. # 1: Error initializing CGO dependencies.
function initCGODeps() { function initCGODeps() {
resetCGO
local goos="$1" local goos="$1"
local goarch="$2" local goarch="$2"
local micro="$3" local micro="$3"
if [[ -n "${FORCE_CC}" ]] && [[ -n "${FORCE_CXX}" ]]; then if [[ -n "${FORCE_CC}" ]] && [[ -n "${FORCE_CXX}" ]]; then
cgo_deps["CC"]="${FORCE_CC}" CC="${FORCE_CC}"
cgo_deps["CXX"]="${FORCE_CXX}" CXX="${FORCE_CXX}"
return 0 return 0
elif [[ -n "${FORCE_CC}" ]] || [[ -n "${FORCE_CXX}" ]]; then elif [[ -n "${FORCE_CC}" ]] || [[ -n "${FORCE_CXX}" ]]; then
echo -e "${COLOR_RED}Both FORCE_CC and FORCE_CXX must be set at the same time.${COLOR_RESET}" echo -e "${COLOR_RED}Both FORCE_CC and FORCE_CXX must be set at the same time.${COLOR_RESET}"
@ -463,26 +403,26 @@ function initCGODeps() {
esac esac
local cc_command cc_options local cc_command cc_options
read -r cc_command cc_options <<<"${cgo_deps["CC"]}" read -r cc_command cc_options <<<"${CC}"
cc_command="$(command -v "${cc_command}")" cc_command="$(command -v "${cc_command}")"
if [[ "${cc_command}" != /* ]]; then if [[ "${cc_command}" != /* ]]; then
cgo_deps["CC"]="$(cd "$(dirname "${cc_command}")" && pwd)/$(basename "${cc_command}")" CC="$(cd "$(dirname "${cc_command}")" && pwd)/$(basename "${cc_command}")"
[[ -n "${cc_options}" ]] && cgo_deps["CC"]="${cgo_deps["CC"]} ${cc_options}" [[ -n "${cc_options}" ]] && CC="${CC} ${cc_options}"
fi fi
local cxx_command cxx_options local cxx_command cxx_options
read -r cxx_command cxx_options <<<"${cgo_deps["CXX"]}" read -r cxx_command cxx_options <<<"${CXX}"
cxx_command="$(command -v "${cxx_command}")" cxx_command="$(command -v "${cxx_command}")"
if [[ "${cxx_command}" != /* ]]; then if [[ "${cxx_command}" != /* ]]; then
cgo_deps["CXX"]="$(cd "$(dirname "${cxx_command}")" && pwd)/$(basename "${cxx_command}")" CXX="$(cd "$(dirname "${cxx_command}")" && pwd)/$(basename "${cxx_command}")"
[[ -n "${cxx_options}" ]] && cgo_deps["CXX"]="${cgo_deps["CXX"]} ${cxx_options}" [[ -n "${cxx_options}" ]] && CXX="${CXX} ${cxx_options}"
fi fi
} }
# Initializes CGO dependencies for the host platform. # Initializes CGO dependencies for the host platform.
function initHostCGODeps() { function initHostCGODeps() {
cgo_deps["CC"]="${HOST_CC}" CC="${HOST_CC}"
cgo_deps["CXX"]="${HOST_CXX}" CXX="${HOST_CXX}"
} }
# Initializes default CGO dependencies based on the target operating system, architecture, and micro architecture. # Initializes default CGO dependencies based on the target operating system, architecture, and micro architecture.
@ -599,8 +539,8 @@ function initLinuxCGO() {
local arch_prefix="$1" local arch_prefix="$1"
local abi="$2" local abi="$2"
local micro="$3" local micro="$3"
local cc_var="CC_LINUX_${arch_prefix^^}${abi^^}${micro^^}" local cc_var=$(echo "CC_LINUX_${arch_prefix}${abi}${micro}" | awk '{print tolower($0)}')
local cxx_var="CXX_LINUX_${arch_prefix^^}${abi^^}${micro^^}" local cxx_var=$(echo "CXX_LINUX_${arch_prefix}${abi}${micro}" | awk '{print tolower($0)}')
if [[ -z "${!cc_var}" ]] && [[ -z "${!cxx_var}" ]]; then if [[ -z "${!cc_var}" ]] && [[ -z "${!cxx_var}" ]]; then
local cross_compiler_name="${arch_prefix}-linux-musl${abi}${micro}-cross" local cross_compiler_name="${arch_prefix}-linux-musl${abi}${micro}-cross"
@ -623,8 +563,8 @@ function initLinuxCGO() {
return 1 return 1
fi fi
cgo_deps["CC"]="${!cc_var} -static --static" CC="${!cc_var} -static --static"
cgo_deps["CXX"]="${!cxx_var} -static --static" CXX="${!cxx_var} -static --static"
return 0 return 0
} }
@ -633,8 +573,8 @@ function initLinuxCGO() {
# $1: Architecture prefix (e.g., "i686", "x86_64"). # $1: Architecture prefix (e.g., "i686", "x86_64").
function initWindowsCGO() { function initWindowsCGO() {
local arch_prefix="$1" local arch_prefix="$1"
local cc_var="CC_WINDOWS_${arch_prefix^^}" local cc_var=$(echo "CC_WINDOWS_${arch_prefix}" | awk '{print tolower($0)}')
local cxx_var="CXX_WINDOWS_${arch_prefix^^}" local cxx_var=$(echo "CXX_WINDOWS_${arch_prefix}" | awk '{print tolower($0)}')
if [[ -z "${!cc_var}" ]] && [[ -z "${!cxx_var}" ]]; then if [[ -z "${!cc_var}" ]] && [[ -z "${!cxx_var}" ]]; then
local cross_compiler_name="${arch_prefix}-w64-mingw32-cross" local cross_compiler_name="${arch_prefix}-w64-mingw32-cross"
@ -657,8 +597,8 @@ function initWindowsCGO() {
return 1 return 1
fi fi
cgo_deps["CC"]="${!cc_var} -static --static" CC="${!cc_var} -static --static"
cgo_deps["CXX"]="${!cxx_var} -static --static" CXX="${!cxx_var} -static --static"
return 0 return 0
} }
@ -714,7 +654,6 @@ function buildTarget() {
supportPIE "${platform}" && build_mode="-buildmode=pie" supportPIE "${platform}" && build_mode="-buildmode=pie"
local build_env=( local build_env=(
"CGO_ENABLED=${CGO_ENABLED}"
"GOOS=${goos}" "GOOS=${goos}"
"GOARCH=${goarch}" "GOARCH=${goarch}"
) )
@ -788,6 +727,8 @@ function buildTargetWithMicro() {
local target_file="${RESULT_DIR}/${BIN_NAME}-${goos}-${goarch}${micro:+"-$micro"}${ext}" local target_file="${RESULT_DIR}/${BIN_NAME}-${goos}-${goarch}${micro:+"-$micro"}${ext}"
local default_target_file="${RESULT_DIR}/${BIN_NAME}-${goos}-${goarch}${ext}" local default_target_file="${RESULT_DIR}/${BIN_NAME}-${goos}-${goarch}${ext}"
isCGOEnabled && build_env+=("CGO_ENABLED=1") || build_env+=("CGO_ENABLED=0")
# Set micro architecture specific environment variables. # Set micro architecture specific environment variables.
case "${goarch}" in case "${goarch}" in
"386") "386")
@ -825,11 +766,11 @@ function buildTargetWithMicro() {
# Set CGO specific environment variables. # Set CGO specific environment variables.
if isCGOEnabled; then if isCGOEnabled; then
build_env+=("CGO_CFLAGS=${DEFAULT_CGO_FLAGS} ${cgo_deps["MORE_CGO_CFLAGS"]}") build_env+=("CGO_CFLAGS=${CGO_FLAGS}${MORE_CGO_CFLAGS:+ ${MORE_CGO_CFLAGS}}")
build_env+=("CGO_CXXFLAGS=${DEFAULT_CGO_FLAGS} ${cgo_deps["MORE_CGO_CXXFLAGS"]}") build_env+=("CGO_CXXFLAGS=${CGO_FLAGS}${MORE_CGO_CXXFLAGS:+ ${MORE_CGO_CXXFLAGS}}")
build_env+=("CGO_LDFLAGS=${DEFAULT_CGO_LDFLAGS} ${cgo_deps["MORE_CGO_LDFLAGS"]}") build_env+=("CGO_LDFLAGS=${CGO_LDFLAGS}${MORE_CGO_LDFLAGS:+ ${MORE_CGO_LDFLAGS}}")
build_env+=("CC=${cgo_deps["CC"]}") build_env+=("CC=${CC}")
build_env+=("CXX=${cgo_deps["CXX"]}") build_env+=("CXX=${CXX}")
fi fi
echo -e "${COLOR_PURPLE}Building ${goos}/${goarch}${micro:+/${micro}}...${COLOR_RESET}" echo -e "${COLOR_PURPLE}Building ${goos}/${goarch}${micro:+/${micro}}...${COLOR_RESET}"
@ -855,11 +796,11 @@ function expandPlatforms() {
local platform="" local platform=""
for platform in ${platforms//,/ }; do for platform in ${platforms//,/ }; do
if [[ "${platform}" == "all" ]]; then if [[ "${platform}" == "all" ]]; then
echo "${CURRENT_ALLOWED_PLATFORM}" echo "${CURRENT_ALLOWED_PLATFORMS}"
return 0 return 0
elif [[ "${platform}" == *\** ]]; then elif [[ "${platform}" == *\** ]]; then
local tmp_var="" local tmp_var=""
for tmp_var in ${CURRENT_ALLOWED_PLATFORM//,/ }; do for tmp_var in ${CURRENT_ALLOWED_PLATFORMS//,/ }; do
[[ "${tmp_var}" == ${platform} ]] && expanded_platforms="${expanded_platforms} ${tmp_var}" [[ "${tmp_var}" == ${platform} ]] && expanded_platforms="${expanded_platforms} ${tmp_var}"
done done
elif [[ "${platform}" != */* ]]; then elif [[ "${platform}" != */* ]]; then
@ -914,7 +855,6 @@ function loadBuildConfig() {
# --- Main Script --- # --- Main Script ---
loadBuildConfig loadBuildConfig
initHostPlatforms
# Parse command-line arguments. # Parse command-line arguments.
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@ -942,7 +882,7 @@ while [[ $# -gt 0 ]]; do
--ldflags=*) --ldflags=*)
addLDFLAGS "${1#*=}" addLDFLAGS "${1#*=}"
;; ;;
--platforms=*) -p=* | --platforms=*)
PLATFORMS="${1#*=}" PLATFORMS="${1#*=}"
;; ;;
--result-dir=*) --result-dir=*)
@ -951,9 +891,9 @@ while [[ $# -gt 0 ]]; do
--tags=*) --tags=*)
addTags "${1#*=}" addTags "${1#*=}"
;; ;;
--show-all-targets) --show-all-platforms)
initPlatforms initPlatforms
echo "${CURRENT_ALLOWED_PLATFORM}" echo "${CURRENT_ALLOWED_PLATFORMS}"
exit 0 exit 0
;; ;;
--github-proxy-mirror=*) --github-proxy-mirror=*)
@ -965,10 +905,10 @@ while [[ $# -gt 0 ]]; do
--force-g++=*) --force-g++=*)
FORCE_CXX="${1#*=}" FORCE_CXX="${1#*=}"
;; ;;
--host-cc=*) --host-gcc=*)
HOST_CC="${1#*=}" HOST_CC="${1#*=}"
;; ;;
--host-cxx=*) --host-g++=*)
HOST_CXX="${1#*=}" HOST_CXX="${1#*=}"
;; ;;
*) *)

Loading…
Cancel
Save