-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (95 loc) · 4.28 KB
/
Makefile
File metadata and controls
122 lines (95 loc) · 4.28 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
# --- Configuration Variables ---
VERSION ?= $(shell git describe --tags --abbrev=0 || echo "v0.0.0")
BINARY_NAME=kektordb
RELEASE_DIR=release
# --- Main Targets ---
.PHONY: all test test-rust bench bench-rust clean release
# The default target is a quick test of the pure Go build
all: test
# Runs the Go version
run:
@echo "==> Running KektorDB (Go-pure implementation)..."
@go run ./cmd/kektordb/ $(ARGS)
# Run the Rust-optimized version
run-rust: build-rust-native
@echo "==> Running KektorDB (Rust CGO implementation)..."
@CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/release" \
go run -tags rust ./cmd/kektordb/ $(ARGS)
# --- Test Targets and Benchmarks ---
test: generate-avo
@echo "==> Running Go tests (Go/AVO implementation)..."
@go test -short -v ./...
test-rust: build-rust-native
@echo "==> Running Go tests (Rust CGO implementation)..."
@CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/release" \
go test -tags rust -short -v ./...
bench: generate-avo
@echo "==> Running Go benchmarks (Go/AVO implementation)..."
@go test -bench=. ./...
bench-rust: build-rust-native
@echo "==> Running Go benchmarks (Rust CGO implementation)..."
@CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/release" \
go test -tags rust -bench=. ./...
# --- Build Target ---
# Build Rust for the current native platform
build-rust-native:
@echo "==> Building Rust compute library (native)..."
@cd native/compute && cargo build --release
# Compile Rust for a specific target (used by the release)
build-rust-target:
@echo "==> Building Rust compute library for target: $(TARGET)..."
@cd native/compute && cargo build --release --target=$(TARGET)
generate-avo:
@echo "==> Generating Assembly code with AVO..."
@go generate ./pkg/core/distance/avo_gen.go
# --- Release Target ---
# This is the main command that will be executed by GitHub Actions
release: clean
@echo "Building releases for all targets..."
@mkdir -p $(RELEASE_DIR)
# Linux AMD64
@make release-build TARGET=x86_64-unknown-linux-gnu ZIG_TARGET=x86_64-linux-gnu \
GOOS=linux GOARCH=amd64 \
CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/x86_64-unknown-linux-gnu/release -lkektordb_compute -ldl -lm -lgcc_s -lc -lpthread"
# Linux ARM64
@make release-build TARGET=aarch64-unknown-linux-gnu ZIG_TARGET=aarch64-linux-gnu \
GOOS=linux GOARCH=arm64 \
CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/aarch64-unknown-linux-gnu/release -lkektordb_compute -ldl -lm -lgcc_s -lc -lpthread"
# Windows AMD64
@make release-build TARGET=x86_64-pc-windows-gnu ZIG_TARGET=x86_64-windows-gnu \
GOOS=windows GOARCH=amd64 EXT=.exe \
CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/x86_64-pc-windows-gnu/release -lkektordb_compute -lws2_32 -luserenv -ladvapi32 -lbcrypt -lntdll -lgcc_s"
# --- macOS (Go Puro) ---
# target release-build-pure.
@make release-build-pure GOOS=darwin GOARCH=amd64
@make release-build-pure GOOS=darwin GOARCH=arm64
# macOS AMD64
# @make release-build TARGET=x86_64-apple-darwin ZIG_TARGET=x86_64-macos-none \
# GOOS=darwin GOARCH=amd64 \
# CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/x86_64-apple-darwin/release -lkektordb_compute -ldl -lm"
# macOS ARM64
# @make release-build TARGET=aarch64-apple-darwin ZIG_TARGET=aarch64-macos-none \
# GOOS=darwin GOARCH=arm64 \
# CGO_LDFLAGS="-L$(CURDIR)/native/compute/target/aarch64-apple-darwin/release -lkektordb_compute -ldl -lm"
# Rust-optimized build (for Linux and Windows)
release-build: build-rust-target
@echo "==> Cross-compiling KektorDB for $(GOOS)/$(GOARCH)..."
@echo "Using Linker Flags: $(CGO_LDFLAGS)"
@CGO_LDFLAGS="$(CGO_LDFLAGS)" \
CGO_ENABLED=1 \
GOOS=$(GOOS) GOARCH=$(GOARCH) \
CC="zig cc -target $(ZIG_TARGET)" CXX="zig c++ -target $(ZIG_TARGET)" \
go build -tags "rust netgo" -ldflags="-s -w" -o "$(RELEASE_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)$(EXT)" ./cmd/kektordb
# Pure Go build (for macOS)
release-build-pure:
@echo "==> Compiling pure-Go KektorDB for $(GOOS)/$(GOARCH)..."
@CGO_ENABLED=0 \
GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build -ldflags="-s -w" -o "$(RELEASE_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)$(EXT)" ./cmd/kektordb
# --- Cleaning ---
clean:
@echo "==> Aggressively cleaning all caches and artifacts..."
@rm -f pkg/core/distance/distance_avo_amd64.s pkg/core/distance/stubs_avo_amd64.go
@rm -rf native/compute/target
@rm -rf $(RELEASE_DIR)
@go clean -cache -testcache