-
Notifications
You must be signed in to change notification settings - Fork 19
/
release.sh
executable file
·120 lines (103 loc) · 3.41 KB
/
release.sh
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
#!/bin/bash
set -e
set -x
RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd )"
source "$RUST_DIR/scripts/gzip-and-sum.sh"
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"}
mkdir -p "$ARTIFACTS_DIR"
export CARGO_TARGET_DIR=${CARO_TARGET_DIR:-"$RUST_DIR/target"}
if [ $# -lt 1 ]
then
echo "Usage : $0 <Linux|Windows|macOS> <cargo flags>"
exit
fi
APP=pact-stub-server
OS=$1
shift;
echo Building Release for "$OS"
# All flags passed to this script are passed to cargo.
cargo_flags=( "$@" )
install_cross() {
cargo install [email protected]
}
build_linux_x86_64() {
install_cross
cargo clean
cross build --target=x86_64-unknown-linux-musl "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-linux-x86_64.gz"
fi
}
build_linux_aarch64() {
install_cross
cargo clean
cross build --target=aarch64-unknown-linux-musl "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-linux-aarch64.gz"
fi
#cargo clean
}
# Build the x86_64 darwin release
build_macos_x86_64() {
cargo build --target x86_64-apple-darwin "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-osx-x86_64.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-macos-x86_64.gz"
fi
}
# Build the aarch64 darwin release
build_macos_aarch64() {
cargo build --target aarch64-apple-darwin "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-osx-aarch64.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-macos-aarch64.gz"
fi
}
# Build the x86_64 windows release
build_windows_x86_64() {
cargo build --target x86_64-pc-windows-msvc "${cargo_flags[@]}"
# If --release in cargo flags, then gzip and sum the release artifacts
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-pc-windows-msvc/release/${APP}.exe" \
"$ARTIFACTS_DIR/${APP}-windows-x86_64.exe.gz"
fi
}
# Build the aarch64 windows release
build_windows_aarch64() {
cargo build --target aarch64-pc-windows-msvc "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-pc-windows-msvc/release/${APP}.exe" \
"$ARTIFACTS_DIR/${APP}-windows-aarch64.exe.gz"
fi
}
case "$OS" in
Linux) echo "Building for Linux"
build_linux_x86_64
build_linux_aarch64
;;
Windows) echo "Building for windows"
build_windows_x86_64
build_windows_aarch64
;;
macOS) echo "Building for macos"
build_macos_x86_64
build_macos_aarch64
;;
*) echo "$OS is not a recognised OS"
exit 1
;;
esac