Enhance build process and options management

- Update Makefile to include new production and UPX build targets for optimized binaries.
- Add BUILDOPTIONS constant to share/const.go for tracking build configurations.
- Modify version command to display build options.
- Update Dockerfile to install UPX for compression during builds.
- Add release and prod targets to streamline artifact creation.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Max 2026-02-03 10:22:55 +08:00
parent 3d7b0a2dbd
commit 6e97de948b
5 changed files with 83 additions and 5 deletions

1
.gitignore vendored
View file

@ -60,3 +60,4 @@ sandbox/docker/yao-bridge-*
sandbox/docker/claude-proxy-* sandbox/docker/claude-proxy-*
sandbox/docker/claude/claude-proxy-* sandbox/docker/claude/claude-proxy-*
sandbox/proxy/claude-proxy-linux-* sandbox/proxy/claude-proxy-linux-*
release/*

View file

@ -400,11 +400,30 @@ artifacts-linux: clean
@CUI_COMMIT=$$(cd ../cui-v1.0 && git log | head -n 1 | awk '{print substr($$2, 0, 12)}') && \ @CUI_COMMIT=$$(cd ../cui-v1.0 && git log | head -n 1 | awk '{print substr($$2, 0, 12)}') && \
sed -ie "s/const PRCUI = \"DEV\"/const PRCUI = \"$$CUI_COMMIT-${NOW}\"/g" share/const.go sed -ie "s/const PRCUI = \"DEV\"/const PRCUI = \"$$CUI_COMMIT-${NOW}\"/g" share/const.go
# Making artifacts # Making artifacts - dev builds (full debug symbols, ~158M)
mkdir -p dist mkdir -p dist
CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -o dist/yao-${VERSION}-unstable-linux-amd64 CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -o dist/yao-${VERSION}-unstable-linux-amd64
CGO_ENABLED=1 CGO_LDFLAGS="-static" LD_LIBRARY_PATH=/usr/lib/gcc-cross/aarch64-linux-gnu/13 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc-13 CXX=aarch64-linux-gnu-g++-13 go build -v -o dist/yao-${VERSION}-unstable-linux-arm64 CGO_ENABLED=1 CGO_LDFLAGS="-static" LD_LIBRARY_PATH=/usr/lib/gcc-cross/aarch64-linux-gnu/13 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc-13 CXX=aarch64-linux-gnu-g++-13 go build -v -o dist/yao-${VERSION}-unstable-linux-arm64
# Making artifacts - prod builds (stripped, ~111M)
sed -i.tmp 's/const BUILDOPTIONS = ""/const BUILDOPTIONS = "-s -w (production, stripped)"/g' share/const.go && rm -f share/const.go.tmp
CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -ldflags="-s -w" -o dist/yao-${VERSION}-unstable-linux-amd64-prod
CGO_ENABLED=1 CGO_LDFLAGS="-static" LD_LIBRARY_PATH=/usr/lib/gcc-cross/aarch64-linux-gnu/13 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc-13 CXX=aarch64-linux-gnu-g++-13 go build -v -ldflags="-s -w" -o dist/yao-${VERSION}-unstable-linux-arm64-prod
# Making artifacts - prod-upx builds (stripped + compressed, ~45-55M)
sed -i.tmp 's/const BUILDOPTIONS = "-s -w (production, stripped)"/const BUILDOPTIONS = "-s -w +upx (production, compressed)"/g' share/const.go && rm -f share/const.go.tmp
CGO_ENABLED=1 CGO_LDFLAGS="-static" GOOS=linux GOARCH=amd64 go build -v -ldflags="-s -w" -o dist/yao-${VERSION}-unstable-linux-amd64-prod-upx
CGO_ENABLED=1 CGO_LDFLAGS="-static" LD_LIBRARY_PATH=/usr/lib/gcc-cross/aarch64-linux-gnu/13 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc-13 CXX=aarch64-linux-gnu-g++-13 go build -v -ldflags="-s -w" -o dist/yao-${VERSION}-unstable-linux-arm64-prod-upx
# UPX compression for prod-upx builds
@if command -v upx > /dev/null 2>&1; then \
echo "Compressing with UPX..."; \
upx --best dist/yao-${VERSION}-unstable-linux-amd64-prod-upx; \
upx --best dist/yao-${VERSION}-unstable-linux-arm64-prod-upx; \
else \
echo "WARNING: UPX not found, skipping compression"; \
fi
mkdir -p dist/release mkdir -p dist/release
mv dist/yao-*-* dist/release/ mv dist/yao-*-* dist/release/
chmod +x dist/release/yao-*-* chmod +x dist/release/yao-*-*
@ -484,8 +503,9 @@ debug: clean
cp -f share/const.goe share/const.go cp -f share/const.goe share/const.go
rm -f share/const.goe rm -f share/const.goe
.PHONY: release # make prepare (build CUI, yao-init, bindata - shared by release and prod)
release: clean .PHONY: prepare
prepare: clean
mkdir -p dist/release mkdir -p dist/release
mkdir .tmp mkdir .tmp
@ -528,13 +548,15 @@ release: clean
cp -r .tmp/yao-init .tmp/data/init cp -r .tmp/yao-init .tmp/data/init
go-bindata -fs -pkg data -o data/bindata.go -prefix ".tmp/data/" .tmp/data/... go-bindata -fs -pkg data -o data/bindata.go -prefix ".tmp/data/" .tmp/data/...
# Replace PRVERSION # Replace PRVERSION
cp -f share/const.go share/const.go.bak cp -f share/const.go share/const.go.bak
sed -ie "s/const PRVERSION = \"DEV\"/const PRVERSION = \"${COMMIT}-${NOW}\"/g" share/const.go sed -ie "s/const PRVERSION = \"DEV\"/const PRVERSION = \"${COMMIT}-${NOW}\"/g" share/const.go
@CUI_COMMIT=$$(cd .tmp/cui/v1.0 && git log | head -n 1 | awk '{print substr($$2, 0, 12)}') && \ @CUI_COMMIT=$$(cd .tmp/cui/v1.0 && git log | head -n 1 | awk '{print substr($$2, 0, 12)}') && \
sed -ie "s/const PRCUI = \"DEV\"/const PRCUI = \"$$CUI_COMMIT-${NOW}\"/g" share/const.go sed -ie "s/const PRCUI = \"DEV\"/const PRCUI = \"$$CUI_COMMIT-${NOW}\"/g" share/const.go
# make release (development build, ~158M)
.PHONY: release
release: prepare
# Making artifacts # Making artifacts
mkdir -p dist mkdir -p dist
CGO_ENABLED=1 go build -v -o dist/release/yao CGO_ENABLED=1 go build -v -o dist/release/yao
@ -552,6 +574,52 @@ release: clean
codesign --deep --force --verify --verbose --sign "${APPLE_SIGN}" dist/release/yao ; \ codesign --deep --force --verify --verbose --sign "${APPLE_SIGN}" dist/release/yao ; \
fi fi
# make prod (production build with -s -w, ~111M on macOS, ~45-55M on Linux with UPX)
.PHONY: prod
prod: prepare
# Set BUILDOPTIONS
@if [ "$$(uname)" = "Linux" ]; then \
sed -i.tmp 's/const BUILDOPTIONS = ""/const BUILDOPTIONS = "-s -w +upx (production, compressed)"/g' share/const.go && rm -f share/const.go.tmp; \
else \
sed -i.tmp 's/const BUILDOPTIONS = ""/const BUILDOPTIONS = "-s -w (production, stripped)"/g' share/const.go && rm -f share/const.go.tmp; \
fi
# Making artifacts
mkdir -p dist
CGO_ENABLED=1 go build -v -ldflags="-s -w" -o dist/release/yao-prod
chmod +x dist/release/yao-prod
# UPX compression (Linux only)
@if [ "$$(uname)" = "Linux" ]; then \
echo "Compressing with UPX..."; \
if command -v upx > /dev/null 2>&1; then \
upx --best dist/release/yao-prod; \
else \
echo "WARNING: UPX not found. Install with: apt install upx"; \
echo "Skipping compression."; \
fi; \
else \
echo "Note: UPX compression skipped on macOS (not supported)"; \
fi
# Clean up and restore bindata.go and const.go
cp data/bindata.go.bak data/bindata.go
cp share/const.go.bak share/const.go
rm data/bindata.go.bak
rm share/const.go.bak
rm -rf .tmp
# MacOS Application Signing
@if [ "$(OS)" = "Darwin" ]; then \
codesign --deep --force --verify --verbose --sign "${APPLE_SIGN}" dist/release/yao-prod ; \
fi
@echo ""
@echo "Done! Production binary:"
@ls -lh dist/release/yao-prod
@echo ""
@echo "Test with: dist/release/yao-prod version --all"
.PHONY: linux-release .PHONY: linux-release
linux-release: clean linux-release: clean

View file

@ -41,6 +41,11 @@ var versionCmd = &cobra.Command{
fmt.Printf("%s", color.WhiteString("Built: ")) fmt.Printf("%s", color.WhiteString("Built: "))
fmt.Printf("%s\n", color.BlueString(buildTime)) fmt.Printf("%s\n", color.BlueString(buildTime))
if share.BUILDOPTIONS != "" {
fmt.Printf("%s", color.WhiteString("Build options: "))
fmt.Printf("%s\n", color.CyanString(share.BUILDOPTIONS))
}
fmt.Printf("%s", color.WhiteString("OS/Arch: ")) fmt.Printf("%s", color.WhiteString("OS/Arch: "))
fmt.Printf("%s\n", color.MagentaString("%s/%s", runtime.GOOS, runtime.GOARCH)) fmt.Printf("%s\n", color.MagentaString("%s/%s", runtime.GOOS, runtime.GOARCH))

View file

@ -27,7 +27,8 @@ RUN apt-get update && \
apt-get install -y wget && \ apt-get install -y wget && \
apt-get install -y curl && \ apt-get install -y curl && \
apt-get install -y git && \ apt-get install -y git && \
apt-get install -y unzip apt-get install -y unzip && \
apt-get install -y upx
# Install Go 1.25.0 # Install Go 1.25.0
RUN wget https://golang.org/dl/go1.25.0.linux-amd64.tar.gz && \ RUN wget https://golang.org/dl/go1.25.0.linux-amd64.tar.gz && \

View file

@ -12,6 +12,9 @@ const CUI = "1.0.0"
// PRCUI CUI PR Commit // PRCUI CUI PR Commit
const PRCUI = "DEV" const PRCUI = "DEV"
// BUILDOPTIONS Build options (e.g., "-s -w", "-s -w +upx")
const BUILDOPTIONS = ""
// BUILDIN If true, the application will be built into a single artifact // BUILDIN If true, the application will be built into a single artifact
const BUILDIN = false const BUILDIN = false