-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathMakefile.toml
More file actions
498 lines (431 loc) · 16.8 KB
/
Copy pathMakefile.toml
File metadata and controls
498 lines (431 loc) · 16.8 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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# NOTE: This file is automatically synchronized from Patina DevOps. Update the original file there
# instead of the file in this repo.
#
# - Patina DevOps Repo: https://github.com/OpenDevicePartnership/patina-devops
# - File Sync Settings: https://github.com/OpenDevicePartnership/patina-devops/blob/main/.sync/Files.yml
[config]
default_to_workspace = false
[env]
NO_STD_FLAGS = "--profile ${RUSTC_PROFILE} --timings"
STD_FLAGS = "--profile ${RUSTC_PROFILE} --features std"
COV_FLAGS = { value = "--workspace --profile test --ignore-filename-regex .*test.*", condition = { env_not_set = ["COV_FLAGS"] } }
RUSTDOCFLAGS = "-D warnings -D missing_docs"
[env.development]
RUSTC_PROFILE = "dev"
[env.release]
RUSTC_PROFILE = "release"
[tasks.install-tools]
description = """Installs the project tools pinned in the `[tools]` section of
`rust-toolchain.toml` at their specified versions. Each tool is installed with
`cargo binstall`, falling back to `cargo install` when a prebuilt binary is not
available. CI also installs and tests the tools in this section.
`cargo-binstall` (https://github.com/cargo-bins/cargo-binstall) is installed
automatically with `cargo install` when it is not already present.
Example:
`cargo make install-tools`
"""
clear = true
install_crate = false
script_runner = "@duckscript"
script = '''
# cargo-binstall is used to install tools.
binstall_path = which cargo-binstall
if is_empty ${binstall_path}
echo "==> cargo-binstall not found. Installing it with cargo install..."
exec --fail-on-error cargo install cargo-binstall
end
toolchain_file = readfile rust-toolchain.toml
lines = split ${toolchain_file} "\n"
# Track whether the current line is inside the `[tools]` section. Parsing runs
# from the `[tools]` header until the next section header.
in_tools = set false
for line in ${lines}
trimmed = trim ${line}
is_section = starts_with ${trimmed} "["
if ${is_section}
if eq ${trimmed} "[tools]"
in_tools = set true
else
in_tools = set false
end
elseif ${in_tools}
is_comment = starts_with ${trimmed} "#"
is_blank = is_empty ${trimmed}
has_assignment = contains ${trimmed} "="
# Only process `name = "version"` lines.
if not ${is_blank}
if not ${is_comment}
if ${has_assignment}
kv = split ${trimmed} "="
name = array_get ${kv} 0
name = trim ${name}
version = array_get ${kv} 1
version_parts = split ${version} "\""
version = array_get ${version_parts} 1
result = exec cargo binstall -y ${name} --version ${version}
output = set "${result.stdout}${result.stderr}"
if not eq ${result.code} "0"
echo " building ${name} ${version} from source (no prebuilt binary)..."
result = exec cargo install ${name} --version ${version}
output = set "${result.stdout}${result.stderr}"
end
if not eq ${result.code} "0"
echo " FAILED ${name} ${version}"
echo ${output}
exit 1
end
already = contains ${output} "already installed"
if ${already}
echo " up-to-date ${name} ${version}"
else
echo " installed ${name} ${version}"
end
end
end
end
end
end
'''
[tasks.individual-package-targets]
script_runner = "@duckscript"
script = '''
args = get_env CARGO_MAKE_TASK_ARGS
if is_empty ${args}
exit
end
1 = array ""
2 = split ${args} ,
3 = array_concat ${1} ${2}
joined_args = array_join ${3} " -p "
release ${1}
release ${2}
release ${3}
joined_args = trim ${joined_args}
set_env INDIVIDUAL_PACKAGE_TARGETS ${joined_args}
release ${joined_args}
'''
[tasks.build]
description = """Builds a single rust package with the standard library.
Customizations:
-p [development|release]: Builds in debug or release. Default: development
-e FEATURES=[feature,...]: Builds with the specified features. Default: none
Example:
`cargo make build`
`cargo make -p release build`
`cargo make -e FEATURES=feature1,feature2 build`
"""
alias = "build-std"
[tasks.build-std]
description = """Builds crates in the repository with the standard library, and their examples.
Customizations:
-p [development|release]: Builds in debug or release. Default: development
-e FEATURES=[feature,...]: Builds with the specified features. Default: none
Example:
`cargo make build-std`
`cargo make -p release build-std`
`cargo make build-std <package_name>`
"""
clear = true
command = "cargo"
args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )", "--examples"]
dependencies = ["individual-package-targets", "build-lib"]
[tasks.build-lib]
description = """Builds crates in the repository with the standard library.
Customizations:
-p [development|release]: Builds in debug or release. Default: development
-e FEATURES=[feature,...]: Builds with the specified features. Default: none
Example:
`cargo make build-lib`
`cargo make -p release build-lib`
`cargo make build-lib <package_name>`
"""
clear = true
command = "cargo"
args = ["build", "--all-features", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )"]
dependencies = ["individual-package-targets"]
[tasks.check_code_x64]
description = "Checks rust code for x64 build errors with results."
private = true
command = "cargo"
args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",]
[tasks.check_code_aarch64]
description = "Checks rust code for aarch64 build errors with results."
private = true
command = "cargo"
args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",]
[tasks.check_tests]
description = "Checks rust test code for build errors with results."
private = true
command = "cargo"
args = ["test", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS, )"]
[tasks.check-no-default-features-code]
description = "Checks rust code compiles without default features."
private = true
command = "cargo"
args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"]
[tasks.check-no-default-features-tests]
description = "Checks rust test code compiles without default features."
private = true
command = "cargo"
args = ["test", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"]
[tasks.check-no-default-features]
description = "Checks rust code and tests compile without default features to catch feature-gate regressions."
clear = true
run_task = [{ name = ["check-no-default-features-code", "check-no-default-features-tests"], parallel = true }]
[tasks.check]
description = "Checks rust code for errors. Example `cargo make check`"
clear = true
run_task = [{ name = ["check_code_x64", "check_code_aarch64", "check_tests"], parallel = true }]
[tasks.patina-test]
description = "Builds crates with Patina tests enabled. Example `cargo make patina-test`"
clear = true
command = "cargo"
args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )", "--features", "test-runner"]
dependencies = ["individual-package-targets"]
[tasks.generate-lockfile]
description = "Generate Cargo.lock file."
private = true
command = "cargo"
args = ["generate-lockfile"]
[tasks.llvm-cov-clean]
description = "Clean coverage data"
private = true
install_crate = false
command = "cargo"
args = ["llvm-cov", "clean", "--workspace"]
[tasks.test]
description = "Runs tests with native cargo test behavior. Example `cargo make test` or `cargo make test -p package_name -- --nocapture`"
clear = true
command = "cargo"
args = ["test", "@@split(CARGO_MAKE_TASK_ARGS,;)"]
[tasks.test-ignored]
description = "Runs ignored tests with native cargo test behavior. Example `cargo make test-ignored` or `cargo make test-ignored -p package_name"
clear = true
command = "cargo"
args = ["test", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--lib", "--tests", "--examples", "--", "--ignored"]
[tasks.test-cov]
description = "Run tests and collect coverage data without generating reports."
install_crate = false
clear = true
# `coverage_attribute` is deliberately excluded from the default allow-features in
# .cargo/config.toml so ungated `#[coverage(off)]` fails to compile. Coverage runs set the
# `coverage` cfg (set by cargo-llvm-cov), which needs the feature, so re-add it here.
# Note: RUSTFLAGS replaces build.rustflags.
env = { RUSTFLAGS = "-Z allow-features=c_variadic,allocator_api,coverage_attribute" }
command = "cargo"
args = ["llvm-cov", "@@split(COV_FLAGS, )", "--no-report", "--doctests"]
dependencies = ["individual-package-targets", "llvm-cov-clean"]
[tasks.test-asan]
description = "Run tests with AddressSanitizer enabled. Example `cargo make test-asan`. Use `cargo make test-asan --print-dll-path` to print the ASan runtime DLL directory."
clear = true
script_runner = "@duckscript"
script = '''
os = os_family
if eq ${os} "windows"
# ASan testing is only supported on Windows x64.
# https://learn.microsoft.com/cpp/sanitizers/asan
arch = get_env PROCESSOR_ARCHITECTURE
if not eq ${arch} "AMD64"
echo "test-asan is only supported on Windows x64. Detected arch: ${arch}. Skipping."
exit 0
end
# The ASan runtime DLL (clang_rt.asan_dynamic-x86_64.dll) from the
# MSVC toolchain must be on PATH for ASan-instrumented test binaries to run.
#
# Resolve the VC toolset path per vswhere docs:
# https://github.com/microsoft/vswhere/wiki/Find-VC
program_files_x86 = get_env "ProgramFiles(x86)"
vswhere = set "${program_files_x86}/Microsoft Visual Studio/Installer/vswhere.exe"
output = exec "${vswhere}" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
install_dir = trim ${output.stdout}
version = readfile "${install_dir}/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt"
version = trim ${version}
asan_dll_path = set "${install_dir}/VC/Tools/MSVC/${version}/bin/HostX64/x64"
args = get_env CARGO_MAKE_TASK_ARGS
if contains "${args}" "--print-dll-path"
asan_dll_path = replace ${asan_dll_path} / \\
echo "${asan_dll_path}"
exit 0
end
current_path = get_env PATH
set_env PATH "${asan_dll_path};${current_path}"
elseif eq ${os} "linux"
# On Linux, the ASan runtime is resolved automatically by the linker.
noop
else
echo "test-asan is not supported on ${os}. Skipping."
exit 0
end
set_env RUSTFLAGS "-Zsanitizer=address"
set_env RUSTDOCFLAGS "-Zsanitizer=address"
target = get_env CARGO_MAKE_RUST_TARGET_TRIPLE
exec --fail-on-error cargo test --target ${target} --workspace --features std
'''
[tasks.coverage-lcov]
description = "Generate an LCOV coverage report from collected data."
install_crate = false
clear = true
command = "cargo"
args = ["llvm-cov", "report", "--lcov", "--output-path", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/lcov.info"]
[tasks.coverage-html]
description = "Generate an HTML coverage report from collected data."
install_crate = false
clear = true
command = "cargo"
args = ["llvm-cov", "report", "--html", "--output-dir", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/coverage"]
[tasks.coverage]
description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports)."
dependencies = ["test-cov", "coverage-lcov", "coverage-html"]
clear = true
[tasks.build-aarch64]
description = "Builds crates in the repository for AARCH64"
clear = true
command = "cargo"
args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--target", "aarch64-unknown-uefi", "@@split(NO_STD_FLAGS, )", ]
dependencies = ["individual-package-targets"]
[tasks.build-x64]
description = "Builds crates in the repository for X64"
clear = true
command = "cargo"
args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--target", "x86_64-unknown-uefi", "@@split(NO_STD_FLAGS, )", ]
dependencies = ["individual-package-targets"]
[tasks.doc]
description = "Builds all rust documentation in the workspace. Example `cargo make doc`"
command = "cargo"
args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--no-deps"]
[tasks.doc-open]
description = "Builds all rust documentation in the workspace and opens the documentation. Example `cargo make doc-open`"
clear = true
command = "cargo"
args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--open"]
[tasks.clippy]
description = "Run cargo clippy for the host target and both UEFI cross-compilation targets."
clear = true
run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = true }]
[tasks.clippy-x64]
description = "Run cargo clippy for x86_64-unknown-uefi."
private = true
command = "cargo"
args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"]
[tasks.clippy-aarch64]
description = "Run cargo clippy for aarch64-unknown-uefi."
private = true
command = "cargo"
args = ["clippy", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"]
[tasks.clippy-std]
description = "Run cargo clippy for std."
private = true
command = "cargo"
args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"]
[tasks.fmt]
description = "Run cargo format."
clear = true
command = "cargo"
args = ["fmt", "--all"]
[tasks.fmt-check]
description = "Check cargo format without modifying files."
clear = true
command = "cargo"
args = ["fmt", "--all", "--check"]
[tasks.doc-test]
description = "Run documentation tests."
clear = true
command = "cargo"
args = ["test", "--doc"]
[tasks.clean-mdbook-deps]
description = """Removes the `target/mdbook/` directory to clean up old rlibs."""
clear = true
script_runner = "@duckscript"
script = '''
mdbook_target = set "target/mdbook"
exists = is_path_exists ${mdbook_target}
if ${exists}
echo Removing stale ${mdbook_target} directory...
rm -r ${mdbook_target}
end
'''
[tasks.build-mdbook-deps]
description = """Builds workspace libraries with the `mdbook` profile.
This is a prerequisite for `cargo make test-mdbook`."""
clear = true
env = { RUSTC_PROFILE = "mdbook" }
command = "cargo"
args = ["build", "--all-features", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )"]
dependencies = ["clean-mdbook-deps", "individual-package-targets"]
[tasks.test-mdbook]
description = """Builds the mdbook and runs all of its embedded doctests with
`mdbook test`. Uses the workspace toolchain (from `rust-toolchain.toml`) so the
doctests link against rlibs built by the same compiler, and points `mdbook test`
to the mdbook profile `target/mdbook/deps/` directory produced by `build-mdbook-deps`.
"""
clear = true
env = { RUSTC_BOOTSTRAP = "1" }
script_runner = "@duckscript"
script = '''
toolchain_file = readfile rust-toolchain.toml
channel = set "stable"
found = set false
lines = split ${toolchain_file} "\n"
for line in ${lines}
trimmed = trim ${line}
starts = starts_with ${trimmed} "channel"
# Only use the first `channel` line (the one under `[toolchain]`).
if ${starts}
if not ${found}
parts = split ${trimmed} "\""
channel = array_get ${parts} 1
found = set true
end
end
end
exec --fail-on-error mdbook build docs
exec --fail-on-error rustup run ${channel} mdbook test docs -L target/mdbook/deps
'''
dependencies = ["build-mdbook-deps"]
[tasks.serve-mdbook]
description = """Serves the mdbook at http://localhost:3000 with live reload.
`mdbook serve` rebuilds on source changes. It does not run the embedded doctests
(use `cargo make test-mdbook` for that)."""
clear = true
command = "mdbook"
args = ["serve", "docs", "--open"]
[tasks.cspell]
description = "Run cspell for spell checking." # npm install -g cspell@latest
script = "cspell --quiet --no-progress --no-summary --dot --gitignore -e \"{.git/**,.github/**,.vscode/**}\" ."
[tasks.deny]
description = "Run cargo deny."
install_crate = false
clear = true
command = "cargo"
args = ["deny", "check"]
[tasks.bench]
description = "Run cargo bench."
clear = true
command = "cargo"
args = ["bench", "@@split(CARGO_MAKE_TASK_ARGS,;)"]
[tasks.vet]
description = "Run cargo vet."
install_crate = false
clear = true
dependencies = ["generate-lockfile"]
command = "cargo"
args = ["vet", "--locked"]
ignore_errors = false
[tasks.all]
description = "Run all tasks for PR readiness."
dependencies = [
"fmt-check",
"deny",
"cspell",
"clippy",
"check-no-default-features",
"build",
"build-x64",
"build-aarch64",
"patina-test",
"coverage",
"doc-test",
"doc",
"test-ignored",
"test-mdbook",
]