Skip to content

Commit

Permalink
🐛 Refactor go-build option
Browse files Browse the repository at this point in the history
Signed-off-by: vankichi <[email protected]>
  • Loading branch information
vankichi committed Feb 9, 2024
1 parent 4248f8b commit b9c3a8d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.d/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ binary/build: \
cmd/agent/core/ngt/ngt: \
ngt/install
$(eval CGO_ENABLED = 1)
$(call go-build,agent/core/ngt,-linkmode 'external',-static -fPIC -pthread -fopenmp -std=gnu++20 -lstdc++ -lm -z relro -z now $(EXTLDFLAGS), cgo,NGT-$(NGT_VERSION),$@)
$(call go-build,agent/core/ngt,-linkmode 'external',-static -fPIC -pthread -fopenmp -std=gnu++20 -lstdc++ -lm -z relro -z now $(EXTLDFLAGS), cgo,NGT-$(NGT_VERSION),$@,CC_FOR_TARGET=${TARGET} CC=${CC} CGO_CFLAGS='${CGO_CFLAGS}')

cmd/agent/core/faiss/faiss: \
faiss/install
Expand Down
1 change: 1 addition & 0 deletions Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ define go-build
GOOS=$(GOOS) \
GOPRIVATE=$(GOPRIVATE) \
GO_VERSION=$(GO_VERSION) \
$7 \
go build \
--ldflags "-w $2 \
-extldflags '$3' \
Expand Down
14 changes: 12 additions & 2 deletions dockers/agent/core/ngt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ COPY go.sum .

RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \
--mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \
make GOARCH=${TARGETARCH} GOOS=${TARGETOS} go/download
if [ "${TARGETARCH}" = "amd64" ] ; then \
export CC=${XARCH}-${TARGETOS}-gnu-gcc; \
export TARGET=gcc-${XARCH_GCC}-${TARGETOS}-gnu ; \
elif [ "${TARGETARCH}" = "arm64" ] ; then \
export CC=${AARCH_GCC}-${TARGETOS}-gnu-gcc; \
export TARGET=gcc-${AARCH_GCC}-${TARGETOS}-gnu ; \
fi \
&& make GOARCH=${TARGETARCH} GOOS=${TARGETOS} go/download

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal
COPY internal .
Expand All @@ -112,10 +119,13 @@ RUN --mount=type=cache,target="${GOPATH}/pkg",id="go-build-${TARGETARCH}" \
--mount=type=cache,target="${HOME}/.cache/go-build",id="go-build-${TARGETARCH}" \
if [ "${TARGETARCH}" = "amd64" ] ; then \
export CC=${XARCH}-${TARGETOS}-gnu-gcc; \
export TARGET=gcc-${XARCH_GCC}-${TARGETOS}-gnu ; \
elif [ "${TARGETARCH}" = "arm64" ] ; then \
export CC=${AARCH_GCC}-${TARGETOS}-gnu-gcc; \
export TARGET=gcc-${AARCH_GCC}-${TARGETOS}-gnu ; \
export CGO_CFLAGS="-march=armv8-a" ; \
fi \
&& make GOARCH=${TARGETARCH} GOOS=${TARGETOS} CC_FOR_TARGET=${CC} REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \
&& make GOARCH=${TARGETARCH} GOOS=${TARGETOS} REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \
&& mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}"

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG}
Expand Down

0 comments on commit b9c3a8d

Please sign in to comment.