-
Notifications
You must be signed in to change notification settings - Fork 2
/
meson.build
271 lines (233 loc) · 6.72 KB
/
meson.build
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
project('donet', 'rust',
version: '0.1.0',
meson_version: '>= 1.1.0',
default_options: [ 'warning_level=2', 'werror=false', ],
)
# Check MinGW or equivalent for Windows build machines
# See: https://github.com/mesonbuild/meson/issues/8776
if build_machine.system() == 'windows'
assert(
find_program('bash', required: false).found(),
'Windows detected, but no GNU core utils found.\n\t' +
'A MinGW environment, or equivalent, is required to build Donet.'
)
endif
git_bin = find_program('git', required: true)
cargo_bin = find_program('cargo', required: true)
find_program('ninja', required: true)
sphinx_bin = find_program('sphinx-build', required: false)
date_bin = find_program('date', required: true)
daemon_bin = meson.project_name() + 'd'
vcs_tag = run_command(git_bin, 'rev-parse', 'HEAD', check: false).stdout().strip()
build_timestamp = run_command(date_bin, '--rfc-email', check: false).stdout().strip()
# The Git branch name is the version name for sphinx docs in the live site
git_branch = get_option('ci_branch')
if git_branch == ''
git_branch = run_command(git_bin, 'branch', '--show-current', check: true).stdout().strip()
endif
# Used in configuring Sphinx documentation to link sources to the repo.
sphinx_version = '7.4'
sphinx_release = 'master' # Full version tag (major.minor.patch)
doc_versions = '[["master", "/master"]]' # Python nested list
git_host = 'gitlab'
git_host_user = 'donet-server'
git_host_repo = 'donet'
git_url = 'https://gitlab.com/' + git_host_user + '/' + git_host_repo
donet_website_url = 'https://www.donet-server.org'
libdonet_website_url = 'https://docs.donet-server.org/donet_core'
sphinx_website_url = 'https://docs.donet-server.org'
# Cargo build options and environment variables
cargo_opts = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
cargo_opts += [ '--target-dir', meson.project_build_root() / 'target' ]
cargo_env = environment()
cargo_env.set('CARGO_HOME', meson.project_build_root() / 'cargo-home')
feature_flags = []
if get_option('profile') == 'release'
cargo_opts += [ '--release' ]
rust_target = 'release'
message('Building Donet for Release.')
else
rust_target = 'debug'
feature_flags += ['tokio_debugging']
# Needed for Tokio async runtime instrumentation
cargo_env.set('RUSTFLAGS', '--cfg tokio_unstable')
message('Building Donet for Debug.')
endif
if get_option('dockerized')
feature_flags += ['dockerized']
endif
if get_option('build_client_agent')
feature_flags += [ 'client-agent' ]
message('Building the Client Agent.')
endif
if get_option('build_message_director')
feature_flags += [ 'message-director' ]
message('Building the Message Director.')
endif
if get_option('build_state_server')
feature_flags += [ 'state-server' ]
message('Building the State Server.')
endif
if get_option('build_database_server')
feature_flags += [ 'database-server' ]
message('Building the Database Server.')
endif
if get_option('build_dbss')
feature_flags += [ 'dbss' ]
message('Building the DBSS.')
endif
if get_option('build_event_logger')
feature_flags += [ 'event-logger' ]
message('Building the Event Logger.')
endif
# Convert FF list to argument string for --features option
cargo_ff_arg = ''
first_flag = false
foreach ff : feature_flags
if first_flag == false
cargo_ff_arg += ff
first_flag = true
else
cargo_ff_arg += ',' + ff
endif
endforeach
if feature_flags.length() > 0
cargo_opts += [ '--no-default-features', '--features', cargo_ff_arg ]
else
message('Building all default Donet services.')
endif
subdir('donet-daemon')
subdir('docs')
run_target(
'update',
env: cargo_env,
command: [ cargo_bin, 'update', '--verbose' ]
)
cargo_build = custom_target(
'cargo-build',
build_by_default: true,
build_always_stale: true,
output: 'cargo_build', # See 'outdir' custom target
console: true,
env: cargo_env,
command: [
cargo_bin, 'build', cargo_opts,
]
)
# Replace below with `--out-dir` cargo option once stable.
# Issue: https://github.com/rust-lang/cargo/issues/6790
custom_target(
'outdir',
build_by_default: true,
build_always_stale: true,
output: meson.project_name(),
console: true,
command: [
'cp', 'target' / rust_target / daemon_bin, '@BUILD_ROOT@',
],
depends: cargo_build
)
cargo_doc = custom_target(
'cargo-doc',
build_by_default: false,
build_always_stale: true,
output: 'doc',
console: true,
env: cargo_env,
command: [
cargo_bin, 'doc', cargo_opts, '--lib', '--no-deps',
'--document-private-items', '--config',
'build.rustdocflags="--default-theme=ayu"'
],
)
clippy = custom_target(
'clippy',
env: cargo_env,
output: 'clippy',
command: [
cargo_bin, 'clippy', '--color=always', cargo_opts,
],
)
run_target(
'linting',
env: cargo_env,
command: [
cargo_bin, 'fmt', '--all', '--', '--color=always', '--check',
],
depends: clippy,
)
cargo_deny = custom_target(
'cargo-deny',
env: cargo_env,
output: 'cargo-deny',
command: [
cargo_bin, 'install', 'cargo-deny', '--locked',
],
)
run_target(
'deny',
env: cargo_env,
command: [
cargo_bin, 'deny', '--manifest-path',
meson.project_source_root() / 'Cargo.toml', 'check'
],
depends: cargo_deny
)
cargo_tarpaulin = custom_target(
'cargo-tarpaulin',
output: 'cargo-tarpaulin',
env: cargo_env,
command: [
cargo_bin, 'install', 'cargo-tarpaulin',
]
)
# Runs cargo-tarpaulin to create code coverage JSON and XML files,
# which is used by the GitLab CI/CD job to upload to codecov.io.
run_target(
'code-coverage',
env: cargo_env,
command: [
cargo_bin, 'tarpaulin',
'--force-clean', '--all',
'--exclude-files', 'build/*',
'--exclude-files', 'builddebug/*',
'--out', 'xml',
'--output-dir', meson.project_build_root() / 'target' / 'tarpaulin',
cargo_opts
],
depends: cargo_tarpaulin,
)
# Build unit tests without running. This outputs the binary
# for the unit tests in the target directory, which can then
# be debugged using GDB or an equivalent.
run_target(
'build-tests',
env: cargo_env,
command: [
cargo_bin, 'test', '--no-run', cargo_opts,
]
)
# Wrapper for `meson test`, but adds the `--verbose`
# flag so it actually outputs `cargo test` stdout/stderr.
run_target(
'tests',
command: [ 'meson', 'test', '--verbose' ],
)
test(
'cargo-test',
cargo_bin,
env: cargo_env,
args: [
'test', '--color=always', '--all',
cargo_opts,
],
is_parallel: false,
timeout: 1800,
)
message('Setting up Git pre-commit hook..')
run_command('cp', '-f', 'build-aux/git/pre-commit.hook', '.git/hooks/pre-commit', check: false)
meson.add_dist_script(
'build-aux/meson/dist-vendor.sh',
meson.project_build_root() / 'meson-dist' / meson.project_name() + '-' + meson.project_version(),
meson.project_source_root()
)