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
|
# https://taskfile.dev
#Called by the vnbuild system to produce builds for my website
#https://www.vaughnnugent.com/resources/software
#This taskfile performs the build operations for a module, it handles
#git code updates, msbuild on solutions, and sleet NuGet feed pushes.
#this file must be in the same directory as the solution file
#NOTES: Since CI project is pulled from the module root, MODULE_DIR is used instead of PROJECT_DIR
version: '3'
vars:
_RMDIR: '{{ if eq OS "windows" }}powershell rm -Recurse -Force{{else}}rm -rf{{end}}'
_MKDIR: '{{ if eq OS "windows" }}powershell mkdir -Force{{else}}mkdir -p{{end}}'
BINARY_DIR: '{{ .BINARY_DIR | default "bin" }}'
CMAKE_BUILD_DIR: 'build/{{ OS }}'
TEST_EXE_NAME: 'nctest'
CI_BUILD_CONFIG: '{{ .CI_BUILD_CONFIG | default "Release" }}'
MBEDTLS_VERSION: '3.6.2'
MBEDTLS_ARCHIVE_SHA: ''
tasks:
default:
desc: "Build the library for your system"
cmds:
- task: cmake-build
vars: { CMAKE_TEST_STATUS: 'OFF', BUILD_CONFIG: 'Release' }
build-debug:
desc: "Build libraries and test executable in debug mode"
summary: |
Runs the CMake configure and compile steps to build the library
and test executable in debug mode.
cmds:
- task: cmake-build
vars: { CMAKE_TEST_STATUS: 'ON', BUILD_CONFIG: 'Debug' }
#available to users and vnbuild runner
test:
desc: "Builds a local copy of the library in a debug configuration, then runs the test executable"
cmds:
- task: build-debug
- task: cmake-test
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
install:
desc: "Uses cmake to install the library on your system"
cmds:
- cmd: echo "Installing noscrypt globally"
silent: true
- task: cmake-install
#Test executable and library must be built for tests to run
memcheck:
desc: 'Runs Valgrind memcheck in debug mode against the nctest executable (Linux only)'
summary: |
Runs Valgrind memcheck in debug mode against the nctest executable.
This task is only available on Linux platforms with Valgrind and the
Memcheck tool is installed. You must build the test executable in debug
mode before running this task.
platforms:
- linux
preconditions:
- which valgrind
cmds:
- cmd: echo "Running valgrind memory check on test executable"
silent: true
- cmd:
valgrind
--tool=memcheck
--leak-check=full
--show-leak-kinds=all
--track-origins=yes
{{ .CMAKE_BUILD_DIR }}/{{ .TEST_EXE_NAME }}
clean:
desc: "Cleans the build and artifact directories"
ignore_error: true
cmds:
- for: [ bin/, build/ ]
cmd: '{{ ._RMDIR }} "{{ .ITEM }}"'
#################################
#
# INTERNAL TASKS
#
#################################
cmake-configue:
internal: true
requires: { CMAKE_BUILD_DIR, BUILD_CONFIG, CMAKE_TEST_STATUS }
cmds:
- cmd: cmake
-S .
-B{{ .CMAKE_BUILD_DIR }}
-DCMAKE_BUILD_TYPE={{ .BUILD_CONFIG }}
-DNC_BUILD_TESTS={{ .CMAKE_TEST_STATUS }}
{{ .CLI_ARGS }}
{{ .CMAKE_CONFIG_ARGS }}
#perfoms CMake compile step
cmake-compile:
internal: true
requires: { CMAKE_BUILD_DIR, BUILD_CONFIG }
cmds:
- cmd: cmake
--build {{ .CMAKE_BUILD_DIR }}
--config {{ .BUILD_CONFIG }}
#runs the configure and compile cmake steps
cmake-build:
internal: true
requires: { CMAKE_BUILD_DIR, BUILD_CONFIG, CMAKE_TEST_STATUS }
cmds:
- task: cmake-configue
vars:
CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}'
BUILD_CONFIG: '{{ .BUILD_CONFIG }}'
CMAKE_TEST_STATUS: '{{ .CMAKE_TEST_STATUS }}'
CMAKE_CONFIG_ARGS: '{{ .CMAKE_CONFIG_ARGS }}'
- task: cmake-compile
vars:
CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}'
BUILD_CONFIG: '{{ .BUILD_CONFIG }}'
#runs the cmake install step
cmake-install:
internal: true
requires: { CMAKE_BUILD_DIR }
cmds:
- cmd: cmake --install {{ .CMAKE_BUILD_DIR }} {{ .CLI_ARGS }}
cmake-test:
internal: true
requires: { CMAKE_BUILD_DIR }
cmds:
- cmd: cd {{ .CMAKE_BUILD_DIR }} && ctest -C Debug --verbose --output-on-failure
mbedtls-download:
internal: true
requires: { CMAKE_BUILD_DIR, MBEDTLS_VERSION }
vars:
MBEDTLS_DOWNLOAD_URL: 'https://github.com/Mbed-TLS/mbedtls/releases/download/mbedtls-{{ .MBEDTLS_VERSION }}/mbedtls-{{ .MBEDTLS_VERSION }}.tar.bz2'
MBEDTLS_DOWNLOAD_DIR: '{{ .CMAKE_BUILD_DIR }}/_deps'
MBEDTLS_SRC_DIR: '{{ .MBEDTLS_DOWNLOAD_DIR }}/mbedtls-{{ .MBEDTLS_VERSION }}'
cmds:
#ensure directory is created
- cmd: '{{ ._MKDIR }} "{{ .MBEDTLS_SRC_DIR }}"'
#download mbedtls archive
- cmd: curl{{ exeExt }} -L '{{ .MBEDTLS_DOWNLOAD_URL }}' -o '{{ .MBEDTLS_DOWNLOAD_DIR }}/mbedtls.tar.bz2'
#extract the archive using bz2 (linux only)
- cmd: '{{ if eq OS "windows" }}wsl{{ end }} tar -xjf "{{ .MBEDTLS_DOWNLOAD_DIR }}/mbedtls.tar.bz2" -C "{{ .MBEDTLS_DOWNLOAD_DIR }}"'
mbedtls-configure:
internal: true
requires: { CMAKE_BUILD_DIR, MBEDTLS_VERSION }
vars:
MBEDTLS_SRC_DIR: '{{ .CMAKE_BUILD_DIR }}/_deps/mbedtls-{{ .MBEDTLS_VERSION }}'
MBEDTLS_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}/_deps/mbedtls-build'
MBEDTLS_CONFIG_FILE: '{{ .USER_WORKING_DIR }}/vendor/mbedtls/mbedtls_noscrypt_config.h'
cmds:
#clear build dir before re-configuring
- cmd: '{{ .RMDIR }} "{{ .MBEDTLS_BUILD_DIR }}"'
ignore_error: true
- cmd: cmake
-S '{{ .MBEDTLS_SRC_DIR }}'
-B '{{ .MBEDTLS_BUILD_DIR }}'
-DCMAKE_BUILD_TYPE=Release
-DENABLE_PROGRAMS=OFF
-DENABLE_TESTING=OFF
-DBUILD_SHARED_LIBS=OFF
-DUSE_SHARED_MBEDTLS_LIBRARY=OFF
-DUSE_STATIC_MBEDTLS_LIBRARY=ON
-DDISABLE_PACKAGE_CONFIG_AND_INSTALL=ON
-DMBEDTLS_CONFIG_FILE='{{ .MBEDTLS_CONFIG_FILE }}'
mbedtls-compile:
internal: true
requires: { CMAKE_BUILD_DIR }
vars:
MBEDTLS_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}/_deps/mbedtls-build'
cmds:
- cmd: cmake --build '{{ .MBEDTLS_BUILD_DIR }}' --config Release
mbedtls-build:
internal: true
desc: "Downloads, configures, and compiles mbedtls"
requires: { CMAKE_BUILD_DIR }
cmds:
- task: mbedtls-download
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
- task: mbedtls-configure
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
- task: mbedtls-compile
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
#################################
#
# CI TASKS
#
#################################
# runs the cmake setups to configure the mbedtls library build for testing
ci-configure-mbedtls:
internal: false
requires: { CMAKE_BUILD_DIR }
cmds:
- task: mbedtls-build
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
- task: cmake-build
vars:
CMAKE_TEST_STATUS: 'ON'
BUILD_CONFIG: 'Debug'
CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}'
CMAKE_CONFIG_ARGS: '
-DNC_ENABLE_UTILS=ON
-DCRYPTO_LIB=mbedtls
-DCRYPTO_LIB_DIR={{ .CMAKE_BUILD_DIR }}/_deps/mbedtls-build'
# runs the cmake setups to configure the default library build for testing
ci-configure-default:
internal: true
requires: { CMAKE_BUILD_DIR }
cmds:
- task: cmake-build
vars:
CMAKE_TEST_STATUS: 'ON'
BUILD_CONFIG: 'Debug'
CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}'
CMAKE_CONFIG_ARGS: '-DNC_ENABLE_UTILS=ON'
# runs cmake testing and memcheck on the mbedtls build
ci-test-mbedtls:
internal: false
requires: { CMAKE_BUILD_DIR }
cmds:
- task: cmake-test
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
#runs memcheck if the platform supports it
- task: memcheck
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
# runs cmake testing and memcheck on the default build
ci-test-default:
internal: true
requires: { CMAKE_BUILD_DIR }
cmds:
- task: cmake-test
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
#runs memcheck if the platform supports it
- task: memcheck
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
# called by Module.taskfile to run tests
ci-test:
vars:
MBEDTLS_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}/test/mbedtls'
DEFAULT_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}/test/default'
deps:
- task: ci-configure-default
vars: { CMAKE_BUILD_DIR: '{{ .DEFAULT_BUILD_DIR }}' }
- task: ci-configure-mbedtls
vars: { CMAKE_BUILD_DIR: '{{ .MBEDTLS_BUILD_DIR }}' }
cmds:
#cleanup build directories after testing
- defer: '{{ ._RMDIR }} "{{ .CMAKE_BUILD_DIR }}/test"'
- task: ci-test-default
vars: { CMAKE_BUILD_DIR: '{{ .DEFAULT_BUILD_DIR }}'}#
- task: ci-test-mbedtls
vars: { CMAKE_BUILD_DIR: '{{ .MBEDTLS_BUILD_DIR }}'}
ci-pack-source:
internal: true
desc: "Packs up the project source code and creates a tarball in the builds binary directory"
vars:
TARGET_SOURCE: '{{ .PROJECT_DIR }}/{{ .BINARY_DIR }}/{{ .PROJECT_NAME }}-src.tgz'
SOURCE_FILES:
CMakeLists.txt
Taskfile.yaml
src
include
license
tests
vendor
readme.md
CMakePresets.json
cmds:
#tar up the source
- cmd: tar -czf "{{ .TARGET_SOURCE }}" {{ .SOURCE_FILES | join " " }}
ci-build-win_x64:
internal: true
platforms: [ windows ]
vars:
TARGET: '{{ .PROJECT_DIR }}/{{ .BINARY_DIR }}/msvc-x64-{{ .CI_BUILD_CONFIG }}-{{ .PROJECT_NAME }}.tgz'
BUILD_DIR: 'build/win-x64'
TAR_FILES: "
{{ .PROJECT_NAME }}.dll
{{ .PROJECT_NAME }}.lib
{{ .PROJECT_NAME }}_static.lib
license.txt"
cmds:
#remove deps dir to avoid conflicts with vnbuild
- defer: '{{ ._RMDIR }} "{{ .BUILD_DIR }}/_deps"'
#run configure and compile commands
- task: cmake-build
vars:
CMAKE_BUILD_DIR: '{{ .BUILD_DIR }}'
BUILD_CONFIG: '{{ .CI_BUILD_CONFIG }}'
CMAKE_TEST_STATUS: 'OFF'
CMAKE_CONFIG_ARGS: '-G "Visual Studio 17 2022" -A x64 -NC_ENABLE_UTILS'
#copy license to build dir
- cmd: powershell cp license '{{ .BUILD_DIR }}/{{ .CI_BUILD_CONFIG }}/license.txt'
#tar up the binaries
- cmd: cd {{ .BUILD_DIR }}/{{ .CI_BUILD_CONFIG }} && tar -czf "{{ .TARGET }}" {{ .TAR_FILES }}
#called by build pipeline to build module
build:
cmds:
- cmd: echo "building project {{ .PROJECT_NAME }}"
- cmd: '{{ ._MKDIR }} {{ .BINARY_DIR }}'
#build windows x64
- task: ci-build-win_x64
#pack source
- task: ci-pack-source
#################################
#
# DEV TASKS
#
#################################
dev-test:
desc: "Re-runs compilation phase and test executable"
cmds:
- task: cmake-compile
vars: { BUILD_CONFIG: 'Debug' }
- task: cmake-test
vars: { CMAKE_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}' }
- task: memcheck
dev:
desc: "Runs local development tests and watches for changes"
summary: |
Watches for changes to source and config files, recompiles, and runs tests
automatically when changes are detected.
watch: true
sources:
- include/*
- src/*
- src/*/*
- tests/*
- CMakelists.txt
- vendor/*
cmds:
- task: dev-test
dev-gdb-test:
platforms: [ linux ]
desc: "Starts a new gdb session on the test executable"
summary: |
(Linux only) Starts a new gdb session on the test executable.
Use the 'run' command to start the test executable.
interactive: true
cmds:
- task: cmake-compile
vars: { BUILD_CONFIG: 'Debug' }
- cmd: gdb '{{ .CMAKE_BUILD_DIR }}/{{ .TEST_EXE_NAME }}'
dev-update-deps:
desc: "Updates vendored projects files (headers mostly) from their source repositories to the configured version"
cmds:
- defer: '{{ ._RMDIR }} .update/'
#must run serially since git does not support mutliple instances
- task: dev-update-monocypher
- task: dev-update-mbedtls-headers
- task: dev-update-openssl-headers
- task: dev-set-secp256-headers
dev-update-monocypher:
vars:
MC_GIT_URL: 'https://github.com/LoupVaillant/Monocypher'
MC_GIT_BRANCH: 'master' #NOTE: Always update to the latest master branch, then verify changes manually
MC_DIR: 'vendor/monocypher'
TMP_DIR: '.update/mc'
cmds:
- cmd: '{{ ._MKDIR }} "{{ .TMP_DIR }}"'
ignore_error: true
- cmd: git clone --depth 1 --branch {{ .MC_GIT_BRANCH }} {{ .MC_GIT_URL }} '{{ .TMP_DIR }}'
- for: [ 'src/monocypher.h', 'src/monocypher.c' ]
cmd: powershell cp '{{ .TMP_DIR }}/{{ .ITEM }}' '{{ .MC_DIR }}'
dev-update-mbedtls-headers:
vars:
MBEDTLS_GIT_URL: 'https://github.com/Mbed-TLS/mbedtls'
MBEDTLS_GIT_BRANCH: 'v{{ .MBEDTLS_VERSION }}'
MBEDTLS_DIR: 'vendor/mbedtls'
TMP_DIR: '.update/mbedtls'
cmds:
- cmd: '{{ ._MKDIR }} "{{ .TMP_DIR }}"'
ignore_error: true
- cmd: git clone --depth 1 --branch {{ .MBEDTLS_GIT_BRANCH }} {{ .MBEDTLS_GIT_URL }} '{{ .TMP_DIR }}'
- for: [ 'include/mbedtls' ]
cmd: powershell cp -Recurse -Force '{{ .TMP_DIR }}/{{ .ITEM }}' '{{ .MBEDTLS_DIR }}'
dev-update-openssl-headers:
vars:
OPENSSL_GIT_URL: 'https://github.com/openssl/openssl'
OPENSSL_GIT_BRANCH: 'openssl-3.4.0'
OPENSSL_DIR: 'vendor/openssl'
TMP_DIR: '.update/openssl'
cmds:
- cmd: '{{ ._MKDIR }} "{{ .TMP_DIR }}"'
ignore_error: true
- cmd: git clone --depth 1 --branch {{ .OPENSSL_GIT_BRANCH }} {{ .OPENSSL_GIT_URL }} '{{ .TMP_DIR }}'
- for: [ 'include/openssl/*' ]
cmd: powershell cp -Recurse -Force '{{ .TMP_DIR }}/{{ .ITEM }}' '{{ .OPENSSL_DIR }}'
dev-set-secp256-headers:
vars:
SECP256_GIT_URL: 'https://github.com/bitcoin-core/secp256k1'
SECP256_GIT_BRANCH: 'v0.6.0'
SECP256_DIR: 'vendor/secp256k1'
TMP_DIR: '.update/secp256k1'
cmds:
- cmd: '{{ ._MKDIR }} "{{ .TMP_DIR }}"'
ignore_error: true
- cmd: git clone --depth 1 --branch {{ .SECP256_GIT_BRANCH }} {{ .SECP256_GIT_URL }} '{{ .TMP_DIR }}'
- for: [ 'include/*' ]
cmd: powershell cp -Recurse -Force '{{ .TMP_DIR }}/{{ .ITEM }}' '{{ .SECP256_DIR }}'
|