Skip to content

Commit 157c87e

Browse files
committed
Move setup to Makefile
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
1 parent dfa54b2 commit 157c87e

File tree

2 files changed

+52
-59
lines changed

2 files changed

+52
-59
lines changed

.github/workflows/ci-pr-checks.yaml

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,12 @@ jobs:
2525
run: |
2626
sudo apt-get update
2727
sudo apt-get install -y pkg-config python3-dev python3-pip
28-
make download-zmq
28+
make install-dependencies
2929
pip3 install transformers --break-system-packages
3030
31-
- name: Configure CGO for Python
32-
run: |
33-
PYTHON_INCLUDE=$(python3 -c "import sysconfig; print(sysconfig.get_path('include'))")
34-
echo "CPATH=${PYTHON_INCLUDE}:${CPATH}" >> $GITHUB_ENV
35-
echo "CGO_ENABLED=1" >> $GITHUB_ENV
36-
echo "CGO_CFLAGS=$(python3-config --cflags --embed)" >> $GITHUB_ENV
37-
echo "CGO_LDFLAGS=$(python3-config --ldflags --embed)" >> $GITHUB_ENV
38-
39-
- name: Set PKG_CONFIG_PATH and PYTHONPATH
40-
run: |
41-
echo "PKG_CONFIG_PATH=/usr/lib/pkgconfig" >> $GITHUB_ENV
42-
GOMODCACHE=$(go env GOMODCACHE)
43-
# Extract kv-cache-manager version from go.mod
44-
KV_CACHE_MGR_VERSION=$(go list -m -f '{{.Version}}' github.com/llm-d/llm-d-kv-cache-manager)
45-
KV_CACHE_MGR_PATH="${GOMODCACHE}/github.com/llm-d/llm-d-kv-cache-manager@${KV_CACHE_MGR_VERSION}/pkg/preprocessing/chat_completions"
46-
echo "PYTHONPATH=${KV_CACHE_MGR_PATH}:${PYTHONPATH}" >> $GITHUB_ENV
47-
4831
- name: Run lint checks
49-
uses: golangci/golangci-lint-action@v8
50-
with:
51-
version: 'v2.4.0'
52-
args: "--config=./.golangci.yml"
53-
env:
54-
CGO_ENABLED: ${{ env.CGO_ENABLED }}
55-
CGO_CFLAGS: ${{ env.CGO_CFLAGS }}
56-
CGO_LDFLAGS: ${{ env.CGO_LDFLAGS }}
57-
CPATH: ${{ env.CPATH }}
58-
PKG_CONFIG_PATH: ${{ env.PKG_CONFIG_PATH }}
32+
run: |
33+
make lint
5934
6035
- name: Build Container image
6136
run: |
@@ -64,12 +39,4 @@ jobs:
6439
- name: Run go test
6540
shell: bash
6641
run: |
67-
echo "Running tests with Ginkgo..."
6842
make test
69-
env:
70-
CGO_ENABLED: ${{ env.CGO_ENABLED }}
71-
CGO_CFLAGS: ${{ env.CGO_CFLAGS }}
72-
CGO_LDFLAGS: ${{ env.CGO_LDFLAGS }}
73-
CPATH: ${{ env.CPATH }}
74-
PKG_CONFIG_PATH: ${{ env.PKG_CONFIG_PATH }}
75-
PYTHONPATH: ${{ env.PYTHONPATH }}

Makefile

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ 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+
60+
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
61+
62+
GOMODCACHE := $(shell go env GOMODCACHE)
63+
KV_CACHE_MGR_VERSION := $(shell go list -m -f '{{.Version}}' github.com/llm-d/llm-d-kv-cache-manager)
64+
KV_CACHE_MGR_PATH := $(GOMODCACHE)/github.com/llm-d/llm-d-kv-cache-manager@$(KV_CACHE_MGR_VERSION)/pkg/preprocessing/chat_completions
65+
export PYTHONPATH := $(KV_CACHE_MGR_PATH):$(PYTHONPATH)
66+
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)
72+
5673
GO_LDFLAGS := -extldflags '-L$(shell pwd)/lib $(LDFLAGS)'
5774
CGO_ENABLED=1
5875
TOKENIZER_LIB = lib/libtokenizers.a
@@ -82,7 +99,7 @@ format: ## Format Go source files
8299
@gofmt -l -w $(SRC)
83100

84101
.PHONY: test
85-
test: $(GINKGO) download-tokenizer download-zmq ## Run tests
102+
test: $(GINKGO) install-dependencies ## Run tests
86103
@printf "\033[33;1m==== Running tests ====\033[0m\n"
87104
ifdef GINKGO_FOCUS
88105
CGO_ENABLED=1 ginkgo -ldflags="$(GO_LDFLAGS)" -v -r -- -ginkgo.v -ginkgo.focus="$(GINKGO_FOCUS)"
@@ -103,7 +120,7 @@ lint: $(GOLANGCI_LINT) ## Run lint
103120
##@ Build
104121

105122
.PHONY: build
106-
build: check-go download-tokenizer download-zmq
123+
build: check-go install-dependencies
107124
@printf "\033[33;1m==== Building ====\033[0m\n"
108125
go build -ldflags="$(GO_LDFLAGS)" -o $(LOCALBIN)/$(PROJECT_NAME) cmd/$(PROJECT_NAME)/main.go
109126

@@ -217,32 +234,41 @@ install-hooks: ## Install git hooks
217234

218235
##@ ZMQ Setup
219236

220-
.PHONY: download-zmq
221-
download-zmq: ## Install ZMQ dependencies based on OS/ARCH
222-
@echo "⏳ Checking if ZMQ is already installed..."
223-
@if pkg-config --exists libzmq; then \
224-
echo "✅ ZMQ is already installed."; \
225-
else \
226-
echo "⏳ Installing ZMQ dependencies..."; \
227-
if [ "$(TARGETOS)" = "linux" ]; then \
228-
if command -v apt >/dev/null 2>&1; then \
229-
sudo apt update && sudo apt install -y libzmq3-dev; \
230-
elif command -v dnf >/dev/null 2>&1; then \
231-
sudo dnf install -y zeromq-devel; \
237+
.PHONY: install-dependencies
238+
install-dependencies: download-tokenizer ## Install development dependencies based on OS/ARCH
239+
@echo "Checking and installing development dependencies..."
240+
@if [ "$(TARGETOS)" = "linux" ]; then \
241+
if [ -x "$$(command -v apt)" ]; then \
242+
if ! dpkg -s libzmq3-dev >/dev/null 2>&1 || ! dpkg -s g++ >/dev/null 2>&1; then \
243+
echo "Installing dependencies with apt..."; \
244+
sudo apt-get update && apt-get install -y libzmq3-dev g++; \
232245
else \
233-
echo -e "⚠️ Unsupported Linux package manager. Follow installation guides: https://github.com/zeromq/libzmq#installation-of-binary-packages-\n"; \
234-
exit 1; \
246+
echo "✅ ZMQ and g++ are already installed."; \
235247
fi; \
236-
elif [ "$(TARGETOS)" = "darwin" ]; then \
237-
if command -v brew >/dev/null 2>&1; then \
238-
brew install zeromq; \
248+
elif [ -x "$$(command -v dnf)" ]; then \
249+
if ! dnf -q list installed zeromq-devel >/dev/null 2>&1 || ! dnf -q list installed gcc-c++ >/dev/null 2>&1; then \
250+
echo "Installing dependencies with dnf..."; \
251+
sudo dnf install -y zeromq-devel gcc-c++; \
239252
else \
240-
echo "⚠️ Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/"; \
241-
exit 1; \
253+
echo "✅ ZMQ and gcc-c++ are already installed."; \
242254
fi; \
243255
else \
244-
echo "⚠️ Unsupported OS: $(TARGETOS). Install libzmq manually - see https://zeromq.org/download/"; \
256+
echo "Unsupported Linux package manager. Install libzmq and g++/gcc-c++ manually."; \
245257
exit 1; \
246258
fi; \
247-
echo "✅ ZMQ dependencies installed."; \
259+
elif [ "$(TARGETOS)" = "darwin" ]; then \
260+
if [ -x "$$(command -v brew)" ]; then \
261+
if ! brew list zeromq pkg-config >/dev/null 2>&1; then \
262+
echo "Installing dependencies with brew..."; \
263+
brew install zeromq pkg-config; \
264+
else \
265+
echo "✅ ZeroMQ and pkgconf are already installed."; \
266+
fi; \
267+
else \
268+
echo "Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/"; \
269+
exit 1; \
270+
fi; \
271+
else \
272+
echo "Unsupported OS: $(TARGETOS). Install development dependencies manually."; \
273+
exit 1; \
248274
fi

0 commit comments

Comments
 (0)