Skip to content

Commit

Permalink
makefile: check cargo version
Browse files Browse the repository at this point in the history
For the build-package target (used by cargo make repo), we need Cargo
version 1.51 or higher to build a dependency of the variants workspace.
To make this clear, we check the Cargo version before build-package and
provide a clear error message.
  • Loading branch information
webern committed Apr 20, 2021
1 parent c3a73ca commit a8a10b1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,31 @@ cargo install \
'''
]

# We need Cargo version 1.51 or higher in order to build a workspace's
# dependency during build-package
[tasks.check-cargo-version]
script_runner = "bash"
script = [
'''
set -euo pipefail
cargo_version=$(cargo --version | awk '{print $2}')
strarr=(${cargo_version//./ })
cargo_major="${strarr[0]}"
cargo_minor="${strarr[1]}"
if [ "${cargo_major}" -gt "1" ] ; then
# cargo is version 2 or higher, so it's higher than 1.51
exit 0
fi
if [ "${cargo_minor}" -lt "51" ] ; then
echo "Error: Cargo 1.51.0 or greater is required, your version is ${cargo_version}" >&2
exit 1
fi
'''
]

# Builds a package including its build-time and runtime dependency packages.
[tasks.build-package]
dependencies = ["build-tools", "publish-setup"]
dependencies = ["check-cargo-version", "build-tools", "publish-setup"]
script_runner = "bash"
script = [
'''
Expand Down

0 comments on commit a8a10b1

Please sign in to comment.