From 2c80155c6f68b5be211267d62a71d123869e2b82 Mon Sep 17 00:00:00 2001 From: Larvan2 <78135608+Larvan2@users.noreply.github.com> Date: Sun, 15 Jan 2023 01:46:30 +0800 Subject: [PATCH] Update Makefile add CGO support for release build add release.sh --- .github/workflows/prerelease.yml | 57 ++++++++++++++++++++++++++++---- Makefile | 21 ++++++++++-- release.sh | 37 +++++++++++++++++++++ 3 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 release.sh diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 4a792eaa..b5cbb781 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -10,12 +10,36 @@ on: - Alpha - Beta jobs: - Build: - runs-on: ubuntu-latest + Build-Prerelease: + permissions: write-all + runs-on: ubuntu-22.04 + steps: - name: Check out code into the Go module directory uses: actions/checkout@v3 + - name: Set variables + if: ${{ github.ref_name }} == Alpha + run: echo "VERSION=master" >> $GITHUB_ENV + shell: bash + + - name: Set variables + if: ${{ github.ref_name }} == Beta + run: echo "VERSION=alpha" >> $GITHUB_ENV + shell: bash + + - name: Set ENV + run: | + echo "NAME=clash.meta" >> $GITHUB_ENV + echo "BUILD_TIME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV + echo "REPO=${{ github.repository }}" >> $GITHUB_ENV + echo "TARGET=windows/*,linux/*,darwin-10.16/*" >> $GITHUB_ENV + echo "TAGS=with_gvisor,with_lwip" >> $GITHUB_ENV + echo "ShortSHA=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV + echo "$ShortSHA" + echo "$REPO" + shell: bash + - name: Setup Go uses: actions/setup-go@v3 with: @@ -23,17 +47,38 @@ jobs: check-latest: true cache: true - - name: Test + - uses: nttld/setup-ndk@v1 + id: setup-ndk + with: + ndk-version: r25b + add-to-path: false + + - name: Go Test if: ${{github.ref_name=='Beta'}} run: | go test ./... + - name: Set up xgo + run: | + docker pull techknowlogick/xgo:latest + go install src.techknowlogick.com/xgo@latest + - name: Build if: success() env: - NAME: Clash.Meta - BINDIR: bin - run: make -j$(($(nproc) + 1)) releases + ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} + run: | + mkdir bin + make android-arm64 + make xgoall + cp release.sh ./bin/ + cd bin + ls -la + chmod +x * + bash ./release.sh + rm ./release.sh + ls -la + cd .. - name: Delete current release assets uses: andreaswilli/delete-release-assets-action@v2.0.0 diff --git a/Makefile b/Makefile index e23fa2d3..78e4cd4f 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,23 @@ all:linux-amd64 linux-arm64\ darwin-amd64 darwin-arm64\ windows-amd64 windows-arm64\ +xgoTarget = windows/*,linux/*,darwin-10.16/* +xgoTags = with_gvisor,with_lwip +Ldflags =-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" -X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" -w -s -buildid= + +xgoall: SHELL:=/bin/bash +xgoall: + xgo --branch $(BRANCH) --out=$(BINDIR)/$(NAME) --targets='$(xgoTarget)' --tags='$(xgoTags)' -ldflags='$(Ldflags)' github.com/$(REPO) + + +darwin-all: darwin-amd64 darwin-arm64 + +GOBUILDCGO = CGO_ENABLED=1 go build -tags with_gvisor,with_lwip -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \ + -X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" \ + -w -s -buildid=' + +CCAndroid=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang + docker: GOAMD64=v3 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ @@ -99,7 +116,7 @@ linux-mips64le: GOARCH=mips64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ android-arm64: - GOARCH=arm64 GOOS=android $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + CC=$(CCAndroid) GOARCH=arm64 GOOS=android $(GOBUILDCGO) -o $(BINDIR)/$(NAME)-$@ freebsd-386: GOARCH=386 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ @@ -154,4 +171,4 @@ CFLAGS := -O2 -g -Wall -Werror $(CFLAGS) ebpf: export BPF_CLANG := $(CLANG) ebpf: export BPF_CFLAGS := $(CFLAGS) ebpf: - cd component/ebpf/ && go generate ./... \ No newline at end of file + cd component/ebpf/ && go generate ./... diff --git a/release.sh b/release.sh new file mode 100644 index 00000000..6422207f --- /dev/null +++ b/release.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +FILENAMES=$(ls) +for FILENAME in $FILENAMES +do + if [[ $FILENAME =~ "darwin-10.16-arm64" ]];then + echo "rename darwin-10.16-arm64 $FILENAME" + mv $FILENAME clash.meta-darwin-arm64-${VERSION}-${ShortSHA} + elif [[ $FILENAME =~ "darwin-10.16-amd64" ]];then + echo "rename darwin-10.16-amd64 $FILENAME" + mv $FILENAME clash.meta-darwin-amd64-${VERSION}-${ShortSHA} + elif [[ $FILENAME =~ "windows-4.0-386" ]];then + echo "rename windows 386 $FILENAME" + mv $FILENAME clash.meta-windows-386-${VERSION}-${ShortSHA}.exe + elif [[ $FILENAME =~ "windows-4.0-amd64" ]];then + echo "rename windows amd64 $FILENAME" + mv $FILENAME clash.meta-windows-amd64-${VERSION}-${ShortSHA}.exe + elif [[ $FILENAME =~ "linux" ]];then + echo "rename linux $FILENAME" + mv $FILENAME $FILENAME-${VERSION}-${ShortSHA} + elif [[ $FILENAME =~ "android" ]];then + echo "rename android $FILENAME" + mv $FILENAME $FILENAME-${VERSION}-${ShortSHA} + else echo "skip $FILENAME" + fi +done + +FILENAMES=$(ls) +for FILENAME in $FILENAMES +do + if [[ ! ($FILENAME =~ ".exe" || $FILENAME =~ ".sh")]];then + gzip -S ".gz" $FILENAME + elif [[ $FILENAME =~ ".exe" ]];then + zip -m $FILENAME.zip $FILENAME + else echo "skip $FILENAME" + fi +done \ No newline at end of file