From 192802ee0691900575a3c7a0cdb90b2d7e703035 Mon Sep 17 00:00:00 2001 From: CaIon Date: Thu, 8 Oct 2026 18:03:06 +0800 Subject: [PATCH] build: build release binaries with moejs's PGO profile moejs ships a default.pgo recorded from plugin workloads. Go only uses a profile found in the main package directory, so the Docker image, the release workflow and the Electron builds now pass it with -pgo. --- .github/workflows/electron-build.yml | 2 +- .github/workflows/release.yml | 8 ++++---- Dockerfile | 2 +- electron/build.sh | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/electron-build.yml b/.github/workflows/electron-build.yml index 5df7becce..fa0587ae6 100644 --- a/.github/workflows/electron-build.yml +++ b/.github/workflows/electron-build.yml @@ -61,7 +61,7 @@ jobs: if: runner.os == 'Windows' run: | go mod download - go build -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$(git describe --tags)'" -o new-api.exe + go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$(git describe --tags)'" -o new-api.exe - name: Update Electron version run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fc2b911d1..c942010ab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,12 +48,12 @@ jobs: - name: Build Backend (amd64) run: | go mod download - go build -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-$VERSION + go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-$VERSION - name: Build Backend (arm64) run: | sudo apt-get update DEBIAN_FRONTEND=noninteractive sudo apt-get install -y gcc-aarch64-linux-gnu - CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-arm64-$VERSION + CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-arm64-$VERSION - name: Generate checksums run: sha256sum new-api-* > checksums-linux.txt @@ -102,7 +102,7 @@ jobs: - name: Build Backend run: | go mod download - go build -ldflags "-X 'github.com/QuantumNous/new-api/common.Version=$VERSION'" -o new-api-macos-$VERSION + go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags "-X 'github.com/QuantumNous/new-api/common.Version=$VERSION'" -o new-api-macos-$VERSION - name: Generate checksums run: shasum -a 256 new-api-macos-* > checksums-macos.txt @@ -153,7 +153,7 @@ jobs: - name: Build Backend run: | go mod download - go build -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$VERSION'" -o new-api-$VERSION.exe + go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$VERSION'" -o new-api-$VERSION.exe - name: Generate checksums run: sha256sum new-api-*.exe > checksums-windows.txt diff --git a/Dockerfile b/Dockerfile index 7c06a42a7..ddcee582c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN go mod download COPY . . COPY --from=builder /build/web/dist ./web/dist -RUN go build -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$(cat VERSION)'" -o new-api +RUN go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$(cat VERSION)'" -o new-api FROM debian:bookworm-slim@sha256:f06537653ac770703bc45b4b113475bd402f451e85223f0f2837acbf89ab020a diff --git a/electron/build.sh b/electron/build.sh index 001ad587a..e8426a593 100755 --- a/electron/build.sh +++ b/electron/build.sh @@ -15,25 +15,25 @@ cd .. if [[ "$OSTYPE" == "darwin"* ]]; then echo "Building for macOS..." - CGO_ENABLED=1 go build -ldflags="-s -w" -o new-api + CGO_ENABLED=1 go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags="-s -w" -o new-api cd electron npm install npm run build:mac elif [[ "$OSTYPE" == "linux-gnu"* ]]; then echo "Building for Linux..." - CGO_ENABLED=1 go build -ldflags="-s -w" -o new-api + CGO_ENABLED=1 go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags="-s -w" -o new-api cd electron npm install npm run build:linux elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then echo "Building for Windows..." - CGO_ENABLED=1 go build -ldflags="-s -w" -o new-api.exe + CGO_ENABLED=1 go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags="-s -w" -o new-api.exe cd electron npm install npm run build:win else echo "Unknown OS, building for current platform..." - CGO_ENABLED=1 go build -ldflags="-s -w" -o new-api + CGO_ENABLED=1 go build -pgo="$(go list -m -f '{{.Dir}}' github.com/Calcium-Ion/moejs)/default.pgo" -ldflags="-s -w" -o new-api cd electron npm install npm run build