diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7bc8c51d18cd..77f42ecc2edb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -118,13 +118,15 @@ jobs: echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v5.3.0 with: go-version-file: go.mod check-latest: true - name: Get project dependencies - run: go mod download + run: | + go mod download + go mod tidy - name: Build Xray run: | @@ -143,6 +145,9 @@ jobs: mv -f resources/* build_assets cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE + if [ "$GOOS" = "windows" ]; then + cp ${GITHUB_WORKSPACE}/xray_no_window.vbs ./build_assets/xray_no_window.vbs || echo "xray_no_window.vbs not found, skipping." + fi - name: Create ZIP archive if: github.event_name == 'release' @@ -178,3 +183,8 @@ jobs: file: ./Xray-${{ env.ASSET_NAME }}.zip* tag: ${{ github.ref }} file_glob: true + + - name: Clean up + run: | + go clean -v -i $(PWD) + go clean -modcache diff --git a/Makefile b/Makefile index 7653e30658cc..adae3271ca4f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ -NAME = xray - -VERSION=$(shell git describe --always --dirty) - # NOTE: This MAKEFILE can be used to build Xray-core locally and in Automatic workflows. It is \ provided for convenience in automatic building and functions as a part of it. # NOTE: If you need to modify this file, please be aware that:\ @@ -13,25 +9,64 @@ VERSION=$(shell git describe --always --dirty) .github/workflows/release.yml \ Otherwise it is recommended to contact the project maintainers. +# Define the name of the output binary +NAME = xray + +# Define the version using the latest git commit description +VERSION = $(shell git describe --always --dirty) + +# Linker flags and build parameters LDFLAGS = -X github.com/xtls/xray-core/core.build=$(VERSION) -s -w -buildid= PARAMS = -trimpath -ldflags "$(LDFLAGS)" -v + +# Main package to build MAIN = ./main + +# Prefix for installation PREFIX ?= $(shell go env GOPATH) -ifeq ($(GOOS),windows) -OUTPUT = $(NAME).exe -ADDITION = go build -o w$(NAME).exe -trimpath -ldflags "-H windowsgui $(LDFLAGS)" -v $(MAIN) + +# Phony targets to avoid conflicts with files named 'clean', 'build', 'test', or 'deps' +.PHONY: clean build test deps default + +# Install dependencies +deps: + @echo "Downloading dependencies..." + go mod download + @if [ $$? -ne 0 ]; then \ + echo "Error downloading dependencies"; \ + exit 1; \ + fi + @echo "Dependencies downloaded successfully" + +# Build target to compile the binary +build: deps + @echo "Building the binary..." + CGO_ENABLED=0 go build -o $(NAME) $(PARAMS) $(MAIN) + @if [ $$? -ne 0 ]; then \ + echo "Error building the binary"; \ + exit 1; \ + fi + @echo "Binary built successfully" +ifeq ($(shell go env GOOS), windows) + mv $(NAME) $(NAME).exe + echo 'CreateObject("Wscript.Shell").Run "$(NAME).exe",0' > $(NAME)_no_window.vbs +else ifeq ($(GOARCH),mips) + GOMIPS=softfloat CGO_ENABLED=0 go build -o $(NAME)_softfloat $(PARAMS) $(MAIN) +else ifeq ($(GOARCH),mipsle) + GOMIPS=softfloat CGO_ENABLED=0 go build -o $(NAME)_softfloat $(PARAMS) $(MAIN) else -OUTPUT = $(NAME) -endif -ifeq ($(shell echo "$(GOARCH)" | grep -Eq "(mips|mipsle)" && echo true),true) # -ADDITION = GOMIPS=softfloat go build -o $(NAME)_softfloat -trimpath -ldflags "$(LDFLAGS)" -v $(MAIN) + @echo "No special build steps for this architecture." endif -.PHONY: clean build -build: - go build -o $(OUTPUT) $(PARAMS) $(MAIN) - $(ADDITION) +# Run tests +test: + go test ./... +# Clean target to remove generated files clean: go clean -v -i $(PWD) - rm -f xray xray.exe wxray.exe xray_softfloat + go clean -modcache + rm -f $(NAME) $(NAME).exe $(NAME)_no_window.vbs $(NAME)_softfloat + +# Default target +default: build