cargo-make 0.37.24

Rust task runner and build tool.
Documentation
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160

[tasks.ci-flow]
description = "CI task will run cargo build and cargo test with verbose output"
category = "CI"
dependencies = [
  "pre-ci-flow",
  "print-env-flow",
  "pre-build",
  "check-format-ci-flow",
  "clippy-ci-flow",
  "build",
  "post-build",
  "test-flow",
  "examples-ci-flow",
  "bench-ci-flow",
  "outdated-ci-flow",
  "ci-coverage-flow",
  "post-ci-flow",
]

[tasks.workspace-ci-flow]
description = "CI task will run CI flow for each member and merge coverage reports"
category = "CI"
workspace = false
dependencies = [
  "pre-workspace-ci-flow",
  "workspace-members-ci",
  "workspace-coverage-pack",
  "post-workspace-ci-flow",
]

[tasks.dev-test-flow]
description = "Development testing flow will first format the code, and than run cargo build and test"
category = "Development"
dependencies = [
  "format-flow",
  "format-toml-conditioned-flow",
  "pre-build",
  "build",
  "post-build",
  "test-flow",
]

[tasks.dev-watch-flow]
description = "Alias for default flow"
category = "Development"
alias = "test-flow"

[tasks.pre-publish-delete-lock]
description = "Deletes lock file before publishing"
category = "Publish"
condition = { env_true = ["CARGO_MAKE_CARGO_PUBLISH_DELETE_LOCK_FILE"] }
run_task = "delete-lock"

[tasks.pre-publish-clean-flow]
description = "Clears old artifactes before publishing"
category = "Publish"
dependencies = ["pre-clean", "clean", "post-clean"]

[tasks.pre-publish-conditioned-clean-flow]
description = "Clears old artifactes before publishing"
category = "Publish"
condition = { env_not_set = ["CARGO_MAKE_SKIP_PREPUBLISH_CLEAN"] }
run_task = "pre-publish-clean-flow"

[tasks.publish-flow]
description = "Publish flow - First clean the target directory of any old leftovers, package and publish"
category = "Publish"
dependencies = [
  "wait",
  "pre-publish-conditioned-clean-flow",
  "pre-publish-delete-lock",
  "pre-publish",
  "publish",
  "post-publish",
]

[tasks.build-flow]
# This is the full sanity testing flow which includes:
# cleanup of old build
# generating docs and moving them to the docs folder
# running cargo build and test
# running cargo plugins such as security and dependency validations
description = "Full sanity testing flow."
category = "Build"
dependencies = [
  "init-build-flow",
  "pre-clean",
  "clean-apidocs",
  "clean",
  "post-clean",
  "format-flow",
  "pre-build",
  "build",
  "post-build",
  "test-flow",
  "examples-ci-flow",
  "bench-ci-flow",
  "pre-verify-project",
  "verify-project",
  "post-verify-project",
  "audit-flow",
  "outdated-flow",
  "docs-flow",
  "end-build-flow",
]

[tasks.init-build-flow]
category = "Build"

[tasks.pre-clean]
category = "Cleanup"

[tasks.clean-apidocs]
description = "Delete API docs."
category = "Documentation"
workspace = false
run_task = [
  { name = "workspace-clean-apidocs", condition = { env_set = [
    "CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER",
  ] } },
  { name = "crate-clean-apidocs" },
]

[tasks.crate-clean-apidocs]
category = "Documentation"
private = true
env = { CARGO_MAKE_DOCS_ROOT_FOLDER = "${CARGO_MAKE_WORKING_DIRECTORY}" }
run_task = "do-clean-apidocs"

[tasks.workspace-clean-apidocs]
category = "Documentation"
private = true
env = { CARGO_MAKE_DOCS_ROOT_FOLDER = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}", CARGO_MAKE_DOCS_SUB_FOLDER = "${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}" }
run_task = "do-clean-apidocs"

[tasks.do-clean-apidocs]
category = "Documentation"
private = true
condition = { env_set = ["CARGO_MAKE_DOCS_ROOT_FOLDER"] }
script = '''
#!@duckscript
DOCS_DIRECTORY = set ${CARGO_MAKE_DOCS_ROOT_FOLDER}/docs/api/${CARGO_MAKE_DOCS_SUB_FOLDER}

# Removing Documentation Directory: ${DOCS_DIRECTORY}
rm -r ${DOCS_DIRECTORY}
'''

[tasks.clean]
description = "Runs the cargo clean command."
category = "Cleanup"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["clean"]

[tasks.post-clean]
category = "Cleanup"

[tasks.delete-lock]
description = "Deletes the Cargo.lock file."
category = "Cleanup"
run_task = [
  { name = "workspace-delete-lock", condition = { env_set = [
    "CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER",
  ] } },
  { name = "crate-delete-lock" },
]

[tasks.crate-delete-lock]
description = "Deletes the Cargo.lock file."
category = "Cleanup"
private = true
script = '''
#!@duckscript
rm ./Cargo.lock
'''

[tasks.workspace-delete-lock]
description = "Deletes the Cargo.lock file."
category = "Cleanup"
condition = { env_set = ["CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY"] }
private = true
script = '''
#!@duckscript
rm ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/Cargo.lock
'''

[tasks.upgrade-dependencies]
description = "Rebuilds the crate with most updated dependencies."
category = "Development"
dependencies = ["delete-lock", "dev-test-flow"]

[tasks.install-rustfmt]
description = "Installs cargo rustfmt plugin."
category = "Development"
env.CFG_RELEASE = { value = "${CARGO_MAKE_RUST_VERSION}", condition = { env_not_set = [
  "CFG_RELEASE",
] } }
env.CFG_RELEASE_CHANNEL = { value = "${CARGO_MAKE_RUST_CHANNEL}", condition = { env_not_set = [
  "CFG_RELEASE_CHANNEL",
] } }
install_crate = { crate_name = "rustfmt-nightly", rustup_component_name = "rustfmt", binary = "rustfmt", test_arg = "--help" }

[tasks.pre-format]
category = "Development"

[tasks.format]
description = "Runs the cargo rustfmt plugin."
category = "Development"
dependencies = ["install-rustfmt"]
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["fmt"]

[tasks.post-format]
category = "Development"

[tasks.pre-check-format]
category = "Test"

[tasks.check-format]
description = "Runs cargo fmt to check appropriate code format."
category = "Test"
dependencies = ["install-rustfmt"]
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["fmt", "--", "--check"]

[tasks.post-check-format]
category = "Test"

[tasks.check-format-flow]
description = "Runs cargo fmt check flow."
category = "Test"
dependencies = ["pre-check-format", "check-format", "post-check-format"]

[tasks.check-format-ci-flow]
description = "Runs cargo fmt --check if conditions are met."
category = "Test"
condition = { env_set = [
  "CARGO_MAKE_RUN_CHECK_FORMAT",
], channels = [
  "nightly",
], platforms = [
  "linux",
] }
run_task = "check-format-flow"

[tasks.format-flow]
description = "Runs the cargo rustfmt plugin as part of a flow."
category = "Development"
dependencies = ["pre-format", "format", "post-format"]

[tasks.pre-docs]
category = "Documentation"

[tasks.docs]
description = "Generate rust documentation."
category = "Documentation"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["doc", "--no-deps"]

[tasks.post-docs]
category = "Documentation"

[tasks.docs-flow]
description = "Generate rust documentation."
category = "Documentation"
dependencies = [
  "pre-docs",
  "docs",
  "post-docs",
  "readme-set-crate-version-conditioned",
  "readme-include-files-conditioned",
  "copy-apidocs",
]

[tasks.pre-workspace-docs]
category = "Documentation"

[tasks.workspace-docs]
description = "Generate workspace level rust documentation."
category = "Documentation"

[tasks.post-workspace-docs]
category = "Documentation"

[tasks.workspace-docs-flow]
description = "Generate workspace level rust documentation."
category = "Documentation"
workspace = false
dependencies = ["pre-workspace-docs", "workspace-docs", "post-workspace-docs"]

[tasks.readme-file-set-env]
description = "Sets the CARGO_MAKE_DOCS_README_FILE environment variable."
category = "Documentation"
private = true
condition = { env_not_set = ["CARGO_MAKE_DOCS_README_FILE"] }
env = { CARGO_MAKE_DOCS_README_FILE = "${CARGO_MAKE_WORKING_DIRECTORY}/README.md" }

[tasks.readme-set-crate-version]
description = "Modifies the current README.md file with the current crate version."
category = "Documentation"
env = { "CARGO_MAKE_DOCS_README_SET_CRATE_VERSION" = true }
run_task = "readme-set-crate-version-conditioned"

[tasks.readme-set-crate-version-conditioned]
description = "Modifies the current README.md file with the current crate version."
category = "Documentation"
private = true
dependencies = ["readme-file-set-env"]
condition = { env_true = ["CARGO_MAKE_DOCS_README_SET_CRATE_VERSION"] }
script = '''
#!@duckscript
readme_file_name = set ${CARGO_MAKE_DOCS_README_FILE}

if is_file ${readme_file_name}
    readme_text = readfile ${readme_file_name}
    prefix = set "dependencies]\n"
    index = indexof ${readme_text} ${prefix}

    if is_defined index
        prefix_length = strlen ${prefix}
        end = calc ${index} + ${prefix_length}
        readme_start = substring ${readme_text} 0 ${end}
        readme_end = substring ${readme_text} ${end}

        prefix = set "${CARGO_MAKE_PROJECT_NAME} = \""
        found = starts_with ${readme_end} ${prefix}
        if ${found}
            prefix_length = strlen ${prefix}
            readme_start = set "${readme_start}${prefix}"
            readme_end = substring ${readme_end} ${prefix_length}

            index = indexof ${readme_end} \"
            if is_defined index
                readme_end = substring ${readme_end} ${index}
                readme_text = set "${readme_start}^${CARGO_MAKE_PROJECT_VERSION}${readme_end}"

                writefile ${readme_file_name} ${readme_text}
            else
                echo "Dependency end not found."
            end
        else
            echo "${CARGO_MAKE_PROJECT_NAME} dependency prefix not found."
        end
    else
        echo "Dependencies prefix not found."
    end
else
    echo "README file: ${readme_file_name} not found."
end
'''

[tasks.readme-include-files]
description = "Modifies the current README.md by including external files."
category = "Documentation"
env = { "CARGO_MAKE_DOCS_README_INCLUDE_FILES" = true }
run_task = "readme-include-files-conditioned"

[tasks.readme-include-files-conditioned]
description = "Modifies the current README.md by including external files."
category = "Documentation"
private = true
condition = { env_true = [
  "CARGO_MAKE_DOCS_README_INCLUDE_FILES",
], files_exist = [
  "${CARGO_MAKE_DOCS_README_FILE}",
] }
dependencies = ["readme-file-set-env"]
install_crate = { crate_name = "md-inc", binary = "md-inc", test_arg = "--help" }
env = { CARGO_MAKE_DOCS_INCLUDE_FILES_MARKDOWN_FILE = "${CARGO_MAKE_DOCS_README_FILE}" }
run_task = "markdown-include-files"

[tasks.markdown-include-files]
description = "Modifies the markdown file defined by the CARGO_MAKE_DOCS_INCLUDE_FILES_MARKDOWN_FILE environment variable, by including external files."
category = "Documentation"
condition = { files_exist = ["${CARGO_MAKE_DOCS_INCLUDE_FILES_MARKDOWN_FILE}"] }
install_crate = { crate_name = "md-inc", binary = "md-inc", test_arg = "--help" }
command = "md-inc"
args = ["${CARGO_MAKE_DOCS_INCLUDE_FILES_MARKDOWN_FILE}"]

[tasks.pre-build]
category = "Build"

[tasks.build]
description = "Runs the rust compiler."
category = "Build"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = [
  "build",
  "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)",
  "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )",
]

[tasks.build-release]
description = "Runs release build."
category = "Build"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["build", "--release", "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )"]

[tasks.post-build]
category = "Build"

[tasks.pre-test]
category = "Test"

[tasks.test]
description = "Runs all available tests."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = [
  "test",
  "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)",
  "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )",
]

[tasks.test-thread-safe]
description = "Runs all available tests without limiting test threads."
category = "Test"
env = { RUST_TEST_THREADS = { unset = true } }
run_task = "test"

[tasks.test-single-threaded]
description = "Runs all ignored tests with a single test thread."
category = "Test"
install_crate = false
env = { RUST_TEST_THREADS = 1 }
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = [
  "test",
  "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)",
  "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )",
  "--",
  "--ignored",
]

[tasks.test-custom]
description = "Runs custom test command."
category = "Test"

[tasks.test-multi-phases-cleanup]
description = "Cleanup after multi phase tests flow."
category = "Test"
private = true
env = { RUST_TEST_THREADS = { unset = true } }

[tasks.test-multi-phases-flow]
description = "Runs single/multi and custom test tasks."
category = "Test"
run_task = [
  { name = [
    "test-thread-safe",
    "test-single-threaded",
    "test-custom",
    "test-multi-phases-cleanup",
  ], condition = { env_true = [
    "CARGO_MAKE_TEST_USE_MULTI_TEST_PHASES",
  ] } },
  { name = "test" },
]

[tasks.test-flow]
description = "Runs pre/post hooks and cargo test."
category = "Test"
dependencies = ["pre-test", "test-multi-phases-flow", "post-test"]

[tasks.test-with-args]
description = "Runs cargo test with command line arguments."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["test", "${@}"]

[tasks.post-test]
category = "Test"

[tasks.pre-bench]
category = "Test"

[tasks.bench]
description = "Runs all available bench files."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["bench", "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )"]

[tasks.post-bench]
category = "Test"

[tasks.bench-flow]
description = "Runs a bench flow."
category = "Test"
dependencies = ["pre-bench", "bench", "post-bench"]

[tasks.bench-conditioned-flow]
description = "Runs the bench flow if conditions are met."
category = "Test"
condition = { env_set = ["CARGO_MAKE_RUN_BENCH"], channels = ["nightly"] }
run_task = "bench-flow"

[tasks.bench-compile]
description = "Compiles all available bench files."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["build", "--benches", "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )"]

[tasks.bench-conditioned-compile]
description = "Compiles all available bench files if conditions are met."
category = "Test"
condition = { env_set = ["CARGO_MAKE_BUILD_BENCH"], channels = ["nightly"] }
run_task = "bench-compile"

[tasks.bench-ci-flow]
description = "Runs/Compiles the benches if conditions are met."
category = "CI"
dependencies = ["bench-conditioned-compile", "bench-conditioned-flow"]

[tasks.pre-check]
category = "Test"

[tasks.check]
description = "Runs cargo check."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["check"]

[tasks.post-check]
category = "Test"

[tasks.check-flow]
description = "Runs cargo check flow."
category = "Test"
dependencies = ["pre-check", "check", "post-check"]

[tasks.check-tests]
description = "Runs cargo check for project tests."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["check", "--tests"]

[tasks.check-examples]
description = "Runs cargo check for project examples."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["check", "--examples"]

[tasks.examples-compile]
description = "Runs cargo build for project examples."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["build", "--examples"]

[tasks.examples-conditioned-compile]
description = "Runs cargo build for project examples if conditions are met."
category = "Test"
condition = { env_set = ["CARGO_MAKE_BUILD_EXAMPLES"] }
run_task = "examples-compile"

[tasks.examples-ci-flow]
description = "Compiles the examples if conditions are met."
category = "CI"
dependencies = ["examples-conditioned-compile"]

[tasks.pre-verify-project]
category = "CI"

[tasks.verify-project]
description = "Runs verify-project cargo plugin."
category = "CI"
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["verify-project"]

[tasks.post-verify-project]
category = "CI"

[tasks.pre-audit]
category = "CI"

[tasks.audit]
description = "Runs audit cargo plugin."
category = "CI"
condition = { env_true = [
  "CARGO_MAKE_CRATE_HAS_DEPENDENCIES",
  "CARGO_MAKE_CRATE_LOCK_FILE_EXISTS",
] }
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["audit"]

[tasks.post-audit]
category = "CI"

[tasks.audit-flow-no-condition]
description = "Runs audit flow."
category = "CI"
private = true
dependencies = ["pre-audit", "audit", "post-audit"]

[tasks.audit-flow]
description = "Runs audit flow."
category = "CI"
condition = { env_not_set = ["CARGO_MAKE_SKIP_SLOW_SECONDARY_FLOWS"] }
run_task = "audit-flow-no-condition"

[tasks.pre-outdated]
category = "CI"

[tasks.outdated]
description = "Runs cargo-outdated cargo plugin."
category = "CI"
condition = { env_true = ["CARGO_MAKE_CRATE_HAS_DEPENDENCIES"] }
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["outdated", "--root-deps-only", "--exit-code", "1"]

[tasks.post-outdated]
category = "CI"

[tasks.outdated-flow-no-condition]
description = "Runs outdated cargo flow."
category = "CI"
private = true
dependencies = ["pre-outdated", "outdated", "post-outdated"]

[tasks.outdated-flow]
description = "Runs outdated cargo flow."
category = "CI"
condition = { env_not_set = ["CARGO_MAKE_SKIP_SLOW_SECONDARY_FLOWS"] }
run_task = "outdated-flow-no-condition"

[tasks.outdated-ci-flow]
description = "Runs outdated cargo conditioned CI flow."
category = "CI"
condition = { env_set = [
  "CARGO_MAKE_CHECK_OUTDATED",
], env_true = [
  "CARGO_MAKE_CRATE_HAS_DEPENDENCIES",
], env_false = [
  "CARGO_MAKE_PR",
], env = { "CARGO_MAKE_CI_BRANCH_NAME" = "master" }, channels = [
  "nightly",
], platforms = [
  "linux",
] }
run_task = "outdated-flow"

[tasks.unused-dependencies-flow]
description = "Checks for unused dependencies."
category = "CI"
condition = { env_true = ["CARGO_MAKE_CRATE_HAS_DEPENDENCIES"] }
dependencies = [
  "pre-unused-dependencies",
  "unused-dependencies",
  "post-unused-dependencies",
]

[tasks.pre-unused-dependencies]
category = "CI"

[tasks.unused-dependencies]
description = "Checks for unused dependencies."
category = "CI"
condition = { channels = [
  "nightly",
], env_true = [
  "CARGO_MAKE_CRATE_HAS_DEPENDENCIES",
] }
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["udeps"]

[tasks.post-unused-dependencies]
category = "CI"

[tasks.install-clippy-any]
description = "Installs the latest clippy code linter via cargo install via rustup or directly from github."
category = "Test"
condition = { channels = ["nightly"] }
ignore_errors = true
install_crate = { crate_name = "clippy", rustup_component_name = "clippy", binary = "cargo-clippy", test_arg = "--help" }
install_crate_args = [
  "--git",
  "https://github.com/rust-lang/rust-clippy/",
  "clippy",
]
args = ["clippy", "--help"]

[tasks.install-clippy-rustup]
description = "Installs the clippy code linter via rustup."
category = "Test"
ignore_errors = true
install_crate = { rustup_component_name = "clippy", binary = "cargo-clippy", test_arg = "--help" }

[tasks.install-clippy]
description = "Installs the clippy code linter."
category = "Test"
run_task = [{ name = ["install-clippy-any", "install-clippy-rustup"] }]

[tasks.pre-clippy]
category = "Test"

[tasks.clippy]
description = "Runs clippy code linter."
category = "Test"
dependencies = ["install-clippy"]
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["clippy", "@@split(CARGO_MAKE_CLIPPY_ARGS, )"]

[tasks.post-clippy]
category = "Test"

[tasks.clippy-allow-fail]
extend = "clippy"
ignore_errors = true

[tasks.clippy-router]
description = "Selects clippy task based on current environment."
category = "Test"
run_task = [
  { name = "clippy-allow-fail", condition = { env_true = [
    "CARGO_MAKE_CLIPPY_ALLOW_FAIL",
  ] } },
  { name = "clippy" },
]

[tasks.clippy-flow]
description = "Runs clippy flow."
category = "Test"
dependencies = ["pre-clippy", "clippy-router", "post-clippy"]

[tasks.clippy-ci-flow]
description = "Runs clippy code linter if conditions are met."
category = "CI"
condition = { env_set = [
  "CARGO_MAKE_RUN_CLIPPY",
], channels = [
  "nightly",
], platforms = [
  "linux",
] }
run_task = "clippy-flow"

[tasks.copy-apidocs]
description = "Copies the generated documentation to the docs/api directory."
category = "Documentation"
workspace = false
run_task = [
  { name = "workspace-copy-apidocs", condition = { env_set = [
    "CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER",
  ] } },
  { name = "crate-copy-apidocs" },
]

[tasks.crate-copy-apidocs]
description = "Copies the generated documentation to the docs/api directory."
category = "Documentation"
private = true
env = { CARGO_MAKE_DOCS_ROOT_FOLDER = "${CARGO_MAKE_WORKING_DIRECTORY}" }
run_task = "do-copy-apidocs"

[tasks.workspace-copy-apidocs]
description = "Copies the generated documentation to the docs/api directory."
category = "Documentation"
private = true
env = { CARGO_MAKE_DOCS_ROOT_FOLDER = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}", CARGO_MAKE_DOCS_SUB_FOLDER = "${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}" }
run_task = "do-copy-apidocs"

[tasks.do-copy-apidocs]
description = "Copies the generated documentation to the docs/api directory."
category = "Documentation"
private = true
script_runner = "@duckscript"
script = '''
if is_empty "${CARGO_MAKE_DOCS_SUB_FOLDER}"
    src_dir= set ${CARGO_MAKE_DOCS_ROOT_FOLDER}
else
    src_dir= set ${CARGO_MAKE_DOCS_ROOT_FOLDER}/${CARGO_MAKE_DOCS_SUB_FOLDER}
end

if is_dir ${src_dir}/target/${CARGO_MAKE_CRATE_TARGET_TRIPLE}/doc
    src_dir= set ${src_dir}/target/${CARGO_MAKE_CRATE_TARGET_TRIPLE}/doc
else
    src_dir= set ${src_dir}/target/doc
end

if is_empty "${CARGO_MAKE_DOCS_SUB_FOLDER}"
    dest_dir= set ${CARGO_MAKE_DOCS_ROOT_FOLDER}/docs/api
else
    dest_dir= set ${CARGO_MAKE_DOCS_ROOT_FOLDER}/docs/api/${CARGO_MAKE_DOCS_SUB_FOLDER}/
end

echo Source Directory: ${src_dir}
echo Target Directory: ${dest_dir}

rm -r ${dest_dir}
mkdir ${dest_dir}

handle = glob_array ${src_dir}/*
for path in ${handle}
    echo Moving documentation path: ${path}
    if is_directory ${path}
        mv ${path}/ ${dest_dir}
    else
        mv ${path} ${dest_dir}
    end
end

echo All docs copied
'''

[tasks.end-build-flow]
category = "Build"

[tasks.pre-package]
category = "Publish"

[tasks.package]
description = "Runs the cargo package command."
category = "Publish"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["package"]

[tasks.post-package]
category = "Publish"

[tasks.pre-publish]
category = "Publish"

[tasks.publish]
description = "Runs the cargo publish command."
category = "Publish"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = ["publish", "@@split(CARGO_MAKE_CARGO_PUBLISH_FLAGS, )"]

[tasks.post-publish]
category = "Publish"

[tasks.pre-ci-flow]
category = "CI"

[tasks.post-ci-flow]
category = "CI"

[tasks.do-on-members]
description = "Runs the requested task for every workspace member."
category = "Tools"
env = { CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY = "${CARGO_MAKE_WORKING_DIRECTORY}/target" }
condition = { env_set = ["CARGO_MAKE_MEMBER_TASK"] }
script = '''
#prevent codecov publish in member builds
export CARGO_MAKE_SKIP_CODECOV="true"

#output coverage data goes into workspace level
export CARGO_MAKE_COVERAGE_REPORT_DIRECTORY="${CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY}/coverage"

cargo make --loglevel=${CARGO_MAKE_LOG_LEVEL} --profile="${CARGO_MAKE_PROFILE}" "${CARGO_MAKE_MEMBER_TASK}"

unset CARGO_MAKE_COVERAGE_REPORT_DIRECTORY
unset CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY
unset CARGO_MAKE_SKIP_CODECOV
'''

[tasks.do-on-members.windows]
clear = true
script = '''
cargo make --loglevel=%CARGO_MAKE_LOG_LEVEL% --profile="%CARGO_MAKE_PROFILE%" %CARGO_MAKE_MEMBER_TASK%
if %errorlevel% neq 0 exit /b %errorlevel%
'''

[tasks.pre-workspace-ci-flow]
category = "CI"

[tasks.post-workspace-ci-flow]
category = "CI"

[tasks.workspace-members-ci]
description = "Runs the ci-flow for every workspace member."
category = "CI"
env = { "CARGO_MAKE_MEMBER_TASK" = "${CARGO_MAKE_CORE_TASK_NAMESPACE_PREFIX}ci-flow" }
run_task = "do-on-members"

[tasks.upload-artifacts]
description = "Uploads the binary artifact from the cargo package/publish output (hook only)."
category = "Publish"

[tasks.build-publish-flow]
description = "Runs full sanity, generates github release and publishes the crate."
category = "Publish"
workspace = false
condition = { env_set = [
  "COMMIT_MSG",
  "GITHUB_API_TOKEN",
  "GITHUB_REPO_NAME",
], env = { "CARGO_MAKE_GIT_BRANCH" = "master" } }
env = { "CARGO_MAKE_SKIP_PREPUBLISH_CLEAN" = true, "CARGO_MAKE_GIT_PUSH_ARGS" = "--no-verify" }
run_task = [
  { name = "workspace-build-publish-flow", condition = { env_true = [
    "CARGO_MAKE_CRATE_IS_WORKSPACE",
  ] } },
  { name = "crate-build-publish-flow" },
]

[tasks.crate-build-publish-flow]
private = true
dependencies = [
  "delete-lock",
  "build-flow",
  "build-file-increment-flow",
  "git-add",
  "git-status",
  "git-commit-message",
  "git-push",
  "git-delete-merged-branches",
  "github-publish-custom-name",
  "publish-flow",
  "upload-artifacts",
  "git-pull",
]

[tasks.workspace-build-publish-flow]
private = true
dependencies = [
  "delete-lock",
  "workspace-build-flow",
  "build-file-increment-flow",
  "git-add",
  "git-status",
  "git-commit-message",
  "git-push",
  "git-delete-merged-branches",
  "github-publish-custom-name",
  "workspace-publish-flow",
  "git-pull",
]

[tasks.workspace-build-flow]
description = "Full sanity testing flow."
category = "Build"
workspace = false
dependencies = ["workspace-member-build-flow", "workspace-docs-flow"]

[tasks.workspace-member-build-flow]
category = "Build"
private = true
env = { "CARGO_MAKE_MEMBER_TASK" = "${CARGO_MAKE_CORE_TASK_NAMESPACE_PREFIX}build-flow" }
run_task = "do-on-members"

[tasks.workspace-publish-flow]
description = "Publish flow - First clean the target directory of any old leftovers, package and publish"
category = "Publish"
workspace = false
env = { "CARGO_MAKE_MEMBER_TASK" = "${CARGO_MAKE_CORE_TASK_NAMESPACE_PREFIX}publish-flow", "CARGO_MAKE_WAIT_MILLISECONDS" = 20000 }
run_task = "do-on-members"

[tasks.install-rust-src]
description = "Installs rust-src rustup component."
category = "Tools"
install_crate = { rustup_component_name = "rust-src" }

[tasks.install-rls]
description = "Installs rust Language server rustup component."
category = "Tools"
install_crate = { rustup_component_name = "rls-preview", binary = "rls", test_arg = "--help" }

[tasks.zip-release-ci-flow]
description = "Compiles the binary in release mode and zips it up"
category = "CI"
condition = { env_set = [
  "CARGO_MAKE_RELEASE_FLOW_TARGET",
], env_true = [
  "CARGO_MAKE_CI",
] }
dependencies = [
  "print-env-flow",
  "clean",
  "setup-release-build-env",
  "build-release-for-binary-upload",
  "zip-release-binary-for-target",
]

[tasks.setup-release-build-env]
description = "Sets up any non-rust dependencies in the build environment"
category = "CI"
private = true
dependencies = [
  "setup-release-build-env-vars",
  "setup-release-build-env-print",
  "install-zip",
  "setup-musl",
]

[tasks.setup-release-build-env-print]
category = "CI"
private = true
script = '''
#!@duckscript
echo "*************************************"
echo "Release Binary Build Environment:"
echo "    Target: ${CARGO_MAKE_RELEASE_FLOW_TARGET}"
echo "    Use Cross: ${CARGO_MAKE_BINARY_RELEASE_ENV_USE_CROSS}"
echo "    Setup MUSL: ${CARGO_MAKE_BINARY_RELEASE_ENV_INSTALL_MUSL}"
echo "    ARM Linux: ${CARGO_MAKE_BINARY_RELEASE_ENV_ARM_LINUX}"
echo "*************************************"
'''

[tasks.setup-release-build-env-vars]
description = "Sets up environment variables based on target."
category = "CI"
private = true
env.CARGO_MAKE_BINARY_RELEASE_ENV_ARM_LINUX = { source = "${CARGO_MAKE_RELEASE_FLOW_TARGET}", default_value = "false", mapping = { "arm-unknown-linux-gnueabihf" = "true" } }
env.CARGO_MAKE_BINARY_RELEASE_ENV_USE_CROSS = "${CARGO_MAKE_BINARY_RELEASE_ENV_ARM_LINUX}"
env.CARGO_MAKE_BINARY_RELEASE_ENV_INSTALL_MUSL = true

[tasks.install-zip]
description = "Installs zip executable"
category = "Tools"
condition = { platforms = ["linux"] }
dependencies = ["setup-sudo-env"]
install_script = '''
which zip || (${CARGO_MAKE_SUDO_COMMAND} apt-get update && ${CARGO_MAKE_SUDO_COMMAND} apt-get install -y zip)
'''

[tasks.setup-musl]
description = "Sets up a musl build environment"
category = "CI"
private = true
condition = { env_set = [
  "CARGO_MAKE_RELEASE_FLOW_TARGET",
  "CARGO_MAKE_OPENSSL_VERSION",
  "CARGO_MAKE_OPENSSL_DOWNLOAD_URL",
], env_true = [
  "CARGO_MAKE_CI",
  "CARGO_MAKE_BINARY_RELEASE_ENV_INSTALL_MUSL",
], platforms = [
  "linux",
] }
env.OPENSSL_DIR = "${HOME}/openssl-musl"
env.OPENSSL_PLATFORM = { source = "${CARGO_MAKE_BINARY_RELEASE_ENV_ARM_LINUX}", default_value = "x86_64", mapping = { "true" = "armv4" } }
script = '''
rustup target add "${CARGO_MAKE_RELEASE_FLOW_TARGET}"
curl --location ${CARGO_MAKE_OPENSSL_DOWNLOAD_URL} | tar xzf -
cd openssl-${CARGO_MAKE_OPENSSL_VERSION}
CC=musl-gcc ./Configure --prefix="${OPENSSL_DIR}" no-dso no-ssl2 no-ssl3 linux-${OPENSSL_PLATFORM} -fPIC
make -j"$(nproc)"
make install
'''

[tasks.build-release-for-binary-upload]
run_task = [
  { name = "cross-build-release-for-target", condition = { env_true = [
    "CARGO_MAKE_BINARY_RELEASE_ENV_USE_CROSS",
  ] } },
  { name = "build-release-for-target" },
]

[tasks.build-release-for-target-base]
description = "Makes a release build for a given target"
category = "Build"
private = true
condition = { env_set = [
  "CARGO_MAKE_RELEASE_FLOW_TARGET",
], env_true = [
  "CARGO_MAKE_CI",
] }
args = [
  "build",
  "--release",
  "--all-features",
  "--target",
  "${CARGO_MAKE_RELEASE_FLOW_TARGET}",
]

[tasks.cross-build-release-for-target]
extend = "build-release-for-target-base"
install_crate = { crate_name = "cross", binary = "cross", test_arg = [
  "--help",
] }
command = "cross"

[tasks.build-release-for-target]
extend = "build-release-for-target-base"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"

[tasks.zip-release-binary-for-target]
description = "Zips up the release binary, README, and license(s)"
category = "Publish"
condition = { env_set = [
  "CARGO_MAKE_RELEASE_FLOW_TARGET",
  "CARGO_MAKE_PROJECT_NAME",
  "CARGO_MAKE_PROJECT_VERSION",
  "CARGO_MAKE_BINARY_EXECUTABLE_NAME",
], env_true = [
  "CARGO_MAKE_CI",
] }
env.OUTPUT_NAME = "${CARGO_MAKE_PROJECT_NAME}-v${CARGO_MAKE_PROJECT_VERSION}-${CARGO_MAKE_RELEASE_FLOW_TARGET}"
env.TARGET_RELEASE_DIRECTORY = "target/${CARGO_MAKE_RELEASE_FLOW_TARGET}/release"
script = '''
#!@duckscript
executable_file = set ${CARGO_MAKE_BINARY_EXECUTABLE_NAME}
additional_executable_file = set "${CARGO_MAKE_ADDITIONAL_BINARY_EXECUTABLE_NAME}"
additional_executable_file_len = length ${additional_executable_file}
additional_executable_file_defined = set true
if eq ${additional_executable_file_len} 0
    additional_executable_file_defined = set false
end
if is_windows
    executable_file = set "${executable_file}.exe"
    additional_executable_file = set "${additional_executable_file}.exe"
end

mkdir ${OUTPUT_NAME}

cp ${TARGET_RELEASE_DIRECTORY}/${executable_file} ${OUTPUT_NAME}/${executable_file}
if ${additional_executable_file_defined}
    if is_path_exists ${TARGET_RELEASE_DIRECTORY}/${additional_executable_file}
        cp ${TARGET_RELEASE_DIRECTORY}/${additional_executable_file} ${OUTPUT_NAME}/${additional_executable_file}
    end
end
cp ./README.md ${OUTPUT_NAME}/README.md
glob_cp ./LICENSE* ${OUTPUT_NAME}/

ls -l ${OUTPUT_NAME}/

if is_windows
    exec --fail-on-error powershell Compress-Archive -Path ${OUTPUT_NAME}/* -DestinationPath ${OUTPUT_NAME}.zip
else
    exec --fail-on-error zip -r ${OUTPUT_NAME}.zip ${OUTPUT_NAME}
end
'''