From 958b13ebb5fcefce6cdcbfd6ef959c560064e919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=90=B2=93=F0=90=B3=9B=F0=90=B3=AA=F0=90=B3=82?= =?UTF-8?q?=F0=90=B3=90=20=F0=90=B2=80=F0=90=B3=A2=F0=90=B3=A6=F0=90=B3=AB?= =?UTF-8?q?=F0=90=B3=A2=20=F0=90=B2=A5=F0=90=B3=94=F0=90=B3=9B=F0=90=B3=AA?= =?UTF-8?q?=F0=90=B3=8C=F0=90=B3=91=F0=90=B3=96=F0=90=B3=87?= <26771058+KobeArthurScofield@users.noreply.github.com> Date: Tue, 18 Feb 2025 16:33:05 +0800 Subject: [PATCH] Build: End of the easily mistaken 'Makefile' (#4395) Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- .github/workflows/release-win7.yml | 27 +++++++++++----------- .github/workflows/release.yml | 24 ++++++++++++------- Makefile | 37 ------------------------------ README.md | 10 ++++---- 4 files changed, 36 insertions(+), 62 deletions(-) delete mode 100644 Makefile diff --git a/.github/workflows/release-win7.yml b/.github/workflows/release-win7.yml index 0d00634a..239de1b5 100644 --- a/.github/workflows/release-win7.yml +++ b/.github/workflows/release-win7.yml @@ -1,11 +1,5 @@ name: Build and Release for Windows 7 -# NOTE: This Github Actions file depends on the Makefile. -# Building the correct package requires the correct binaries generated by the Makefile. To -# ensure the correct output, the Makefile must accept the appropriate input and compile the -# correct file with the correct name. If you need to modify this file, please ensure it won't -# disrupt the Makefile. - on: workflow_dispatch: release: @@ -37,6 +31,9 @@ jobs: GOARCH: ${{ matrix.goarch }} CGO_ENABLED: 0 steps: + - name: Checkout codebase + uses: actions/checkout@v4 + - name: Show workflow information run: | _NAME=${{ matrix.assetname }} @@ -46,18 +43,17 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: stable + go-version-file: go.mod check-latest: true - name: Setup patched builder run: | GOSDK=$(go env GOROOT) - curl -O -L https://github.com/XTLS/go-win7/releases/latest/download/go-for-win7-linux-amd64.zip rm -r $GOSDK/* + cd $GOSDK + curl -O -L https://github.com/XTLS/go-win7/releases/latest/download/go-for-win7-linux-amd64.zip unzip ./go-for-win7-linux-amd64.zip -d $GOSDK - - - name: Checkout codebase - uses: actions/checkout@v4 + rm ./go-for-win7-linux-amd64.zip - name: Get project dependencies run: go mod download @@ -65,8 +61,13 @@ jobs: - name: Build Xray run: | mkdir -p build_assets - make - find . -maxdepth 1 -type f -regex './\(wxray\|xray\).exe' -exec mv {} ./build_assets/ \; + COMMID=$(git describe --always --dirty) + echo 'Building Xray for Windows 7...' + go build -o build_assets/xray.exe -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main + echo 'CreateObject("Wscript.Shell").Run "xray.exe -config config.json",0' > build_assets/xray_no_window.vbs + echo 'Start-Process -FilePath ".\xray.exe" -ArgumentList "-config .\config.json" -WindowStyle Hidden' > build_assets/xray_no_window.ps1 + # The line below is for without running conhost.exe version. Commented for not being used. Provided for reference. + # go build -o build_assets/wxray.exe -trimpath -buildvcs=false -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main - name: Restore Geodat Cache uses: actions/cache/restore@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7bc8c51d..4de01e48 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,5 @@ name: Build and Release -# NOTE: This Github Actions file depends on the Makefile. -# Building the correct package requires the correct binaries generated by the Makefile. To -# ensure the correct output, the Makefile must accept the appropriate input and compile the -# correct file with the correct name. If you need to modify this file, please ensure it won't -# disrupt the Makefile. - on: workflow_dispatch: release: @@ -129,8 +123,22 @@ jobs: - name: Build Xray run: | mkdir -p build_assets - make - find . -maxdepth 1 -type f -regex './\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \; + COMMID=$(git describe --always --dirty) + if [[ ${GOOS} == 'windows' ]]; then + echo 'Building Xray for Windows...' + go build -o build_assets/xray.exe -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main + echo 'CreateObject("Wscript.Shell").Run "xray.exe -config config.json",0' > build_assets/xray_no_window.vbs + echo 'Start-Process -FilePath ".\xray.exe" -ArgumentList "-config .\config.json" -WindowStyle Hidden' > build_assets/xray_no_window.ps1 + # The line below is for without running conhost.exe version. Commented for not being used. Provided for reference. + # go build -o build_assets/wxray.exe -trimpath -buildvcs=false -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main + else + echo 'Building Xray...' + go build -o build_assets/xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main + if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then + echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...' + GOMIPS=softfloat go build -o build_assets/xray_softfloat -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main + fi + fi - name: Restore Geodat Cache uses: actions/cache/restore@v4 diff --git a/Makefile b/Makefile deleted file mode 100644 index 7653e306..00000000 --- a/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -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:\ - - This file is not the main Makefile; it only accepts environment variables and builds the \ - binary.\ - - Automatic building expects the correct binaries to be built by this Makefile. If you \ - intend to propose a change to this Makefile, carefully review the file below and ensure \ - that the change will not accidentally break the automatic building:\ - .github/workflows/release.yml \ - Otherwise it is recommended to contact the project maintainers. - -LDFLAGS = -X github.com/xtls/xray-core/core.build=$(VERSION) -s -w -buildid= -PARAMS = -trimpath -ldflags "$(LDFLAGS)" -v -MAIN = ./main -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) -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) -endif -.PHONY: clean build - -build: - go build -o $(OUTPUT) $(PARAMS) $(MAIN) - $(ADDITION) - -clean: - go clean -v -i $(PWD) - rm -f xray xray.exe wxray.exe xray_softfloat diff --git a/README.md b/README.md index 2f78f78d..7b258cff 100644 --- a/README.md +++ b/README.md @@ -126,25 +126,27 @@ - [Xray-core v1.0.0](https://github.com/XTLS/Xray-core/releases/tag/v1.0.0) was forked from [v2fly-core 9a03cc5](https://github.com/v2fly/v2ray-core/commit/9a03cc5c98d04cc28320fcee26dbc236b3291256), and we have made & accumulated a huge number of enhancements over time, check [the release notes for each version](https://github.com/XTLS/Xray-core/releases). - For third-party projects used in [Xray-core](https://github.com/XTLS/Xray-core), check your local or [the latest go.mod](https://github.com/XTLS/Xray-core/blob/main/go.mod). -## Compilation +## One-line Compilation ### Windows (PowerShell) ```powershell $env:CGO_ENABLED=0 -go build -o xray.exe -trimpath -ldflags "-s -w -buildid=" ./main +go build -o xray.exe -trimpath -buildvcs=false -ldflags="-s -w -buildid=" -v ./main ``` ### Linux / macOS ```bash -CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w -buildid=" ./main +CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-s -w -buildid=" -v ./main ``` ### Reproducible Releases +Make sure that you are using the same Go version, and remember to set the git commit id (7 bytes): + ```bash -make +CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main ``` ## Stargazers over time