Skip to content

Commit 4c8321e

Browse files
authored
fix: make 'install-dependencies' and 'build' target (#493)
* fix: make 'install-dependencies' require sudo on Linux - create a new target 'check-dependencies' and fix check - dnf list installed only show avaiable package not the ones installed or not. use rpm instead. - when running "make test-*" only check not install depdencies - better instruction requies user sudo before run 'install-dependencies' - add fallback when "sudo" Go not in the PATH, "go env" wont work, use "uname" to get OS and ARCH Signed-off-by: Wen Zhou <wenzhou@redhat.com> * fix: make build is not working since missing CGO_CFLAGS and CGOL_LDFLAGS - local also require python3-devel package to get python header file, add it into "install-dependencies" target Signed-off-by: Wen Zhou <wenzhou@redhat.com> * fix: tab was used in Makefile, replace with spaces Signed-off-by: Wen Zhou <wenzhou@redhat.com> --------- Signed-off-by: Wen Zhou <wenzhou@redhat.com>
1 parent e11b6f1 commit 4c8321e

File tree

1 file changed

+54
-25
lines changed

1 file changed

+54
-25
lines changed

Makefile

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ include Makefile.tools.mk
44
SHELL := /usr/bin/env bash
55

66
# Defaults
7-
TARGETOS ?= $(shell go env GOOS)
8-
TARGETARCH ?= $(shell go env GOARCH)
7+
TARGETOS ?= $(shell command -v go >/dev/null 2>&1 && go env GOOS || uname -s | tr '[:upper:]' '[:lower:]')
8+
TARGETARCH ?= $(shell command -v go >/dev/null 2>&1 && go env GOARCH || uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/; s/armv7l/arm/')
99
PROJECT_NAME ?= llm-d-inference-scheduler
1010
SIDECAR_IMAGE_NAME ?= llm-d-routing-sidecar
1111
VLLM_SIMULATOR_IMAGE_NAME ?= llm-d-inference-sim
@@ -69,24 +69,24 @@ PYTHON_VERSION := 3.12
6969
PYTHON_CONFIG ?= $(shell command -v python$(PYTHON_VERSION)-config || command -v python3-config)
7070
ifeq ($(PYTHON_CONFIG),)
7171
ifeq ($(TARGETOS),darwin)
72-
# macOS: Find Homebrew's python-config script for the most reliable flags.
73-
BREW_PREFIX := $(shell command -v brew >/dev/null 2>&1 && brew --prefix python@$(PYTHON_VERSION) 2>/dev/null)
74-
PYTHON_CONFIG ?= $(BREW_PREFIX)/bin/python$(PYTHON_VERSION)-config
75-
PYTHON_ERROR := "Could not execute 'python$(PYTHON_VERSION)-config'. Please ensure Python is installed correctly with: 'brew install python@$(PYTHON_VERSION)' or install python3.12 manually."
72+
# macOS: Find Homebrew's python-config script for the most reliable flags.
73+
BREW_PREFIX := $(shell command -v brew >/dev/null 2>&1 && brew --prefix python@$(PYTHON_VERSION) 2>/dev/null)
74+
PYTHON_CONFIG ?= $(BREW_PREFIX)/bin/python$(PYTHON_VERSION)-config
75+
PYTHON_ERROR := "Could not execute 'python$(PYTHON_VERSION)-config'. Please ensure Python is installed correctly with: 'brew install python@$(PYTHON_VERSION)' or install python3.12 manually."
7676
else ifeq ($(TARGETOS),linux)
77-
# Linux: Use standard system tools to find flags.
78-
PYTHON_ERROR := "Python $(PYTHON_VERSION) development headers not found. Please install with: 'sudo apt install python$(PYTHON_VERSION)-dev' or 'sudo dnf install python$(PYTHON_VERSION)-devel'"
77+
# Linux: Use standard system tools to find flags.
78+
PYTHON_ERROR := "Python $(PYTHON_VERSION) development headers not found. Please install with: 'sudo apt install python$(PYTHON_VERSION)-dev' or 'sudo dnf install python$(PYTHON_VERSION)-devel'"
7979
else
80-
PYTHON_ERROR := "you should set up PYTHON_CONFIG variable manually"
80+
PYTHON_ERROR := "you should set up PYTHON_CONFIG variable manually"
8181
endif
8282
endif
8383

8484
ifneq ($(shell $(PYTHON_CONFIG) --cflags 2>/dev/null),)
85-
PYTHON_CFLAGS := $(shell $(PYTHON_CONFIG) --cflags)
86-
# Use --ldflags --embed to get all necessary flags for linking
87-
PYTHON_LDFLAGS := $(shell $(PYTHON_CONFIG) --ldflags --embed)
85+
PYTHON_CFLAGS := $(shell $(PYTHON_CONFIG) --cflags)
86+
# Use --ldflags --embed to get all necessary flags for linking
87+
PYTHON_LDFLAGS := $(shell $(PYTHON_CONFIG) --ldflags --embed)
8888
else
89-
$(error ${PYTHON_ERROR})
89+
$(error $(PYTHON_ERROR))
9090
endif
9191

9292
# CGO flags with all dependencies
@@ -147,12 +147,12 @@ test: test-unit test-e2e ## Run unit tests and e2e tests
147147
test-unit: test-unit-epp test-unit-sidecar
148148

149149
.PHONY: test-unit-%
150-
test-unit-%: download-tokenizer install-dependencies ## Run unit tests
150+
test-unit-%: download-tokenizer check-dependencies ## Run unit tests
151151
@printf "\033[33;1m==== Running Unit Tests ====\033[0m\n"
152152
CGO_CFLAGS=${$*_CGO_CFLAGS} CGO_LDFLAGS=${$*_CGO_LDFLAGS} go test $($*_LDFLAGS) -v $$($($*_TEST_FILES) | tr '\n' ' ')
153153

154154
.PHONY: test-integration
155-
test-integration: download-tokenizer install-dependencies ## Run integration tests
155+
test-integration: download-tokenizer check-dependencies ## Run integration tests
156156
@printf "\033[33;1m==== Running Integration Tests ====\033[0m\n"
157157
go test -ldflags="$(LDFLAGS)" -v -tags=integration_tests ./test/integration/
158158

@@ -178,7 +178,7 @@ lint: check-golangci-lint check-typos ## Run lint
178178
build: build-epp build-sidecar ## Build the project
179179

180180
.PHONY: build-%
181-
build-%: check-go install-dependencies download-tokenizer ## Build the project
181+
build-%: check-go download-tokenizer ## Build the project
182182
@printf "\033[33;1m==== Building ====\033[0m\n"
183183
go build $($*_LDFLAGS) -o bin/$($*_NAME) cmd/$($*_NAME)/main.go
184184

@@ -456,26 +456,55 @@ clean-env-dev-kubernetes: check-kubectl check-kustomize check-envsubst
456456

457457
##@ Dependencies
458458

459+
.PHONY: check-dependencies
460+
check-dependencies: ## Check if development dependencies are installed
461+
@if [ "$(TARGETOS)" = "linux" ]; then \
462+
if [ -x "$$(command -v apt)" ]; then \
463+
if ! dpkg -s libzmq3-dev >/dev/null 2>&1 || ! dpkg -s g++ >/dev/null 2>&1 || ! dpkg -s python$(PYTHON_VERSION)-dev >/dev/null 2>&1; then \
464+
echo "ERROR: Missing dependencies. Please run 'sudo make install-dependencies'"; \
465+
exit 1; \
466+
fi; \
467+
elif [ -x "$$(command -v dnf)" ]; then \
468+
if ! rpm -q zeromq-devel >/dev/null 2>&1 || ! rpm -q gcc-c++ >/dev/null 2>&1 || ! rpm -q python$(PYTHON_VERSION)-devel >/dev/null 2>&1; then \
469+
echo "ERROR: Missing dependencies. Please run 'sudo make install-dependencies'"; \
470+
exit 1; \
471+
fi; \
472+
else \
473+
echo "WARNING: Unsupported Linux package manager. Cannot verify dependencies."; \
474+
fi; \
475+
elif [ "$(TARGETOS)" = "darwin" ]; then \
476+
if [ -x "$$(command -v brew)" ]; then \
477+
if ! brew list zeromq pkg-config >/dev/null 2>&1; then \
478+
echo "ERROR: Missing dependencies. Please run 'make install-dependencies'"; \
479+
exit 1; \
480+
fi; \
481+
else \
482+
echo "ERROR: Homebrew is not installed and is required. Install it from https://brew.sh/"; \
483+
exit 1; \
484+
fi; \
485+
fi
486+
@echo "✅ All dependencies are installed."
487+
459488
.PHONY: install-dependencies
460489
install-dependencies: ## Install development dependencies based on OS/ARCH
461490
@echo "Checking and installing development dependencies..."
462491
@if [ "$(TARGETOS)" = "linux" ]; then \
463492
if [ -x "$$(command -v apt)" ]; then \
464-
if ! dpkg -s libzmq3-dev >/dev/null 2>&1 || ! dpkg -s g++ >/dev/null 2>&1; then \
493+
if ! dpkg -s libzmq3-dev >/dev/null 2>&1 || ! dpkg -s g++ >/dev/null 2>&1 || ! dpkg -s python$(PYTHON_VERSION)-dev >/dev/null 2>&1; then \
465494
echo "Installing dependencies with apt..."; \
466-
apt-get update && apt-get install -y libzmq3-dev g++; \
495+
apt-get update && apt-get install -y libzmq3-dev g++ python$(PYTHON_VERSION)-dev; \
467496
else \
468-
echo "✅ ZMQ and g++ are already installed."; \
497+
echo "✅ ZMQ, g++, and Python dev headers are already installed."; \
469498
fi; \
470499
elif [ -x "$$(command -v dnf)" ]; then \
471-
if ! dnf -q list installed zeromq-devel >/dev/null 2>&1 || ! dnf -q list installed gcc-c++ >/dev/null 2>&1; then \
500+
if ! rpm -q zeromq-devel >/dev/null 2>&1 || ! rpm -q gcc-c++ >/dev/null 2>&1 || ! rpm -q python$(PYTHON_VERSION)-devel >/dev/null 2>&1; then \
472501
echo "Installing dependencies with dnf..."; \
473-
dnf install -y zeromq-devel gcc-c++; \
502+
dnf install -y zeromq-devel gcc-c++ python$(PYTHON_VERSION)-devel; \
474503
else \
475-
echo "✅ ZMQ and gcc-c++ are already installed."; \
504+
echo "✅ ZMQ, gcc-c++, and Python dev headers are already installed."; \
476505
fi; \
477506
else \
478-
echo "Unsupported Linux package manager. Install libzmq and g++/gcc-c++ manually."; \
507+
echo "ERROR: Unsupported Linux package manager. Install libzmq, g++/gcc-c++, and python-devel manually."; \
479508
exit 1; \
480509
fi; \
481510
elif [ "$(TARGETOS)" = "darwin" ]; then \
@@ -487,10 +516,10 @@ install-dependencies: ## Install development dependencies based on OS/ARCH
487516
echo "✅ ZeroMQ and pkgconf are already installed."; \
488517
fi; \
489518
else \
490-
echo "Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/"; \
519+
echo "ERROR: Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/"; \
491520
exit 1; \
492521
fi; \
493522
else \
494-
echo "Unsupported OS: $(TARGETOS). Install development dependencies manually."; \
523+
echo "ERROR: Unsupported OS: $(TARGETOS). Install development dependencies manually."; \
495524
exit 1; \
496525
fi

0 commit comments

Comments
 (0)