mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-23 11:26:52 +00:00
use musl libc toolchains for build statically linked binaries
This commit is contained in:
parent
ce76cedb0d
commit
e24d672a36
1 changed files with 43 additions and 40 deletions
71
.github/workflows/release.yml
vendored
71
.github/workflows/release.yml
vendored
|
@ -42,51 +42,54 @@ jobs:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
check-latest: true
|
check-latest: true
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
if [ "${{ matrix.platform }}" == "arm64" ]; then
|
|
||||||
sudo apt install gcc-aarch64-linux-gnu
|
|
||||||
elif [ "${{ matrix.platform }}" == "armv7" ]; then
|
|
||||||
sudo apt install gcc-arm-linux-gnueabihf
|
|
||||||
elif [ "${{ matrix.platform }}" == "armv6" ]; then
|
|
||||||
sudo apt install gcc-arm-linux-gnueabihf
|
|
||||||
elif [ "${{ matrix.platform }}" == "386" ]; then
|
|
||||||
sudo apt install gcc-i686-linux-gnu
|
|
||||||
elif [ "${{ matrix.platform }}" == "armv5" ]; then
|
|
||||||
sudo apt install gcc-arm-linux-gnueabi
|
|
||||||
elif [ "${{ matrix.platform }}" == "s390x" ]; then
|
|
||||||
sudo apt install gcc-s390x-linux-gnu
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Build 3x-ui
|
- name: Build 3x-ui
|
||||||
run: |
|
run: |
|
||||||
export CGO_ENABLED=1
|
export CGO_ENABLED=1
|
||||||
export GOOS=linux
|
export GOOS=linux
|
||||||
export GOARCH=${{ matrix.platform }}
|
export GOARCH=${{ matrix.platform }}
|
||||||
if [ "${{ matrix.platform }}" == "arm64" ]; then
|
TOOLCHAIN_URL=""
|
||||||
export GOARCH=arm64
|
MUSL_CC_HOST="https://github.com/musl-cc/musl.cc/releases/download/v0.0.1" #http://musl.cc
|
||||||
export CC=aarch64-linux-gnu-gcc
|
case "${{ matrix.platform }}" in
|
||||||
elif [ "${{ matrix.platform }}" == "armv7" ]; then
|
amd64)
|
||||||
|
TOOLCHAIN_URL="$MUSL_CC_HOST/x86_64-linux-musl-cross.tgz"
|
||||||
|
;;
|
||||||
|
arm64)
|
||||||
|
TOOLCHAIN_URL="$MUSL_CC_HOST/aarch64-linux-musl-cross.tgz"
|
||||||
|
;;
|
||||||
|
armv7)
|
||||||
|
TOOLCHAIN_URL="$MUSL_CC_HOST/armv7l-linux-musleabihf-cross.tgz"
|
||||||
export GOARCH=arm
|
export GOARCH=arm
|
||||||
export GOARM=7
|
export GOARM=7
|
||||||
export CC=arm-linux-gnueabihf-gcc
|
;;
|
||||||
elif [ "${{ matrix.platform }}" == "armv6" ]; then
|
armv6)
|
||||||
|
TOOLCHAIN_URL="$MUSL_CC_HOST/armv6-linux-musleabihf-cross.tgz"
|
||||||
export GOARCH=arm
|
export GOARCH=arm
|
||||||
export GOARM=6
|
export GOARM=6
|
||||||
export CC=arm-linux-gnueabihf-gcc
|
;;
|
||||||
elif [ "${{ matrix.platform }}" == "386" ]; then
|
armv5)
|
||||||
export GOARCH=386
|
TOOLCHAIN_URL="$MUSL_CC_HOST/arm-linux-musleabi-cross.tgz"
|
||||||
export CC=i686-linux-gnu-gcc
|
|
||||||
elif [ "${{ matrix.platform }}" == "armv5" ]; then
|
|
||||||
export GOARCH=arm
|
export GOARCH=arm
|
||||||
export GOARM=5
|
export GOARM=5
|
||||||
export CC=arm-linux-gnueabi-gcc
|
;;
|
||||||
elif [ "${{ matrix.platform }}" == "s390x" ]; then
|
386)
|
||||||
export GOARCH=s390x
|
TOOLCHAIN_URL="$MUSL_CC_HOST/i686-linux-musl-cross.tgz"
|
||||||
export CC=s390x-linux-gnu-gcc
|
;;
|
||||||
fi
|
s390x)
|
||||||
go build -ldflags "-w -s" -o xui-release -v main.go
|
TOOLCHAIN_URL="$MUSL_CC_HOST/s390x-linux-musl-cross.tgz"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
echo "Downloading musl toolchain for ${{ matrix.platform }}"
|
||||||
|
curl -LO "$TOOLCHAIN_URL"
|
||||||
|
tar -xf *.tgz
|
||||||
|
TOOLCHAIN_DIR=$(find . -maxdepth 1 -type d -name "*-cross" | head -n1)
|
||||||
|
TOOLCHAIN_DIR=$(realpath "$TOOLCHAIN_DIR")
|
||||||
|
export PATH="$TOOLCHAIN_DIR/bin:$PATH"
|
||||||
|
# Detect compiler
|
||||||
|
export CC=$(find $TOOLCHAIN_DIR/bin -name '*-gcc' | head -n1)
|
||||||
|
echo "Using CC=$CC"
|
||||||
|
go build -ldflags "-w -s -linkmode external -extldflags '-static'" -o xui-release -v main.go
|
||||||
|
file xui-release
|
||||||
|
ldd xui-release || echo "Static binary confirmed"
|
||||||
|
|
||||||
mkdir x-ui
|
mkdir x-ui
|
||||||
cp xui-release x-ui/
|
cp xui-release x-ui/
|
||||||
|
|
Loading…
Reference in a new issue