Skip to content

Commit

Permalink
build: Dont build and run swagger for release builds
Browse files Browse the repository at this point in the history
* This is due to mixing CGO and Go builds (swag) during cross compiling. There is no added value in running swagger for release builds, so disable them

Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Jul 6, 2024
1 parent a2dae34 commit 7b2fc9c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ common-unused:
$(GO) mod tidy
@git diff --exit-code -- go.sum go.mod

# Dont bother updating swagger docs for release builds
.PHONY: common-build
common-build: promu swag
ifeq ($(RELEASE_BUILD), 0)
ifeq ($(CGO_BUILD), 1)
@echo ">> updating swagger docs"
$(SWAG) init -d $(SWAGGER_DIR) -g $(SWAGGER_MAIN) -o $(SWAGGER_DIR)/docs --pd --quiet
$(SWAG) fmt -d $(SWAGGER_DIR) -g $(SWAGGER_MAIN)
endif
ifeq ($(RELEASE_BUILD), 0)
@echo ">> building test binaries"
$(PROMU_TEST) build --prefix $(PREFIX) $(PROMU_BINARIES)
endif
Expand Down Expand Up @@ -239,14 +240,15 @@ $(PROMU):
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
rm -r $(PROMU_TMP)

# Set CC and CXX vars here else during cross compilation swag will be built in ARCH
# specific bin folder like $(GOPATH)/bin/linux_386/swag. By setting CC and CXX we are
# explicitly saying it to build as default arch and bin will be placed in $(GOPATH)/bin
# Dont run swagger for release builds. This is due to cross compiling with GOARCH set
# to different archs and swag will be built in arch specific bin folder.
.PHONY: swag
swag: $(SWAG)
$(SWAG):
ifeq ($(RELEASE_BUILD), 0)
ifeq ($(CGO_BUILD), 1)
cc='gcc' cxx='g++' GOARCH='amd64' $(GO) install github.com/swaggo/swag/cmd/[email protected]
$(GO) install github.com/swaggo/swag/cmd/[email protected]
endif
endif

.PHONY: proto
Expand Down

0 comments on commit 7b2fc9c

Please sign in to comment.