forked from picodata/picodata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
194 lines (157 loc) · 6.22 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
# Cargo supports posix jobserver protocol to restrict its parallelism.
# XXX: we don't need to propagate -jN if N > 1, make jobserver got us covered.
# https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html
MAKE_JOBSERVER_ARGS = $(filter -j%, $(MAKEFLAGS))
ifneq ($(MAKE_JOBSERVER_ARGS),-j1)
MAKE_JOBSERVER_ARGS =
endif
# Select appropriate pytest parallelism flags.
PYTEST_NUMPROCESSES = $(patsubst -j%, --numprocesses=%, $(filter -j%, $(MAKEFLAGS)))
ifeq ($(PYTEST_NUMPROCESSES),)
PYTEST_NUMPROCESSES = --numprocesses=auto
endif
# It should be possible to keep the flags to the bare minimum.
# Hence, we don't use `override` here but add it to all build prerequisites.
CARGO_FLAGS := --features webui --all
PYTEST_FLAGS :=
# For clarity and an ability to turn it off without overriding whole CARGO_FLAGS
ERROR_INJECTION := --features error_injection
# Devs may want to drop this flag using make LOCKED=
LOCKED := --locked
.PHONY: default
default: ;
.PHONY: tarantool-patch
tarantool-patch:
if test ! -f tarantool-sys/VERSION || \
test "${VER_TNT}" != "$(cat tarantool-sys/VERSION)"; then \
echo "${VER_TNT}" > tarantool-sys/VERSION; \
fi
# CARGO_FLAGS_EXTRA is meant to be set outside the makefile by user
.PHONY: build
build: tarantool-patch
if test -f ~/.cargo/env; then . ~/.cargo/env; fi && $(CARGO_ENV) \
cargo build $(LOCKED) $(MAKE_JOBSERVER_ARGS) $(CARGO_FLAGS) $(CARGO_FLAGS_EXTRA)
# There are 4 build options. 3 for each build profile (dev, fast-release, release).
# They are intended to be consumed by tests/local development.
# Remaining `build-release-pkg` is intended for packages we ship as our release artifacts.
# For now the only difference is absence of error_injection feature.
.PHONY: build-dev
build-dev: override CARGO_FLAGS += --profile=dev $(ERROR_INJECTION)
build-dev: build
.PHONY: build-fast-release
build-fast-release: override CARGO_FLAGS += --profile=fast-release $(ERROR_INJECTION)
build-fast-release: build
.PHONY: build-release
build-release: override CARGO_FLAGS += --profile=release $(ERROR_INJECTION)
build-release: build
.PHONY: build-release-pkg
build-release-pkg: override CARGO_FLAGS += --profile=release
build-release-pkg: build
# We have to specify target to disable ASan for proc macros, build.rs, etc.
# See https://github.com/rust-lang/cargo/issues/6375#issuecomment-444900324.
DEFAULT_TARGET := $(shell cargo -vV | sed -n 's|host: ||p')
# TODO: drop nightly features once sanitizers are stable.
.PHONY: build-asan-dev
build-asan-dev: override CARGO_ENV = RUSTC_BOOTSTRAP=1 RUSTFLAGS=-Zsanitizer=address
build-asan-dev: override CARGO_FLAGS += --profile=asan-dev --target=$(DEFAULT_TARGET)
build-asan-dev: build
# XXX: make sure we pass proper flags to cargo test so resulting picodata binary is reused
# can be reused for python tests without recompilation
# Note: tarantool and tlua are skipped intentionally, no need to run their doc tests in picodata
# Note: non-doc tests and doc tests are run separately. This is intended to prevent excessive
# memory usage caused by doc tests compilation model. Doc tests are compiled as part of actual test run.
# So, each parallel thread lanuched by cargo test spawns full blown compiler for each doctest
# which at the end leads to OOM.
.PHONY: test
test:
cargo test $(LOCKED) $(MAKE_JOBSERVER_ARGS) $(CARGO_FLAGS) $(CARGO_FLAGS_EXTRA) $(ERROR_INJECTION) \
--exclude sbroad-core \
--exclude tarantool \
--exclude tlua \
--tests
cargo test $(LOCKED) $(MAKE_JOBSERVER_ARGS) $(CARGO_FLAGS) $(CARGO_FLAGS_EXTRA) $(ERROR_INJECTION) \
--exclude sbroad-core \
--exclude tarantool \
--exclude tlua \
--doc -- --test-threads 2
poetry run pytest $(PYTEST_NUMPROCESSES) $(PYTEST_FLAGS) -vv --color=yes
.PHONY: generate
generate:
poetry run python test/generate_snapshot.py
.PHONY: lint
lint:
cargo version
cargo fmt --check
cargo check $(LOCKED) $(MAKE_JOBSERVER_ARGS)
cargo clippy --version
cargo clippy \
$(LOCKED) $(MAKE_JOBSERVER_ARGS) $(CARGO_FLAGS) \
--features=load_test,error_injection \
--exclude picodata-plugin \
--exclude sbroad-core \
--exclude tarantool \
--exclude tlua \
-- --deny clippy::all --no-deps
RUSTDOCFLAGS="-Dwarnings -Arustdoc::private_intra_doc_links" \
cargo doc \
$(LOCKED) $(MAKE_JOBSERVER_ARGS) \
--workspace --no-deps --document-private-items \
--exclude=tlua --exclude=sbroad-core --exclude=tarantool
poetry run flake8 ./test
poetry run black ./test --check --diff
poetry run mypy ./test
.PHONY: fmt
fmt:
cargo fmt
poetry run black ./test
.PHONY: clean
clean:
cargo clean || true
git submodule foreach --recursive 'git clean -dxf && git reset --hard'
find . -type d -name __pycache__ | xargs -n 500 rm -rf
.PHONY: benchmark
benchmark:
PICODATA_LOG_LEVEL=warn poetry run pytest test/manual/test_benchmark.py
.PHONY: flamegraph
flamegraph:
PICODATA_LOG_LEVEL=warn poetry run pytest test/manual/test_benchmark.py --with-flamegraph
.PHONY: k6
k6:
PICODATA_LOG_LEVEL=warn poetry run pytest test/manual/sql/test_sql_perf.py
.PHONY: install
install:
mkdir -p $(DESTDIR)/usr/bin
install -m 0755 target/*/picodata $(DESTDIR)/usr/bin/picodata
# IMPORTANT. This rule is primarily used in CI pack stage. It repeats
# the behavior of build.rs `build_webui()`, but uses a different out_dir
# `picodata-webui/dist` instead of `target/debug/build/picodata-webui`
.PHONY: build-webui-bundle
build-webui-bundle:
yarn --cwd webui install \
--prefer-offline \
--frozen-lockfile \
--no-progress \
--non-interactive
yarn --cwd webui vite build \
--outDir dist \
--emptyOutDir
.PHONY: reset-submodules
reset-submodules:
git submodule foreach --recursive 'git clean -dxf && git reset --hard'
git submodule update --init --recursive
.PHONY: install-cargo
install-cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |\
sh -s -- -y --profile default --default-toolchain 1.76.0
.PHONY: centos7-cmake3
centos7-cmake3:
if [ ! -L /usr/bin/cmake3 ] ; then \
[ -f /usr/bin/cmake ] && sudo rm /usr/bin/cmake; \
sudo ln -s /usr/bin/cmake3 /usr/bin/cmake; \
fi
sudo find {/opt,/usr} -name libgomp.spec -delete
publish-picodata-plugin:
cargo publish --dry-run -p picodata-plugin-proc-macro
cargo publish -p picodata-plugin-proc-macro
cargo publish --dry-run -p picodata-plugin
cargo publish -p picodata-plugin