# Copyright 2015-2019 Benjamin Fry # # Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be # copied, modified, or distributed except according to those terms. # This is a Makefile for `cargo make`, to use it first install cargo-make with `cargo install cargo-make` [config] skip_core_tasks = true [config.modify_core_tasks] # if true, all core tasks are set to private (default false) private = true ## General environment configuration [env] TARGET_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target" CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY = "${TARGET_DIR}" CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = "true" CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY = "${TARGET_DIR}/kcov" CARGO_MAKE_KCOV_DOWNLOAD_DIRECTORY = "${TARGET_DIR}/kcov-dl" CARGO_MAKE_KCOV_VERSION = "37" TDNS_BIND_PATH = "${TARGET_DIR}/bind" TDNS_WORKSPACE_ROOT = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}" TDNS_WITH_KCOV_ARGS = "--lib --bins --tests --examples" CARGO_MAKE_CRATES_IO_TOKEN = { value = "--token=${CRATES_IO_TOKEN}", condition = { env_set = ["CRATES_IO_TOKEN"] } } #RUST_BACKTRACE=1 ## ## Installation tasks ## [tasks.install-openssl] description = "Installs OpenSSL on Windows" workspace = false env = { OPENSSL_VERSION = "1_1_1k", OPENSSL_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}\\target\\OpenSSL" } condition = { platforms = ["windows"], files_not_exist = ["${OPENSSL_DIR}"] } script_runner = "powershell" script_extension = "ps1" script = [ ''' mkdir ${env:CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}\\target mkdir ${env:CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}\\target\OpenSSL Invoke-WebRequest -URI "http://slproweb.com/download/Win64OpenSSL-${env:OPENSSL_VERSION}.exe" -OutFile "${env:CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}\target\OpenSSL.exe" Start-Process -FilePath "${env:CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}\target\OpenSSL.exe" -ArgumentList "/SILENT /VERYSILENT /SP- /DIR=${env:OPENSSL_DIR}" Invoke-WebRequest "https://curl.haxx.se/ca/cacert.pem" -O "${env:OPENSSL_DIR}\cacert.pem" ''' ] [tasks.install-bind] description = "Installs BIND9 on Ubuntu" workspace = false condition = { platforms = ["linux", "mac"], files_not_exist = ["${TDNS_BIND_PATH}/sbin/named"] } env = { BIND_VER="9.11.7" } script_runner = "@shell" script = [ ''' set -e if ${TDNS_BIND_PATH}/sbin/named -v ; then exit 0 ; fi ## This must run after OpenSSL installation echo installing python-ply if apt-get --version ; then sudo apt-get install -y python-ply ; fi if openssl version ; then WITH_OPENSSL="--with-openssl=$(dirname $(dirname $(which openssl)))" ; fi mkdir -p ${TARGET_DIR:?} echo "----> downloading bind" rm -rf ${TARGET_DIR:?}/bind-${BIND_VER} wget -O ${TARGET_DIR:?}/bind-${BIND_VER}.tar.gz https://downloads.isc.org/isc/bind9/${BIND_VER}/bind-${BIND_VER}.tar.gz ls -la ${TARGET_DIR:?}/bind-${BIND_VER}.tar.gz tar -xzf ${TARGET_DIR:?}/bind-${BIND_VER}.tar.gz -C ${TARGET_DIR:?} echo "----> compiling bind" cd ${TARGET_DIR:?}/bind-${BIND_VER} ./configure --prefix ${TDNS_BIND_PATH:?} ${WITH_OPENSSL} make install cd - ${TDNS_BIND_PATH}/sbin/named -v rm ${TARGET_DIR:?}/bind-${BIND_VER}.tar.gz rm -rf ${TARGET_DIR:?}/bind-${BIND_VER} ''' ] [tasks.install-audit] description = "Installs cargo-audit" workspace = false condition_script = ["if cargo audit --version ; then exit 1 ; else exit 0 ; fi"] command = "cargo" args = ["install", "cargo-audit"] [tasks.install-with] description = "Installs cargo-with" workspace = false condition_script = ["if cargo with --version ; then exit 1 ; else exit 0 ; fi"] command = "cargo" args = ["install", "cargo-with", "--git=https://github.com/bluejekyll/cargo-with.git", "--branch=master"] [tasks.install-kcov] description = "Installs the kcov coverage tool" workspace = false script_runner = "bash" install_script = [ ''' KCOV_INSTALLATION_DIRECTORY="" KCOV_BINARY_DIRECTORY="" if [ -n "${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}" ]; then mkdir -p ${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY} cd ${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY} KCOV_INSTALLATION_DIRECTORY="$(pwd)/" cd - echo "Kcov Installation Directory: ${KCOV_INSTALLATION_DIRECTORY}" KCOV_BINARY_DIRECTORY="${KCOV_INSTALLATION_DIRECTORY}/build/src/" echo "Kcov Binary Directory: ${KCOV_BINARY_DIRECTORY}" fi if ${KCOV_BINARY_DIRECTORY}kcov --version ; then exit 0 ; fi # get help info to fetch all supported command line arguments KCOV_HELP_INFO=`${KCOV_BINARY_DIRECTORY}kcov --help` || true # check needed arguments are supported, else install if [[ $KCOV_HELP_INFO != *"--include-pattern"* ]] || [[ $KCOV_HELP_INFO != *"--exclude-line"* ]] || [[ $KCOV_HELP_INFO != *"--exclude-region"* ]]; then # check we are on a supported platform if [ "$(uname)" == "Linux" ]; then if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then echo "Installing/Upgrading kcov..." sudo apt-get update || true sudo apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc binutils-dev fi elif [ "$(uname)" == "Darwin" ]; then for brew_install in zlib bash cmake pkgconfig wget ; do if brew info ${brew_install} | grep "Not installed" ; then brew install ${brew_install} else echo "skipping ${brew_install} already installed" fi done fi mkdir -p ${CARGO_MAKE_KCOV_DOWNLOAD_DIRECTORY} cd ${CARGO_MAKE_KCOV_DOWNLOAD_DIRECTORY} KCOV_DOWNLOAD_DIRECTORY=$(pwd) rm -rf kcov-${CARGO_MAKE_KCOV_VERSION:?} rm -f v${CARGO_MAKE_KCOV_VERSION}.zip wget https://github.com/SimonKagstrom/kcov/archive/v${CARGO_MAKE_KCOV_VERSION}.zip unzip v${CARGO_MAKE_KCOV_VERSION}.zip cd kcov-${CARGO_MAKE_KCOV_VERSION} mkdir -p build cd ./build cmake .. make # if custom installation directory, leave kcov as local if [ -n "${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}" ]; then cd ${KCOV_DOWNLOAD_DIRECTORY}/kcov-${CARGO_MAKE_KCOV_VERSION} mv ./* ${KCOV_INSTALLATION_DIRECTORY} else sudo make install cd ../.. rm -rf kcov-${CARGO_MAKE_KCOV_VERSION} fi fi ''' ] ## ## Standard tasks for testing, building, etc. ## # TODO: actually make this await rather than sleep [tasks.await-update] description = "awaits the package to show up in crates.io" script_runner = "@shell" script = [ ''' sleep 10 ''' ] [tasks.clean-bind] description = "Remove the BIND9 build directory" workspace = false script_runner = "@shell" script = [ ''' rm -rf ${TDNS_BIND_PATH:?} rm -rf ${TDNS_BIND_PATH:?}_* ''' ] [tasks.clean-kcov] description = "Remove the kcov installation" workspace = false script_runner = "@shell" script = [ ''' rm -rf ${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY:?} ''' ] [tasks.clean] description = "Remove only the current workspace member" command = "cargo" args = ["clean", "-p", "${CARGO_MAKE_CRATE_NAME}"] [tasks.clean-all] description = "Remove only the current workspace member" script_runner = "@shell" script = [ ''' rm -rf ${TARGET_DIR:?} rm -rf target ''' ] [tasks.update] description = "Update dependencies" command = "cargo" args = ["update", "-p", "${CARGO_MAKE_CRATE_NAME}"] [tasks.fmt] description = "Check formatting with rustfmt" command = "cargo" args = ["fmt", "--", "--check"] [tasks.check] description = "Run a quick check on all the crates" command = "cargo" args = ["check", "--lib", "--examples", "--tests", "--bins", "@@remove-empty(FEATURES)"] [tasks.build] description = "Build all the crates" command = "cargo" args = ["build", "--lib", "--bins", "@@remove-empty(FEATURES)"] [tasks.test] description = "Run tests all the crates" command = "cargo" args = ["test", "--lib", "--examples", "--tests", "--bins", "@@remove-empty(FEATURES)"] [tasks.touch_all_rs] description = "Touch all Rust files (for clippy)" script_runner = "@shell" script = [ ''' find ${PWD} -name '*.rs' -exec touch {} \; ''' ] [tasks.clippy-inner] description = "Run the clippy linter on all crates" command = "cargo" args = ["clippy", "--lib", "--examples", "--tests", "--bins", "@@remove-empty(FEATURES)", "--", "-D", "warnings"] [tasks.clippy-default-features] description = "Run the clippy linter with default features" workspace = false env = { FEATURES = "" } run_task = { name = "clippy-inner" } [tasks.clippy-no-default-features] description = "Run the clippy linter with no-default-features" workspace = false env = { FEATURES = "--no-default-features" } run_task = { name = "clippy-inner" } [tasks.clippy-all-features] description = "Run the clippy linter with all-features" workspace = false env = { FEATURES = "--all-features" } run_task = { name = "clippy-inner" } [tasks.clippy] description = "Run the clippy linter with default features, no-default-features, and all-features" workspace = false dependencies = ["touch_all_rs"] run_task = { name = ["clippy-all-features", "clippy-default-features", "clippy-no-default-features"] } [tasks.build-bench] description = "Check that all benchmarks compile" command = "cargo" toolchain = "nightly" args = ["bench", "--no-run"] [tasks.audit] description = "Run cargo audit on all crates" workspace = false dependencies = ["check", "install-audit"] command = "cargo" args = ["audit", "--deny", "warnings"] [tasks.cleanliness] description = "Runs clippy, fmt, and audit" workspace = false dependencies = ["clippy", "fmt", "audit"] [tasks.bind-compatibility] description = "Run compatibility tests, currently the BIND9 installation has issues, set TDNS_BIND_PATH to another BIND9 installation" workspace = false dependencies = ["install-bind"] command = "cargo" args = ["test", "--manifest-path=tests/compatibility-tests/Cargo.toml", "--no-default-features", "--features=bind"] [tasks.all] description = "Run check, build, and test on all crates" dependencies = ["check", "build", "test"] [tasks.default] description = "Run the all task" run_task = "all" ## ## All feature testing builds ## [tasks.default-features] description = "Run all with default features" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "" } run_task = { name = "all", fork = true } [tasks.no-default-features] description = "Run all with --no-default-features" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--no-default-features", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "tests/compatibility-tests" } run_task = { name = "all", fork = true } [tasks.all-features] description = "Run all with --all-features" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--all-features" } run_task = { name = "all", fork = true } [tasks.dns-over-openssl] description = "Run all with --features=dns-over-openssl" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--features=dns-over-openssl", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "crates/async-std-resolver;crates/native-tls;crates/openssl;crates/rustls;crates/https;tests/compatibility-tests;util" } run_task = { name = "all", fork = true } [tasks.dnssec-openssl] description = "Run all with --features=dnssec-openssl" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--features=dnssec-openssl", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "crates/async-std-resolver;crates/native-tls;crates/openssl;crates/rustls;crates/https;tests/compatibility-tests;util" } run_task = { name = "all", fork = true } [tasks.dnssec-ring] description = "Run all with --features=dnssec-ring" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--features=dnssec-ring", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "crates/async-std-resolver;crates/native-tls;crates/openssl;crates/rustls;crates/https;tests/compatibility-tests;util" } run_task = { name = "all", fork = true } [tasks.dns-over-rustls] description = "Run all with --features=dns-over-rustls" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--features=dns-over-rustls", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "crates/async-std-resolver;crates/native-tls;crates/openssl;crates/rustls;crates/https;tests/compatibility-tests;util" } run_task = { name = "all", fork = true } [tasks.dns-over-https-rustls] description = "Run all with --features=dns-over-https-rustls" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--features=dns-over-https-rustls", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "crates/async-std-resolver;crates/native-tls;crates/openssl;crates/rustls;crates/https;tests/compatibility-tests;util" } run_task = { name = "all", fork = true } [tasks.dns-over-native-tls] description = "Run all with --features=dns-over-native-tls" dependencies = ["install-openssl"] workspace = false # TODO: seems like a gap in testing if there are no testst in client for native-tls env = { FEATURES = "--features=dns-over-native-tls", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "crates/async-std-resolver;crates/native-tls;crates/openssl;crates/rustls;crates/https;crates/server;bin;tests/compatibility-tests;tests/integration-tests;util" } run_task = { name = "all", fork = true } [tasks.mdns] description = "Run all with --features=mdns" dependencies = ["install-openssl"] workspace = false env = { FEATURES = "--features=mdns", CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "crates/resolver;crates/async-std-resolver;crates/native-tls;crates/openssl;crates/rustls;crates/https;crates/server;bin;tests/compatibility-tests;tests/integration-tests;util" } run_task = { name = "all", fork = true } [tasks.async-std] description = "Run all for async-std crates" workspace = false env = { CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = "crates/async-std-resolver" } run_task = { name = "all", fork = true } [tasks.world] description = "Run all with every features independently (this will melt your computer)" workspace = false run_task = { name = ["no-default-features", "default-features", "all-features", "dns-over-https-rustls", "dns-over-rustls", "dns-over-native-tls", "dns-over-openssl", "dnssec-openssl", "dnssec-ring", "mdns", "async-std"], fork = false } ## ## Coverage ## [tasks.coverage-kcov] description = "Installs (if missing) and runs coverage using kcov (not supported on windows)" windows_alias = "empty" mac_alias = "empty" # TODO: mac works, but is so slow it hangs on some tests... dependencies = ["install-with", "install-kcov"] script_runner = "bash" env = { CARGO_MAKE_KCOV_INCLUDE_PATTERN = "${CARGO_MAKE_WORKING_DIRECTORY}/src/", CARGO_MAKE_COVERAGE_REPORT_DIRECTORY = "${TARGET_DIR}/coverage", CARGO_MAKE_WITH_KCOV_ARGS = "${TDNS_WITH_KCOV_ARGS}" } script = [ ''' set -e echo "Working Directory: ${CARGO_MAKE_WORKING_DIRECTORY}" KCOV_BINARY_DIRECTORY="" if [ -n "${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}" ]; then cd ${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY} KCOV_INSTALLATION_DIRECTORY="$(pwd)/" cd - echo "Kcov Installation Directory: ${KCOV_INSTALLATION_DIRECTORY}" KCOV_BINARY_DIRECTORY="${KCOV_INSTALLATION_DIRECTORY}/build/src/" echo "Kcov Binary Directory: ${KCOV_BINARY_DIRECTORY}" fi TARGET_DIRECTORY="target/coverage/${CARGO_MAKE_CRATE_FS_NAME}" if [ -n "$CARGO_MAKE_COVERAGE_REPORT_DIRECTORY" ]; then TARGET_DIRECTORY="$CARGO_MAKE_COVERAGE_REPORT_DIRECTORY/${CARGO_MAKE_CRATE_FS_NAME}" mkdir -p ${TARGET_DIRECTORY} else mkdir -p ${TARGET_DIRECTORY} fi BINARY_DIRECTORY=target/debug if [ -n "$CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY" ]; then BINARY_DIRECTORY="${CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY}/debug" fi KCOV_EXCLUDE_LINE_ARG="" if [ -n "$CARGO_MAKE_KCOV_EXCLUDE_LINE" ]; then KCOV_EXCLUDE_LINE_ARG="--exclude-line=${CARGO_MAKE_KCOV_EXCLUDE_LINE}" fi KCOV_EXCLUDE_REGION_ARG="" if [ -n "$CARGO_MAKE_KCOV_EXCLUDE_REGION" ]; then KCOV_EXCLUDE_REGION_ARG="--exclude-region=${CARGO_MAKE_KCOV_EXCLUDE_REGION}" fi cd ${CARGO_MAKE_WORKING_DIRECTORY} echo "Working director: ${PWD}" echo "Running tests from directory: ${BINARY_DIRECTORY}" # Evaluate variables that may be in the expression # This allows us to do double expansion on a non-variable second expansion CARGO_MAKE_TEST_COVERAGE_BINARY_FILTER_REGEX="$(sh -c "echo \"${CARGO_MAKE_TEST_COVERAGE_BINARY_FILTER}\"")" echo "Test binary filter regex: ${CARGO_MAKE_TEST_COVERAGE_BINARY_FILTER_REGEX}" ## Setup the env for the kcov script KCOV=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY:?}/scripts/kcov.sh export KCOV_BINARY=${KCOV_BINARY_DIRECTORY:?}/kcov export KCOV_TARGET_DIRECTORY=${TARGET_DIRECTORY:?} export KCOV_INCLUDE_PATTERN=${CARGO_MAKE_KCOV_INCLUDE_PATTERN:?} export KCOV_EXCLUDE_LINE_ARG export KCOV_EXCLUDE_REGION_ARG echo "Running coverage for ${CARGO_MAKE_CRATE_FS_NAME} ${CARGO_MAKE_WITH_KCOV_ARGS} ${FEATURES}" cargo with "${KCOV:?} {bin} {args}" -- test ${CARGO_MAKE_WITH_KCOV_ARGS} ${FEATURES} || true ''' ] [tasks.coverage] description = "Run coverage reports on all crates" run_task = "coverage-kcov" ## ## publishing ## [tasks.package] description = "package artifacts for each crate" command = "cargo" args = ["package", "--locked"] [tasks.inner_publish] description = "publish next release" dependencies = ["await-update", "update", "check", "package"] private = true command = "cargo" args = ["publish", "--verbose", "--locked", "@@remove-empty(CARGO_MAKE_CRATES_IO_TOKEN)"] [tasks.publish] description = "publish next release" workspace = false env = { CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = "tests/*"} run_task = { name = "inner_publish", fork = true }