Skip to content

Commit a15923f

Browse files
authored
Fix Makefile (#278)
* Fix Makefile Signed-off-by: irar2 <[email protected]> * Added CGO_CFLAGS to lint Signed-off-by: irar2 <[email protected]> --------- Signed-off-by: irar2 <[email protected]>
1 parent 847a06a commit a15923f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Makefile

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,26 @@ SRC = $(shell find . -type f -name '*.go')
5353
help: ## Print help
5454
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
5555

56-
PYTHON_INCLUDE := $(shell python3 -c "import sysconfig; print(sysconfig.get_path('include'))")
57-
CGO_CFLAGS := $(shell python3-config --cflags --embed)
58-
CGO_LDFLAGS := $(shell python3-config --ldflags --embed)
59-
6056
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
6157

58+
##@ Python Configuration
59+
60+
PYTHON_VERSION := 3.12
61+
62+
# Unified Python configuration detection. This block runs once.
63+
PYTHON_CONFIG ?= $(shell command -v python$(PYTHON_VERSION)-config || command -v python3-config)
64+
65+
CGO_CFLAGS := $(shell $(PYTHON_CONFIG) --cflags --embed)
66+
CGO_LDFLAGS := $(shell $(PYTHON_CONFIG) --ldflags --embed)
67+
6268
GOMODCACHE := $(shell go env GOMODCACHE)
6369
KV_CACHE_MGR_VERSION := $(shell go list -m -f '{{.Version}}' github.com/llm-d/llm-d-kv-cache-manager)
6470
KV_CACHE_MGR_PATH := $(GOMODCACHE)/github.com/llm-d/llm-d-kv-cache-manager@$(KV_CACHE_MGR_VERSION)/pkg/preprocessing/chat_completions
6571
export PYTHONPATH := $(KV_CACHE_MGR_PATH):$(PYTHONPATH)
6672

67-
# Export them for all targets (optional)
68-
export CGO_ENABLED=1
69-
export CGO_CFLAGS
70-
export CGO_LDFLAGS
71-
export CPATH := $(PYTHON_INCLUDE):$(CPATH)
73+
CPATH := $(PYTHON_INCLUDE):$(CPATH)
7274

73-
GO_LDFLAGS := -extldflags '-L$(shell pwd)/lib $(LDFLAGS)'
75+
GO_LDFLAGS := -extldflags '-L$(shell pwd)/lib $(LDFLAGS) $(CGO_LDFLAGS)'
7476
CGO_ENABLED=1
7577
TOKENIZER_LIB = lib/libtokenizers.a
7678
# Extract TOKENIZER_VERSION from Dockerfile
@@ -102,9 +104,9 @@ format: ## Format Go source files
102104
test: $(GINKGO) install-dependencies ## Run tests
103105
@printf "\033[33;1m==== Running tests ====\033[0m\n"
104106
ifdef GINKGO_FOCUS
105-
CGO_ENABLED=1 ginkgo -ldflags="$(GO_LDFLAGS)" -v -r -- -ginkgo.v -ginkgo.focus="$(GINKGO_FOCUS)"
107+
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" $(GINKGO) -ldflags="$(GO_LDFLAGS)" -v -r -- -ginkgo.v -ginkgo.focus="$(GINKGO_FOCUS)"
106108
else
107-
CGO_ENABLED=1 $(GINKGO) -ldflags="$(GO_LDFLAGS)" -v -r
109+
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" $(GINKGO) -ldflags="$(GO_LDFLAGS)" -v -r $(TEST_PKG)
108110
endif
109111

110112
.PHONY: post-deploy-test
@@ -115,14 +117,14 @@ post-deploy-test: ## Run post deployment tests
115117
.PHONY: lint
116118
lint: $(GOLANGCI_LINT) ## Run lint
117119
@printf "\033[33;1m==== Running linting ====\033[0m\n"
118-
$(GOLANGCI_LINT) run
120+
CGO_CFLAGS="$(CGO_CFLAGS)" $(GOLANGCI_LINT) run
119121

120122
##@ Build
121123

122124
.PHONY: build
123125
build: check-go install-dependencies
124126
@printf "\033[33;1m==== Building ====\033[0m\n"
125-
go build -ldflags="$(GO_LDFLAGS)" -o $(LOCALBIN)/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go
127+
CGO_CFLAGS="$(CGO_CFLAGS)" go build -ldflags="$(GO_LDFLAGS)" -o $(LOCALBIN)/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go
126128

127129
##@ Container Build/Push
128130

0 commit comments

Comments
 (0)