.DEFAULT_GOAL := help
BINARY_NAME := octobrain
VERSION := $(shell grep '^version =' Cargo.toml | cut -d '"' -f2)
RUST_VERSION := $(shell rustc --version)
TARGET_DIR := target
RELEASE_DIR := $(TARGET_DIR)/release
DEBUG_DIR := $(TARGET_DIR)/debug
TARGETS := x86_64-unknown-linux-musl \
aarch64-unknown-linux-musl \
x86_64-pc-windows-msvc \
aarch64-pc-windows-msvc
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
BLUE := \033[0;34m
NC := \033[0m
GIT_AVAILABLE := $(shell git status >/dev/null 2>&1 && echo "yes" || echo "no")
.PHONY: help
help:
@echo "$(BLUE)octobrain v$(VERSION)$(NC)"
@echo "$(BLUE)Rust version: $(RUST_VERSION)$(NC)"
@echo ""
@echo "$(YELLOW)Available targets:$(NC)"
@awk 'BEGIN {FS = ":.*##"}; /^[a-zA-Z_-]+:.*##/ { printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
@echo ""
@echo "$(YELLOW)Usage:$(NC)"
@echo " make $(GREEN)<target>$(NC) @echo " make $(GREEN)build$(NC) @echo " make $(GREEN)build-release$(NC) @echo " make $(GREEN)install$(NC) @echo " make $(GREEN)install-completions$(NC) @echo " make $(GREEN)check$(NC) @echo " make $(GREEN)fmt$(NC) @echo " make $(GREEN)clippy$(NC) @echo " make $(GREEN)test$(NC) @echo " make $(GREEN)clean$(NC) @echo " make $(GREEN)install-deps$(NC) @echo " make $(GREEN)run$(NC) @echo " make $(GREEN)run-release$(NC) @echo ""
@echo "$(YELLOW)For more information, see INSTRUCTIONS.md$(NC)"
.PHONY: install-deps
install-deps:
@echo "$(YELLOW)Installing development dependencies...$(NC)"
trustup component add clippy rustfmt
@echo "$(GREEN)Dependencies installed successfully$(NC)"
.PHONY: install-targets
install-targets:
@echo "$(YELLOW)Installing compilation targets...$(NC)"
@for target in $(TARGETS); do \
echo "Installing $$target..."; \
rustup target add $$target; \
done
@echo "$(GREEN)Compilation targets installed$(NC)"
.PHONY: check
check:
@echo "$(YELLOW)Running cargo check...$(NC)"
cargo check --no-default-features --all-targets
@echo "$(GREEN)Cargo check passed$(NC)"
.PHONY: fmt
fmt:
@echo "$(YELLOW)Formatting code...$(NC)"
cargo fmt --all -- --check
@echo "$(GREEN)Code formatted$(NC)"
.PHONY: clippy
clippy:
@echo "$(YELLOW)Running clippy lints...$(NC)"
cargo clippy --no-default-features --all-targets -- -D warnings
@echo "$(GREEN)Clippy checks passed$(NC)"
.PHONY: test
test:
@echo "$(YELLOW)Running tests...$(NC)"
cargo test --verbose --no-default-features
@echo "$(GREEN)Tests passed$(NC)"
.PHONY: test-fastembed
test-fastembed:
@echo "$(YELLOW)Running tests with fastembed feature...$(NC)"
cargo test --verbose --no-default-features --features fastembed
@echo "$(GREEN)Tests passed with fastembed$(NC)"
.PHONY: test-huggingface
test-huggingface:
@echo "$(YELLOW)Running tests with huggingface feature...$(NC)"
cargo test --verbose --no-default-features --features huggingface
@echo "$(GREEN)Tests passed with huggingface$(NC)"
.PHONY: test-all-features
test-all-features:
@echo "$(YELLOW)Running tests with all features...$(NC)"
cargo test --verbose --no-default-features --features "fastembed,huggingface"
@echo "$(GREEN)Tests passed with all features$(NC)"
.PHONY: check-features
check-features:
@echo "$(YELLOW)Checking all feature combinations...$(NC)"
@echo "$(BLUE)1. No features...$(NC)"
@cargo check --no-default-features --all-targets
@echo "$(BLUE)2. FastEmbed only...$(NC)"
@cargo check --no-default-features --features fastembed --all-targets
@echo "$(BLUE)3. HuggingFace only...$(NC)"
@cargo check --no-default-features --features huggingface --all-targets
@echo "$(BLUE)4. All features...$(NC)"
@cargo check --no-default-features --features "fastembed,huggingface" --all-targets
@echo "$(GREEN)All feature combinations checked successfully$(NC)"
.PHONY: clean
clean:
@echo "$(YELLOW)Cleaning build artifacts...$(NC)"
cargo clean
@echo "$(GREEN)Build artifacts cleaned$(NC)"
.PHONY: install
install: build-release
@echo "$(YELLOW)Installing $(BINARY_NAME)...$(NC)"
cargo install --path .
@echo "$(GREEN)$(BINARY_NAME) installed successfully$(NC)"
.PHONY: uninstall
uninstall:
@echo "$(YELLOW)Uninstalling $(BINARY_NAME)...$(NC)"
cargo uninstall $(BINARY_NAME)
@echo "$(GREEN)$(BINARY_NAME) uninstalled successfully$(NC)"
.PHONY: install-completions
install-completions: build-release
@echo "$(YELLOW)Installing shell completions...$(NC)"
./scripts/install-completions.sh
@echo "$(GREEN)Shell completions installed!$(NC)"
.PHONY: test-completions
test-completions: build-release
@echo "$(YELLOW)Testing shell completion generation...$(NC)"
./scripts/test-completions.sh
@echo "$(GREEN)Completion tests passed!$(NC)"
.PHONY: run
run:
@echo "$(YELLOW)Running $(BINARY_NAME) in debug mode...$(NC)"
cargo run --no-default-features
@echo "$(GREEN)Application exited$(NC)"
.PHONY: run-release
run-release:
@echo "$(YELLOW)Running $(BINARY_NAME) in release mode...$(NC)"
cargo run --no-default-features --release
@echo "$(GREEN)Application exited$(NC)"
.PHONY: build
build:
@echo "$(YELLOW)Building $(BINARY_NAME) in debug mode...$(NC)"
cargo build --no-default-features
@echo "$(GREEN)Build complete$(NC)"
.PHONY: build-release
build-release:
@echo "$(YELLOW)Building $(BINARY_NAME) in release mode...$(NC)"
cargo build --no-default-features --release
@echo "$(GREEN)Release binary built: $(RELEASE_DIR)/$(BINARY_NAME)$(NC)"
.PHONY: build-all
build-all: install-targets
@echo "$(YELLOW)Building for all supported platforms...$(NC)"
@for target in $(TARGETS); do \
echo "Building $$target..."; \
cargo build --no-default-features --release --target $$target; \
if [ $$? -eq 0 ]; then \
echo "$(GREEN)✓ $$target built successfully$(NC)"; \
else \
echo "$(RED)✗ $$target build failed$(NC)"; \
fi; \
done
@echo "$(GREEN)All targets built successfully$(NC)"
.PHONY: ci
ci: format-check lint test
@echo "$(GREEN)All CI checks passed!$(NC)"
.PHONY: ci-quick
ci-quick: format-check lint
@echo "$(GREEN)Quick CI checks passed!$(NC)"
$(TARGET_DIR):
mkdir -p $(TARGET_DIR)
$(RELEASE_DIR): $(TARGET_DIR)
mkdir -p $(RELEASE_DIR)
$(DEBUG_DIR): $(TARGET_DIR)
mkdir -p $(DEBUG_DIR)