forked from RedisJSON/RedisJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
291 lines (214 loc) · 7.78 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
ROOT=.
include $(ROOT)/deps/readies/mk/main
#----------------------------------------------------------------------------------------------
define HELPTEXT
make setup # install prerequisites
make build
NIGHTLY=1 # use nightly toolchain
DEBUG=1 # build debug variant
SAN=type # build with LLVM sanitizer (type=address|memory|leak|thread)
VALGRIND|VG=1 # build for testing with Valgrind
make clean # remove binary files
ALL=1 # remove binary directories
make all # build all libraries and packages
make run # run redis-server with RedisJSON module
make pytest # run flow tests using RLTest
TEST=file:name # run test matching `name` from `file`
TEST_ARGS="..." # RLTest arguments
QUICK=1 # run only general tests
GEN=1 # run general tests on a standalone Redis topology
AOF=1 # run AOF persistency tests on a standalone Redis topology
SLAVES=1 # run replication tests on standalone Redis topology
CLUSTER=1 # run general tests on a OSS Redis Cluster topology
VERBOSE=1 # display more RLTest-related information
SAN=type # use LLVM sanitizer (type=address|memory|leak|thread)
VG=1 # run specified tests with Valgrind
make bench # run benchmarks
make pack # build package (RAMP file)
make upload-artifacts # copy snapshot packages to S3
OSNICK=nick # copy snapshots for specific OSNICK
make upload-release # copy release packages to S3
common options for upload operations:
STAGING=1 # copy to staging lab area (for validation)
FORCE=1 # allow operation outside CI environment
VERBOSE=1 # show more details
NOP=1 # do not copy, just print commands
make coverage # perform coverage analysis
make show-cov # show coverage analysis results (implies COV=1)
make upload-cov # upload coverage analysis results to codecov.io (implies COV=1)
make docker # build for specific Linux distribution
OSNICK=nick # Linux distribution to build for
REDIS_VER=ver # use Redis version `ver`
TEST=1 # test aftar build
PACK=1 # create packages
ARTIFACTS=1 # copy artifacts from docker image
PUBLISH=1 # publish (i.e. docker push) after build
make sanbox # create container for CLang Sanitizer tests
endef
#----------------------------------------------------------------------------------------------
SRCDIR=src
MK_CUSTOM_CLEAN=1
BINDIR=$(BINROOT)
include $(MK)/defs
include $(MK)/rules
#----------------------------------------------------------------------------------------------
MODULE_NAME=rejson.so
RUST_TARGET:=$(shell eval $$(rustc --print cfg | grep =); echo $$target_arch-$$target_vendor-$$target_os-$$target_env)
CARGO_TOOLCHAIN=
CARGO_FLAGS=
RUST_FLAGS=
RUST_DOCFLAGS=
ifeq ($(DEBUG),1)
ifeq ($(SAN),)
TARGET_DIR=$(BINDIR)/target/debug
else
NIGHTLY=1
CARGO_FLAGS += -Zbuild-std
RUST_FLAGS += -Zsanitizer=$(SAN) -C link-args=-znostart-stop-gc
ifeq ($(SAN),memory)
RUST_FLAGS += -Zsanitizer-memory-track-origins
endif
endif
else
CARGO_FLAGS += --release
TARGET_DIR=$(BINDIR)/target/release
endif
ifeq ($(COV),1)
RUST_FLAGS += -C instrument_coverage
endif
ifeq ($(PROFILE),1)
RUST_FLAGS += -g -C force-frame-pointers=yes
endif
ifeq ($(NIGHTLY),1)
TARGET_DIR=$(BINDIR)/target/$(RUST_TARGET)/debug
ifeq ($(RUST_GOOD_NIGHTLY),)
CARGO_TOOLCHAIN = +nightly
else
CARGO_TOOLCHAIN = +$(RUST_GOOD_NIGHTLY)
endif
endif
export CARGO_TARGET_DIR=$(BINDIR)/target
TARGET=$(BINDIR)/$(MODULE_NAME)
#----------------------------------------------------------------------------------------------
setup:
$(SHOW)./sbin/setup
update:
$(SHOW)cargo update
.PHONY: setup update
#----------------------------------------------------------------------------------------------
lint:
$(SHOW)cargo fmt -- --check
.PHONY: lint
#----------------------------------------------------------------------------------------------
define extract_symbols
$(SHOW)objcopy --only-keep-debug $1 $1.debug
$(SHOW)objcopy --strip-debug $1
$(SHOW)objcopy --add-gnu-debuglink $1.debug $1
endef
RUST_SOEXT.linux=so
RUST_SOEXT.freebsd=so
RUST_SOEXT.macos=dylib
build:
ifneq ($(NIGHTLY),1)
$(SHOW)set -e ;\
export RUSTFLAGS="$(RUST_FLAGS)" ;\
cargo build --all --all-targets $(CARGO_FLAGS)
else
$(SHOW)set -e ;\
export RUSTFLAGS="$(RUST_FLAGS)" ;\
export RUSTDOCFLAGS="$(RUST_DOCFLAGS)" ;\
cargo $(CARGO_TOOLCHAIN) build --target $(RUST_TARGET) $(CARGO_FLAGS)
endif
$(SHOW)cp $(TARGET_DIR)/librejson.$(RUST_SOEXT.$(OS)) $(TARGET)
ifneq ($(DEBUG),1)
ifneq ($(OS),macos)
$(SHOW)$(call extract_symbols,$(TARGET))
endif
endif
clean:
ifneq ($(ALL),1)
$(SHOW)cargo clean
else
$(SHOW)rm -rf $(BINDIR)
endif
.PHONY: build clean
#----------------------------------------------------------------------------------------------
run:
$(SHOW)if ! command -v redis-server &> /dev/null; then \
>&2 echo "redis-server not found." ;\
>&2 echo "Install it with ./deps/readies/bin/getredis" ;\
else \
redis-server --loadmodule $(TARGET) ;\
fi
.PHONY: run
#----------------------------------------------------------------------------------------------
test: cargo_test pytest
pytest:
$(SHOW)MODULE=$(abspath $(TARGET)) RLTEST_ARGS='--no-progress' $(realpath ./tests/pytest/tests.sh)
cargo_test:
$(SHOW)cargo $(CARGO_TOOLCHAIN) test --all
.PHONY: pytest cargo_test
#----------------------------------------------------------------------------------------------
ifneq ($(REMOTE),)
BENCHMARK_ARGS = run-remote
else
BENCHMARK_ARGS = run-local
endif
BENCHMARK_ARGS += --module_path $(realpath $(TARGET)) --required-module ReJSON
ifneq ($(BENCHMARK),)
BENCHMARK_ARGS += --test $(BENCHMARK)
endif
bench benchmark: $(TARGET)
$(SHOW)set -e ;\
cd tests/benchmarks ;\
redisbench-admin $(BENCHMARK_ARGS)
.PHONY: bench benchmark
#----------------------------------------------------------------------------------------------
pack:
$(SHOW)MODULE=$(abspath $(TARGET)) ./sbin/pack.sh
upload-release:
$(SHOW)RELEASE=1 ./sbin/upload-artifacts
upload-artifacts:
$(SHOW)SNAPSHOT=1 ./sbin/upload-artifacts
.PHONY: pack upload-artifacts upload-release
#----------------------------------------------------------------------------------------------
clang-install:
./sbin/install_clang.sh
.PHONY: clang-install
#----------------------------------------------------------------------------------------------
COV_EXCLUDE_DIRS += bin deps tests
COV_EXCLUDE.llvm += $(foreach D,$(COV_EXCLUDE_DIRS),'$(realpath $(ROOT))/$(D)/*')
coverage:
$(SHOW)$(MAKE) build COV=1
$(SHOW)$(COVERAGE_RESET.llvm)
-$(SHOW)$(MAKE) test COV=1
$(SHOW)$(COVERAGE_COLLECT_REPORT.llvm)
.PHONY: coverage
#----------------------------------------------------------------------------------------------
docker:
$(SHOW)$(MAKE) -C build/docker
ifeq ($(PUBLISH),1)
$(SHOW)make -C build/docker publish
endif
.PHONY: docker
#----------------------------------------------------------------------------------------------
ifneq ($(wildcard /w/*),)
SANBOX_ARGS += -v /w:/w
endif
sanbox:
@docker run -it -v $(PWD):/rejson -w /rejson --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
$(SANBOX_ARGS) redisfab/clang:16-x64-focal bash
.PHONY: sanbox
#----------------------------------------------------------------------------------------------
info:
$(SHOW)if command -v redis-server &> /dev/null; then redis-server --version; fi
$(SHOW)rustc --version
$(SHOW)cargo --version
$(SHOW)rustup --version
$(SHOW)rustup show
$(SHOW)if command -v gcc &> /dev/null; then gcc --version; fi
$(SHOW)if command -v clang &> /dev/null; then clang --version; fi
$(SHOW)if command -v cmake &> /dev/null; then cmake --version; fi
$(SHOW)python3 --version
$(SHOW)python3 -m pip list -v
.PHONY: info