From 2d60543026049f3df67acf082a705e93899afc68 Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Mon, 4 Aug 2025 16:54:28 +0200 Subject: [PATCH] use musl libc toolchains Co-Authored-By: elseif <253712+elseif@users.noreply.github.com> --- .github/workflows/docker.yml | 2 +- .github/workflows/release.yml | 127 ++++++++++++++++++++-------------- DockerInitFiles.sh | 2 +- 3 files changed, 77 insertions(+), 54 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f2c332e3..aab209f8 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,7 +7,7 @@ on: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index adc7de2b..59a768ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,26 @@ name: Release X-UI on: - push: - tags: - - "*" workflow_dispatch: + release: + types: [published] + push: + branches: + - main + paths: + - '**.js' + - '**.css' + - '**.html' + - '**.sh' + - '**.go' + - 'go.mod' + - 'go.sum' + - 'x-ui.service' jobs: build: + permissions: + contents: write strategy: matrix: platform: @@ -15,10 +28,10 @@ jobs: - arm64 - armv7 - armv6 - - armv5 - 386 + - armv5 - s390x - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 @@ -27,53 +40,56 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: go.mod - - - 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 }}" == "armv5" ]; then - sudo apt install gcc-arm-linux-gnueabi - elif [ "${{ matrix.platform }}" == "386" ]; then - sudo apt install gcc-i686-linux-gnu - elif [ "${{ matrix.platform }}" == "s390x" ]; then - sudo apt install gcc-s390x-linux-gnu - fi + check-latest: true - name: Build x-ui run: | export CGO_ENABLED=1 export GOOS=linux export GOARCH=${{ matrix.platform }} - if [ "${{ matrix.platform }}" == "arm64" ]; then - export GOARCH=arm64 - export CC=aarch64-linux-gnu-gcc - elif [ "${{ matrix.platform }}" == "armv7" ]; then - export GOARCH=arm - export GOARM=7 - export CC=arm-linux-gnueabihf-gcc - elif [ "${{ matrix.platform }}" == "armv6" ]; then - export GOARCH=arm - export GOARM=6 - export CC=arm-linux-gnueabihf-gcc - elif [ "${{ matrix.platform }}" == "armv5" ]; then - export GOARCH=arm - export GOARM=5 - export CC=arm-linux-gnueabi-gcc - elif [ "${{ matrix.platform }}" == "386" ]; then - export GOARCH=386 - export CC=i686-linux-gnu-gcc - elif [ "${{ matrix.platform }}" == "s390x" ]; then - export GOARCH=s390x - export CC=s390x-linux-gnu-gcc - fi - - go build -ldflags "-w -s" -o xui-release -v main.go + TOOLCHAIN_URL="" + MUSL_CC_HOST="https://github.com/musl-cc/musl.cc/releases/download/v0.0.1" #http://musl.cc + case "${{ matrix.platform }}" in + 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 GOARM=7 + ;; + armv6) + TOOLCHAIN_URL="$MUSL_CC_HOST/armv6-linux-musleabihf-cross.tgz" + export GOARCH=arm + export GOARM=6 + ;; + armv5) + TOOLCHAIN_URL="$MUSL_CC_HOST/arm-linux-musleabi-cross.tgz" + export GOARCH=arm + export GOARM=5 + ;; + 386) + TOOLCHAIN_URL="$MUSL_CC_HOST/i686-linux-musl-cross.tgz" + ;; + s390x) + 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 cp xui-release x-ui/ @@ -84,7 +100,7 @@ jobs: cd x-ui/bin # Download dependencies - Xray_URL="https://github.com/XTLS/Xray-core/releases/download/v25.7.26/" + Xray_URL="https://github.com/XTLS/Xray-core/releases/download/v25.8.3/" if [ "${{ matrix.platform }}" == "amd64" ]; then wget -q ${Xray_URL}Xray-linux-64.zip unzip Xray-linux-64.zip @@ -101,14 +117,14 @@ jobs: wget -q ${Xray_URL}Xray-linux-arm32-v6.zip unzip Xray-linux-arm32-v6.zip rm -f Xray-linux-arm32-v6.zip - elif [ "${{ matrix.platform }}" == "armv5" ]; then - wget -q ${Xray_URL}Xray-linux-arm32-v5.zip - unzip Xray-linux-arm32-v5.zip - rm -f Xray-linux-arm32-v5.zip elif [ "${{ matrix.platform }}" == "386" ]; then wget -q ${Xray_URL}Xray-linux-32.zip unzip Xray-linux-32.zip rm -f Xray-linux-32.zip + elif [ "${{ matrix.platform }}" == "armv5" ]; then + wget -q ${Xray_URL}Xray-linux-arm32-v5.zip + unzip Xray-linux-arm32-v5.zip + rm -f Xray-linux-arm32-v5.zip elif [ "${{ matrix.platform }}" == "s390x" ]; then wget -q ${Xray_URL}Xray-linux-s390x.zip unzip Xray-linux-s390x.zip @@ -124,9 +140,16 @@ jobs: - name: Package run: tar -zcvf x-ui-linux-${{ matrix.platform }}.tar.gz x-ui - + + - name: Upload files to Artifacts + uses: actions/upload-artifact@v4 + with: + name: x-ui-linux-${{ matrix.platform }} + path: ./x-ui-linux-${{ matrix.platform }}.tar.gz + - name: Upload files to GH release uses: svenstaro/upload-release-action@v2 + if: github.event_name == 'release' && github.event.action == 'published' with: repo_token: ${{ secrets.GITHUB_TOKEN }} tag: ${{ github.ref }} diff --git a/DockerInitFiles.sh b/DockerInitFiles.sh index ca522254..bc7b0f6d 100755 --- a/DockerInitFiles.sh +++ b/DockerInitFiles.sh @@ -23,7 +23,7 @@ case $1 in esac mkdir -p build/bin cd build/bin -wget -q "https://github.com/XTLS/Xray-core/releases/download/v25.7.26/Xray-linux-${ARCH}.zip" +wget -q "https://github.com/XTLS/Xray-core/releases/download/v25.8.3/Xray-linux-${ARCH}.zip" unzip "Xray-linux-${ARCH}.zip" rm -f "Xray-linux-${ARCH}.zip" geoip.dat geosite.dat LICENSE README.md mv xray "xray-linux-${FNAME}"