# 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: 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: build-internal 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/ ] task: clean-internal vars: { FILE: '{{ .ITEM }}'} ################################# # # INTERNAL TASKS # ################################# mkdir: internal: true requires: { DIR } preconditions: - '{{ if eq OS "windows" }}powershell Test-Path{{ else }}test -n{{ end }} {{ .DIR }}' cmds: - cmd: mkdir -p '{{ .DIR }}' platforms: [linux, darwin] - cmd: powershell mkdir '{{ .DIR }}' -Force platforms: [windows] rm-dir: internal: true requires: { DIR } preconditions: - '{{ if eq OS "windows" }}powershell Test-Path{{ else }}test -n{{ end }} {{ .DIR }}' cmds: - cmd: rm -rf '{{ .DIR }}' platforms: [linux, darwin] - cmd: powershell rm -Recurse -Force '{{ .DIR }}' platforms: [windows] clean-internal: internal: true ignore_error: true requires: { FILE } cmds: - cmd: rm -rf '{{ .FILE }}' platforms: [linux, darwin] - cmd: powershell rm -Recurse -Force '{{ .FILE }}' platforms: [windows] #build-internal: 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: #remove source dirs if they exist - cmd: rm -rf '{{ .MBEDTLS_SRC_DIR }}' platforms: [linux, darwin] - cmd: powershell rm -Recurse -Force '{{ .MBEDTLS_SRC_DIR }}' platforms: [windows] ignore_error: true #ensure directory is created - task: mkdir vars: { DIR: '{{ .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: '{{ if eq OS "windows"}}powershell{{ end }} rm -r {{ .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: CMAKE_CONFIG_ARGS: '-DNC_ENABLE_UTILS' MBEDTLS_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}/mbedtls' DEFAULT_BUILD_DIR: '{{ .CMAKE_BUILD_DIR }}/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: - 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: powershell rm -Recurse -Force "{{ .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 }}" - task: mkdir vars: { DIR: 'bin/' } #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: powershell rm -Recurse '.update/' -Force #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: powershell mkdir '{{ .TMP_DIR }}' -Force ignore_error: true - git clone --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: 'v3.6.2' MBEDTLS_DIR: 'vendor/mbedtls' TMP_DIR: '.update/mbedtls' cmds: - cmd: powershell mkdir '{{ .TMP_DIR }}' -Force ignore_error: true - git clone --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: powershell mkdir '{{ .TMP_DIR }}' -Force ignore_error: true - git clone --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: powershell mkdir '{{ .TMP_DIR }}' -Force ignore_error: true - git clone --branch {{ .SECP256_GIT_BRANCH }} {{ .SECP256_GIT_URL }} '{{ .TMP_DIR }}' - for: [ 'include/*' ] cmd: powershell cp -Recurse -Force '{{ .TMP_DIR }}/{{ .ITEM }}' '{{ .SECP256_DIR }}'