From 0b59548079c956acc1ba25c32088634b28e4279d Mon Sep 17 00:00:00 2001 From: Nimbus318 <136771156+Nimbus318@users.noreply.github.com> Date: Fri, 9 May 2025 18:54:45 +0800 Subject: [PATCH] fix(build): Enable architecture-aware backend builds for multi-platform support Signed-off-by: Nimbus318 <136771156+Nimbus318@users.noreply.github.com> --- server/Dockerfile | 4 +++- server/Makefile | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index 9165b2b..bea55a3 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -2,11 +2,13 @@ FROM golang:1.23.1 AS builder WORKDIR /src +ARG TARGETARCH + COPY . . RUN apt-get update && apt-get install -y --no-install-recommends protobuf-compiler -RUN make build +RUN make build TARGET_ARCH=${TARGETARCH} FROM debian:stable-slim diff --git a/server/Makefile b/server/Makefile index 7dbe891..fee817d 100644 --- a/server/Makefile +++ b/server/Makefile @@ -3,6 +3,7 @@ CMD_PATH ?= ./cmd/ BUILD_PATH ?= ./build/ VERSION ?= $(shell git describe --tags --always) DIRS = $(shell ls $(CMD_PATH)) +TARGET_ARCH ?= amd64 # 1. Install Go dependencies .PHONY: install-deps @@ -37,10 +38,11 @@ tidy-mod: # 4. Build-related commands .PHONY: build-linux build-linux: - @ for dir in $(DIRS); \ + @echo "Building for GOOS=linux GOARCH=$(TARGET_ARCH)" # TARGET_ARCH 会从 make 命令传入 + @for dir in $(DIRS); \ do \ - GO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BUILD_PATH)$$dir ${CMD_PATH}$$dir; \ - echo "Built $$dir for Linux"; \ + CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGET_ARCH) go build -o $(BUILD_PATH)$$dir ${CMD_PATH}$$dir; \ + echo "Built $$dir for Linux/$(TARGET_ARCH)"; \ done .PHONY: build-local