Skip to content

Commit

Permalink
build nightly with cargo-zigbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Dec 17, 2022
1 parent 3b802b0 commit 26a04b9
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build-nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ jobs:
default: true
override: true

- name: Install cross
run: cargo install cross
- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2

- name: Install cargo-zigbuild
run: cargo install cargo-zigbuild

- name: Build ${{ matrix.target }}
timeout-minutes: 120
Expand All @@ -49,7 +52,7 @@ jobs:
fi
cd build
./build-release -t ${{ matrix.target }} $compile_features $compile_compress
./build-release-zigbuild -t ${{ matrix.target }} $compile_features $compile_compress
- name: Upload Artifacts
uses: actions/upload-artifact@v2
Expand Down
130 changes: 130 additions & 0 deletions build/build-release-zigbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/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

while getopts "t:f:u" opt; do
case $opt in
t)
targets+=($OPTARG)
;;
f)
features+=($OPTARG)
;;
u)
use_upx=true
;;
?)
echo "Usage: $(basename $0) [-t <target-triple>] [-f features] [-u]"
;;
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


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}\" ..."

cargo zigbuild --target "${TARGET}" \
--features "${TARGET_FEATURES}" \
--release
else
echo "* Building ${TARGET} package ${VERSION} ..."

cargo zigbuild --target "${TARGET}" \
--release
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}
zip ${PKG_PATH} \
"sslocal.exe" \
"ssserver.exe" \
"ssurl.exe" \
"ssmanager.exe" \
"ssservice.exe"

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

0 comments on commit 26a04b9

Please sign in to comment.