-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-release
executable file
·62 lines (53 loc) · 1.9 KB
/
build-release
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
#!/bin/bash
#
# Usage: ./build-release <PROJECT>
#
# Called by CI to verify the source tree is ready for release, and to build
# release binaries. We use 'cross' where necessary for cross-platform builds.
#
# We keep all this logic in a separate script so we don't need to duplicate it
# in every CI file.
set -euo pipefail
# Command-line arguments.
PKG_NAME="$1"
BIN_NAME="$PKG_NAME"
TARGET="$2"
HOST="$3"
CARGO_COMMAND="$4"
# This is either a tag, or possibly something like refs/heads/feature-branch-1.
# The important thing is that we remove all slashes.
VERSION="$RELEASE_VERSION"
# Install 'cargo deny'.
echo "Installing cargo-deny"
cargo_deny_version=0.12.1
cargo_deny_basename=cargo-deny-$cargo_deny_version-$HOST
curl -fLO https://github.com/EmbarkStudios/cargo-deny/releases/download/$cargo_deny_version/$cargo_deny_basename.tar.gz
tar xf $cargo_deny_basename.tar.gz
mv $cargo_deny_basename/cargo-deny /usr/local/bin/
rm -rf $cargo_deny_basename $cargo_deny_basename.tar.gz
# Perform standard checks and tests.
echo "Verifying code is ready for release"
cargo deny check
cargo fmt -- --check
cargo clippy -- -D warnings
cargo test --package "$PKG_NAME"
# Install cross if needed.
if [ "$CARGO_COMMAND" = "cross" ]; then
echo "Installing cross for cross-compilation"
cross_version=v0.2.1
cross_basename=cross-$cross_version-$HOST
curl -fLO https://github.com/rust-embedded/cross/releases/download/$cross_version/$cross_basename.tar.gz
tar xf $cross_basename.tar.gz
mv cross /usr/local/bin/
rm -rf $cross_basename.tar.gz
fi
# Build our binaries.
echo "Building binaries using $CARGO_COMMAND"
$CARGO_COMMAND build --package "$PKG_NAME" --release --target "$TARGET"
# Figure out whether binaries have a file extension.
case "$TARGET" in
*windows*) bin_ext=.exe ;;
*) bin_ext= ;;
esac
# Package binaries.
zip -j "$PKG_NAME"_"$VERSION"_"$TARGET".zip target/"$TARGET"/release/"$BIN_NAME"$bin_ext