Skip to content

Commit

Permalink
build: Allow passing in custom -ldflags
Browse files Browse the repository at this point in the history
This change allows passing in additional options for Go's `-ldflags`,
for example to pass in `-s -w` to reduce binary size.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
  • Loading branch information
dbussink committed Aug 8, 2023
1 parent 30d90fb commit 0eadde9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ ifdef VT_EXTRA_BUILD_FLAGS
export EXTRA_BUILD_FLAGS := $(VT_EXTRA_BUILD_FLAGS)
endif

ifdef VT_EXTRA_BUILD_LDFLAGS
export EXTRA_BUILD_LDFLAGS := $(VT_EXTRA_BUILD_LDFLAGS)
endif

# This should be the root of the vitess Git directory.
ifndef VTROOT
export VTROOT=${PWD}
Expand All @@ -76,7 +80,7 @@ ifndef NOBANNER
endif
bash ./build.env
go build -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \
-ldflags "$(shell tools/build_version_flags.sh)" \
-ldflags "$(EXTRA_BUILD_LDFLAGS) $(shell tools/build_version_flags.sh)" \
-o ${VTROOTBIN} ./go/...

# build the vitess binaries statically
Expand All @@ -89,7 +93,7 @@ endif
# Binaries will be placed in ${VTROOTBIN}.
CGO_ENABLED=0 go build \
-trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \
-ldflags "$(shell tools/build_version_flags.sh)" \
-ldflags "$(EXTRA_BUILD_LDFLAGS) $(shell tools/build_version_flags.sh)" \
-o ${VTROOTBIN} ./go/...
ifndef NOVTADMINBUILD
echo "Building VTAdmin Web, disable VTAdmin build by setting 'NOVTADMINBUILD'"
Expand All @@ -111,7 +115,7 @@ endif
mkdir -p ${VTROOTBIN}/${GOOS}_${GOARCH}
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build \
-trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \
-ldflags "$(shell tools/build_version_flags.sh)" \
-ldflags "$(EXTRA_BUILD_LDFLAGS) $(shell tools/build_version_flags.sh)" \
-o ${VTROOTBIN}/${GOOS}_${GOARCH} ./go/...

@if [ ! -x "${VTROOTBIN}/${GOOS}_${GOARCH}/vttablet" ]; then \
Expand All @@ -125,7 +129,7 @@ endif
bash ./build.env
go build -trimpath \
$(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \
-ldflags "$(shell tools/build_version_flags.sh)" \
-ldflags "$(EXTRA_BUILD_LDFLAGS) $(shell tools/build_version_flags.sh)" \
-gcflags -'N -l' \
-o ${VTROOTBIN} ./go/...

Expand Down

0 comments on commit 0eadde9

Please sign in to comment.