-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
234 lines (212 loc) · 6.89 KB
/
Makefile
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# Variables
CARGO := cargo
MAKE := make
TARGET_DIR := target
RELEASE_DIR := $(TARGET_DIR)/release
DEBUG_DIR := $(TARGET_DIR)/debug
BINARY_NAME := polycrypt_rs
RUST_LIB_PATH := $(shell pwd)/$(RELEASE_DIR)
GO_BUILD_FLAGS := -ldflags "-r $(RUST_LIB_PATH)"
GO_OUTPUT_BINARY := polycrypt_ffi_go
EXAMPLES_DIR := examples
GO_EXAMPLES_DIR := $(EXAMPLES_DIR)/go
PYTHON_EXAMPLES_DIR := $(EXAMPLES_DIR)/python
DB_SETUP_DIR := db/setup
GO_ENTRY_POINT := main.go
PYTHON_ENTRY_POINT := main.py
PYTHON_TEST_ENTRY_POINT := test.py
LIB_NAME := libpolycrypt_rs.so
# Colors
CYAN := \033[36m
GREEN := \033[32m
YELLOW := \033[33m
RED := \033[31m
RESET_COLOR := \033[0m
# Aesthetic
DASH_LINE := \033[90m---------------------------------------------------------------\033[0m
# Default target
# all: build
# Build for release and copy the library
build:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Building polycrypt-rs (release)...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) build --release
@echo "$(DASH_LINE)"
@echo "$(GREEN)Build completed successfully.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@echo "$(CYAN)Copying $(LIB_NAME) to Go and Python packages...$(RESET_COLOR)"
@cp $(RELEASE_DIR)/$(LIB_NAME) $(GO_EXAMPLES_DIR)/polycrypt/
@cp $(RELEASE_DIR)/$(LIB_NAME) $(PYTHON_EXAMPLES_DIR)/polycrypt/
@cp $(RELEASE_DIR)/$(LIB_NAME) $(DB_SETUP_DIR)/polycrypt/
@echo "$(GREEN)Library copied successfully.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Build for debug
debug:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Building polycrypt-rs (debug)...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) build
@echo "$(DASH_LINE)"
@echo "$(GREEN)Debug build completed successfully.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Run the program (release mode)
run: build
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running polycrypt-rs (release)...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(RELEASE_DIR)/$(BINARY_NAME)
@echo "$(DASH_LINE)"
# Run the program (debug mode)
run-debug: debug
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running polycrypt-rs (debug)...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(DEBUG_DIR)/$(BINARY_NAME)
@echo "$(DASH_LINE)"
# Run tests
test:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Rust tests for polycrypt-rs...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) test
@echo "$(DASH_LINE)"
@echo "$(GREEN)Rust tests completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Run benchmarks
bench:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running benchmarks for polycrypt-rs...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) bench --bench db_benchmarks
@echo "$(DASH_LINE)"
@echo "$(GREEN)Benchmarks completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
bench-heavy:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running heavy benchmarks...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@ENABLE_HEAVY_BENCHMARKS=1 $(CARGO) bench
@echo "$(DASH_LINE)"
@echo "$(GREEN)Heavy benchmarks completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Check the project for errors
check:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Checking polycrypt-rs for errors...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) check
@echo "$(DASH_LINE)"
@echo "$(GREEN)Check completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Format the code
fmt:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Formatting polycrypt-rs code...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) fmt
@echo "$(DASH_LINE)"
@echo "$(GREEN)Formatting completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Lint the code
lint:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Linting polycrypt-rs code...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) clippy
@echo "$(DASH_LINE)"
@echo "$(GREEN)Linting completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Clean the project
clean:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Cleaning polycrypt-rs project...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) clean
@rm -f $(EXAMPLES_DIR)/$(GO_OUTPUT_BINARY)
@rm -f $(GO_EXAMPLES_DIR)/polycrypt/$(LIB_NAME)
@rm -f $(GO_EXAMPLES_DIR)/polycrypt_ffi_go
@rm -f $(PYTHON_EXAMPLES_DIR)/polycrypt/$(LIB_NAME)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Cleaning completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Generate documentation
doc:
@echo "$(DASH_LINE)"
@echo "$(CYAN)Generating documentation for polycrypt-rs...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) doc --no-deps
@echo "$(DASH_LINE)"
@echo "$(GREEN)Documentation generated.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# FFI bindings tests
py-run: build
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Python example...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@RUST_LOG=debug python3 $(PYTHON_EXAMPLES_DIR)/$(PYTHON_ENTRY_POINT)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Python example completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Build the Go example
go-build: build
@echo "$(DASH_LINE)"
@echo "$(CYAN)Building Go example...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@cd $(GO_EXAMPLES_DIR) && go build $(GO_BUILD_FLAGS) -o $(GO_OUTPUT_BINARY) $(GO_ENTRY_POINT)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Go example built successfully.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Run the Go example
go-run: go-build
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Go example...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@cd $(GO_EXAMPLES_DIR) && ./$(GO_OUTPUT_BINARY)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Go example completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Run Go tests (including example tests)
go-test: build
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Go tests for polycrypt-rs...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@cd $(GO_EXAMPLES_DIR) && LD_LIBRARY_PATH=$(RUST_LIB_PATH) go test -v $(GO_BUILD_FLAGS)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Go tests completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Run Python tests (including example tests)
py-test: build
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Python tests for polycrypt-rs...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@cd $(PYTHON_EXAMPLES_DIR) && python3 -m unittest $(PYTHON_TEST_ENTRY_POINT)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Python tests completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
# Run all tests (Rust, Go, and Python)
test-all:
@echo "$(DASH_LINE)"
@echo "$(YELLOW)Running all tests for polycrypt-rs...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Rust tests...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@$(CARGO) test
@echo "$(DASH_LINE)"
@echo "$(GREEN)Rust tests completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Go tests...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@cd $(GO_EXAMPLES_DIR) && LD_LIBRARY_PATH=$(RUST_LIB_PATH) go test -v $(GO_BUILD_FLAGS)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Go tests completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@echo "$(CYAN)Running Python tests...$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@cd $(PYTHON_EXAMPLES_DIR) && python3 -m unittest $(PYTHON_TEST_ENTRY_POINT)
@echo "$(DASH_LINE)"
@echo "$(GREEN)Python tests completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
@echo "$(YELLOW)All tests for polycrypt-rs completed.$(RESET_COLOR)"
@echo "$(DASH_LINE)"
.PHONY: all build debug run run-debug test bench check fmt lint clean doc install uninstall py-run go-build go-run go-test py-test test-all