1
1
#! /bin/bash
2
2
3
- if [ $# -lt 1 ]
3
+ set -e
4
+ set -x
5
+
6
+ RUST_DIR=" $( cd -- " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
7
+
8
+ source " $RUST_DIR /scripts/gzip-and-sum.sh"
9
+ ARTIFACTS_DIR=${ARTIFACTS_DIR:- " $RUST_DIR /release_artifacts" }
10
+ mkdir -p " $ARTIFACTS_DIR "
11
+ export CARGO_TARGET_DIR=${CARO_TARGET_DIR:- " $RUST_DIR /target" }
12
+
13
+ if [ $# -lt 2 ]
4
14
then
5
- echo " Usage : $0 <Linux|Windows|macOS> <version tag >"
15
+ echo " Usage : $0 <Linux|Windows|macOS> <release version> <cargo flags >"
6
16
exit
7
17
fi
8
18
9
- set -e
19
+ APP=pact-protobuf-plugin
20
+ OS=$1
21
+ shift ;
22
+ VERSION=$1
23
+ shift ;
24
+ echo Building Release for " $OS "
25
+ # All flags passed to this script are passed to cargo.
26
+ cargo_flags=( " $@ " )
27
+ build_manifest () {
28
+ NEXT=$( echo " $VERSION " | sed ' s/^refs\/tags\/v-//' )
29
+ # get latest release tag, if NEXT still contains refs
30
+ if [[ " ${NEXT} " =~ " refs" * ]]; then
31
+ CRATE_VERSION=$( cat Cargo.toml| grep ' version = ".*"' -m1 | cut -d ' "' -f 2)
32
+ echo " defaulting NEXT=$VERSION to version from Cargo.toml $CRATE_VERSION "
33
+ NEXT=$CRATE_VERSION
34
+ # LATEST_RELEASE=$(echo $(curl -s https://api.github.com/repos/pact-foundation/pact-stub-server/releases/latest | jq -r '.name') | sed 's/v//')
35
+ # echo "defaulting NEXT=$VERSION to latest release $LATEST_RELEASE"
36
+ # NEXT=$LATEST_RELEASE
37
+ fi
38
+ sed -e ' s/\"version\": \".*\"/\"version\": \"' ${NEXT} ' \"/' " $RUST_DIR /pact-plugin.json" > " $ARTIFACTS_DIR /pact-plugin.json"
39
+ sed -e ' s/VERSION=\".*\"/VERSION=\"' ${NEXT} ' \"/' " $RUST_DIR /scripts/install-plugin.sh" > " $ARTIFACTS_DIR /install-plugin.sh"
40
+ openssl dgst -sha256 -r $ARTIFACTS_DIR /install-plugin.sh > " $ARTIFACTS_DIR /install-plugin.sh.sha256"
41
+ }
42
+ install_cross () {
43
+ cargo install cross@0.2.5
44
+ }
45
+
46
+ build_linux_x86_64 () {
47
+ install_cross
48
+ cargo clean
49
+ cross build --target=x86_64-unknown-linux-musl " ${cargo_flags[@]} "
50
+ if [[ " ${cargo_flags[*]} " =~ " --release" ]]; then
51
+ gzip_and_sum \
52
+ " $CARGO_TARGET_DIR /x86_64-unknown-linux-musl/release/${APP} " \
53
+ " $ARTIFACTS_DIR /${APP} -linux-x86_64.gz"
54
+ # cargo clean
55
+ fi
56
+ }
57
+
58
+ build_linux_aarch64 () {
59
+ install_cross
60
+ cargo clean
61
+ cross build --target=aarch64-unknown-linux-musl " ${cargo_flags[@]} "
62
+
63
+ if [[ " ${cargo_flags[*]} " =~ " --release" ]]; then
64
+ gzip_and_sum \
65
+ " $CARGO_TARGET_DIR /aarch64-unknown-linux-musl/release/${APP} " \
66
+ " $ARTIFACTS_DIR /${APP} -linux-aarch64.gz"
67
+ fi
68
+ }
69
+ # Build the x86_64 darwin release
70
+ build_macos_x86_64 () {
71
+ cargo build --target x86_64-apple-darwin " ${cargo_flags[@]} "
72
+
73
+ if [[ " ${cargo_flags[*]} " =~ " --release" ]]; then
74
+ gzip_and_sum \
75
+ " $CARGO_TARGET_DIR /x86_64-apple-darwin/release/${APP} " \
76
+ " $ARTIFACTS_DIR /${APP} -osx-x86_64.gz"
77
+ gzip_and_sum \
78
+ " $CARGO_TARGET_DIR /x86_64-apple-darwin/release/${APP} " \
79
+ " $ARTIFACTS_DIR /${APP} -macos-x86_64.gz"
80
+ fi
81
+ }
82
+
83
+ # Build the aarch64 darwin release
84
+ build_macos_aarch64 () {
85
+ cargo build --target aarch64-apple-darwin " ${cargo_flags[@]} "
86
+
87
+ if [[ " ${cargo_flags[*]} " =~ " --release" ]]; then
88
+ gzip_and_sum \
89
+ " $CARGO_TARGET_DIR /aarch64-apple-darwin/release/${APP} " \
90
+ " $ARTIFACTS_DIR /${APP} -osx-aarch64.gz"
91
+ gzip_and_sum \
92
+ " $CARGO_TARGET_DIR /aarch64-apple-darwin/release/${APP} " \
93
+ " $ARTIFACTS_DIR /${APP} -macos-aarch64.gz"
94
+ fi
95
+ }
96
+
97
+ # Build the x86_64 windows release
98
+ build_windows_x86_64 () {
99
+ cargo build --target x86_64-pc-windows-msvc " ${cargo_flags[@]} "
100
+
101
+ # If --release in cargo flags, then gzip and sum the release artifacts
102
+ if [[ " ${cargo_flags[*]} " =~ " --release" ]]; then
103
+ gzip_and_sum \
104
+ " $CARGO_TARGET_DIR /x86_64-pc-windows-msvc/release/${APP} .exe" \
105
+ " $ARTIFACTS_DIR /${APP} -windows-x86_64.exe.gz"
106
+ fi
107
+ }
10
108
11
- echo Building Release for " $1 " - " $2 "
109
+ # Build the aarch64 windows release
110
+ build_windows_aarch64 () {
111
+ cargo build --target aarch64-pc-windows-msvc " ${cargo_flags[@]} "
12
112
13
- cargo clean
14
- mkdir -p target/artifacts
113
+ if [[ " ${cargo_flags[*]} " =~ " --release" ]]; then
114
+ gzip_and_sum \
115
+ " $CARGO_TARGET_DIR /aarch64-pc-windows-msvc/release/${APP} .exe" \
116
+ " $ARTIFACTS_DIR /${APP} -windows-aarch64.exe.gz"
117
+ fi
118
+ }
15
119
16
- case " $1 " in
120
+ case " $OS " in
17
121
Linux) echo " Building for Linux"
18
- docker run --rm --user " $( id -u) " :" $( id -g) " -v " $( pwd) :/workspace" -w /workspace -t \
19
- pactfoundation/rust-musl-build -c ' LIBZ_SYS_STATIC=1 cargo build --release'
20
- gzip -c target/release/pact-protobuf-plugin > target/artifacts/pact-protobuf-plugin-linux-x86_64.gz
21
- openssl dgst -sha256 -r target/artifacts/pact-protobuf-plugin-linux-x86_64.gz > target/artifacts/pact-protobuf-plugin-linux-x86_64.gz.sha256
22
- cp pact-plugin.json target/artifacts
23
- NEXT=$( echo " $2 " | cut -d\- -f2)
24
- sed -e ' s/VERSION=\"0.1.5\"/VERSION=\"' ${NEXT} ' \"/' scripts/install-plugin.sh > target/artifacts/install-plugin.sh
25
- openssl dgst -sha256 -r target/artifacts/install-plugin.sh > target/artifacts/install-plugin.sh.sha256
26
-
27
- # Build aarch64
28
- cargo install cross --git https://github.com/cross-rs/cross
29
- cross build --target aarch64-unknown-linux-gnu --release
30
- gzip -c target/aarch64-unknown-linux-gnu/release/pact-protobuf-plugin > target/artifacts/pact-protobuf-plugin-linux-aarch64.gz
31
- openssl dgst -sha256 -r target/artifacts/pact-protobuf-plugin-linux-aarch64.gz > target/artifacts/pact-protobuf-plugin-linux-aarch64.gz.sha256
122
+ build_linux_x86_64
123
+ build_linux_aarch64
124
+ build_manifest
32
125
;;
33
- Windows) echo " Building for Windows"
34
- cargo build --release
35
- gzip -c target/release/pact-protobuf-plugin.exe > target/artifacts/pact-protobuf-plugin-windows-x86_64.exe.gz
36
- openssl dgst -sha256 -r target/artifacts/pact-protobuf-plugin-windows-x86_64.exe.gz > target/artifacts/pact-protobuf-plugin-windows-x86_64.exe.gz.sha256
126
+ Windows) echo " Building for windows"
127
+ build_windows_x86_64
128
+ build_windows_aarch64
37
129
;;
38
- macOS) echo " Building for OSX"
39
- cargo build --release
40
- gzip -c target/release/pact-protobuf-plugin > target/artifacts/pact-protobuf-plugin-osx-x86_64.gz
41
- openssl dgst -sha256 -r target/artifacts/pact-protobuf-plugin-osx-x86_64.gz > target/artifacts/pact-protobuf-plugin-osx-x86_64.gz.sha256
42
- # macos
43
- gzip -c target/release/pact-protobuf-plugin > target/artifacts/pact-protobuf-plugin-macos-x86_64.gz
44
- openssl dgst -sha256 -r target/artifacts/pact-protobuf-plugin-macos-x86_64.gz > target/artifacts/pact-protobuf-plugin-macos-x86_64.gz.sha256
45
-
46
- # M1
47
- # export SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path)
48
- # export MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version)
49
- export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:- 12}
50
- cargo build --target aarch64-apple-darwin --release
51
-
52
- gzip -c target/aarch64-apple-darwin/release/pact-protobuf-plugin > target/artifacts/pact-protobuf-plugin-osx-aarch64.gz
53
- openssl dgst -sha256 -r target/artifacts/pact-protobuf-plugin-osx-aarch64.gz > target/artifacts/pact-protobuf-plugin-osx-aarch64.gz.sha256
54
- # macos
55
- gzip -c target/aarch64-apple-darwin/release/pact-protobuf-plugin > target/artifacts/pact-protobuf-plugin-macos-aarch64.gz
56
- openssl dgst -sha256 -r target/artifacts/pact-protobuf-plugin-macos-aarch64.gz > target/artifacts/pact-protobuf-plugin-macos-aarch64.gz.sha256
130
+ macOS) echo " Building for macos"
131
+ build_macos_x86_64
132
+ build_macos_aarch64
57
133
;;
58
- * ) echo " $1 is not a recognised OS"
134
+ * ) echo " $OS is not a recognised OS"
59
135
exit 1
60
136
;;
61
- esac
137
+ esac
0 commit comments