Files
Archive/shadowsocks-rust/build/build-release
2024-11-25 19:36:45 +01:00

153 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
CUR_DIR=$( cd $( dirname $0 ) && pwd )
VERSION=$(grep -E '^version' ${CUR_DIR}/../Cargo.toml | awk '{print $3}' | sed 's/"//g')
## Disable macos ACL file
if [[ "$(uname -s)" == "Darwin" ]]; then
export COPYFILE_DISABLE=1
fi
targets=()
features=()
use_upx=false
use_nightly=false
cargo_flags=""
while getopts "t:f:unZ:" opt; do
case $opt in
t)
targets+=($OPTARG)
;;
f)
features+=($OPTARG)
;;
u)
use_upx=true
;;
n)
use_nightly=true
;;
Z)
cargo_flags="-Z $OPTARG"
;;
?)
echo "Usage: $(basename $0) [-t <target-triple>] [-f features] [-u] [-n]"
;;
esac
done
features+=${EXTRA_FEATURES}
if [[ "${#targets[@]}" == "0" ]]; then
echo "Specifying compile target with -t <target-triple>"
exit 1
fi
if [[ "${use_upx}" = true ]]; then
if [[ -z "$upx" ]] && command -v upx &> /dev/null; then
upx="upx -9"
fi
if [[ "x$upx" == "x" ]]; then
echo "Couldn't find upx in PATH, consider specifying it with variable \$upx"
exit 1
fi
fi
build_command="cross"
if [[ "${use_nightly}" = true ]]; then
build_command="$build_command +nightly"
fi
function build() {
cd "$CUR_DIR/.."
TARGET=$1
RELEASE_DIR="target/${TARGET}/release"
TARGET_FEATURES="${features[@]}"
if [[ "${TARGET_FEATURES}" != "" ]]; then
echo "* Building ${TARGET} package ${VERSION} with features \"${TARGET_FEATURES}\" ..."
$build_command build --target "${TARGET}" \
--features "${TARGET_FEATURES}" \
--release \
${cargo_flags}
else
echo "* Building ${TARGET} package ${VERSION} ..."
$build_command build --target "${TARGET}" \
--release \
${cargo_flags}
fi
if [[ $? != "0" ]]; then
exit 1
fi
PKG_DIR="${CUR_DIR}/release"
mkdir -p "${PKG_DIR}"
if [[ "$TARGET" == *"-linux-"* ]]; then
PKG_NAME="shadowsocks-v${VERSION}.${TARGET}.tar.xz"
PKG_PATH="${PKG_DIR}/${PKG_NAME}"
cd ${RELEASE_DIR}
if [[ "${use_upx}" = true ]]; then
# Enable upx for MIPS.
$upx sslocal ssserver ssurl ssmanager ssservice #>/dev/null
fi
echo "* Packaging XZ in ${PKG_PATH} ..."
tar -cJf ${PKG_PATH} \
"sslocal" \
"ssserver" \
"ssurl" \
"ssmanager" \
"ssservice"
if [[ $? != "0" ]]; then
exit 1
fi
cd "${PKG_DIR}"
shasum -a 256 "${PKG_NAME}" > "${PKG_NAME}.sha256"
elif [[ "$TARGET" == *"-windows-"* ]]; then
PKG_NAME="shadowsocks-v${VERSION}.${TARGET}.zip"
PKG_PATH="${PKG_DIR}/${PKG_NAME}"
echo "* Packaging ZIP in ${PKG_PATH} ..."
cd ${RELEASE_DIR}
sswinservice=""
if [ -e "sswinservice.exe" ]; then
sswinservice="sswinservice.exe"
fi
zip ${PKG_PATH} \
"sslocal.exe" \
"ssserver.exe" \
"ssurl.exe" \
"ssmanager.exe" \
"ssservice.exe" \
"${sswinservice}"
if [[ $? != "0" ]]; then
exit 1
fi
cd "${PKG_DIR}"
shasum -a 256 "${PKG_NAME}" > "${PKG_NAME}.sha256"
fi
echo "* Done build package ${PKG_NAME}"
}
for target in "${targets[@]}"; do
build "$target";
done