-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
131 lines (107 loc) · 3.66 KB
/
Makefile
File metadata and controls
131 lines (107 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
.PHONY: build build-debug build-release clean test test-go test-rust test-all lint lint-go lint-rust fmt fmt-go fmt-rust help
GOLANGCI_LINT_VERSION := v2.5.0
GOLANGCI_LINT_CMD := go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
UNAME_S := $(shell uname -s 2>/dev/null || echo UNKNOWN)
OS_ENV := $(OS)
ifeq ($(UNAME_S),UNKNOWN)
$(warning uname -s failed; OS detection will rely on OS env and fallback rules)
endif
ifeq ($(OS_ENV),Windows_NT)
HOST_OS := windows
else ifneq (,$(findstring MINGW,$(UNAME_S)))
HOST_OS := windows
else ifneq (,$(findstring MSYS,$(UNAME_S)))
HOST_OS := windows
else ifneq (,$(findstring CYGWIN,$(UNAME_S)))
HOST_OS := windows
else ifeq ($(UNAME_S),Darwin)
HOST_OS := darwin
else ifeq ($(UNAME_S),Linux)
HOST_OS := linux
else ifeq ($(UNAME_S),UNKNOWN)
HOST_OS := linux
else
HOST_OS := linux
$(warning unrecognized uname -s '$(UNAME_S)'; defaulting HOST_OS to linux)
endif
ifeq ($(HOST_OS),darwin)
LIB_NAME := libhnsw_toolbox.dylib
else ifeq ($(HOST_OS),windows)
LIB_NAME := hnsw_toolbox.dll
else
LIB_NAME := libhnsw_toolbox.so
endif
TARGET_DIR_ENV := $(strip $(CARGO_TARGET_DIR))
ifeq ($(TARGET_DIR_ENV),)
TARGET_DIR := target
else ifneq ($(filter /%,$(TARGET_DIR_ENV)),)
TARGET_DIR := $(TARGET_DIR_ENV)
else ifneq ($(findstring :,$(TARGET_DIR_ENV)),)
TARGET_DIR := $(TARGET_DIR_ENV)
else ifneq ($(findstring \\,$(TARGET_DIR_ENV)),)
TARGET_DIR := $(TARGET_DIR_ENV)
else
TARGET_DIR := $(TARGET_DIR_ENV)
endif
TARGET_DEBUG := $(TARGET_DIR)/debug/$(LIB_NAME)
TARGET_RELEASE := $(TARGET_DIR)/release/$(LIB_NAME)
ifeq ($(HOST_OS),windows)
VERIFY_DEBUG_ARTIFACT := @echo "Skipping POSIX artifact check on Windows Make host."
VERIFY_RELEASE_ARTIFACT := @echo "Skipping POSIX artifact check on Windows Make host."
else
VERIFY_DEBUG_ARTIFACT := @test -f "$(TARGET_DEBUG)" || (echo "Expected debug library not found at $(TARGET_DEBUG). Check CARGO_TARGET_DIR." && exit 1)
VERIFY_RELEASE_ARTIFACT := @test -f "$(TARGET_RELEASE)" || (echo "Expected release library not found at $(TARGET_RELEASE). Check CARGO_TARGET_DIR." && exit 1)
endif
help:
@echo "hnsw-toolbox Build System"
@echo ""
@echo "Available targets:"
@echo " build - Build Rust library in debug mode"
@echo " build-debug - Build Rust library in debug mode"
@echo " build-release - Build Rust library in release mode"
@echo " test - Run Go + Rust tests"
@echo " test-go - Run Go tests"
@echo " test-rust - Run Rust tests"
@echo " test-all - Run Go + Rust tests"
@echo " lint - Run Go and Rust linters"
@echo " lint-go - Run golangci-lint"
@echo " lint-rust - Run cargo clippy with -D warnings"
@echo " fmt - Format Go and Rust code"
@echo " fmt-go - Format Go code"
@echo " fmt-rust - Format Rust code"
@echo " clean - Clean Rust target directory"
@echo ""
@echo "Environment variables:"
@echo " CARGO_TARGET_DIR - Optional cargo target directory override"
build: build-debug
build-debug:
cargo build --locked
$(VERIFY_DEBUG_ARTIFACT)
@echo "Built debug library at $(TARGET_DEBUG)"
build-release:
cargo build --locked --release
$(VERIFY_RELEASE_ARTIFACT)
@echo "Built release library at $(TARGET_RELEASE)"
test: test-all
test-go:
go test ./...
test-rust:
cargo test --locked
test-all: test-go test-rust
lint: lint-go lint-rust
lint-go:
$(GOLANGCI_LINT_CMD) run --timeout=5m ./...
lint-rust:
cargo clippy --locked --all-targets -- -D warnings
fmt: fmt-go fmt-rust
fmt-go:
gofmt -w .
@if command -v goimports >/dev/null 2>&1; then \
goimports -w .; \
else \
echo "goimports not found; skipping goimports formatting"; \
fi
fmt-rust:
cargo fmt
clean:
cargo clean