-
Notifications
You must be signed in to change notification settings - Fork 46
/
release-linux.sh
executable file
·129 lines (110 loc) · 3.71 KB
/
release-linux.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
121
122
123
124
125
126
127
128
129
#!/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"}
# All flags passed to this script are passed to cargo.
cargo_flags=( "$@" )
# Build the x86_64 GNU linux release
build_x86_64_gnu() {
install_cross
cargo clean
cross build --target x86_64-unknown-linux-gnu "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/libpact_ffi.a" \
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64.a.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/libpact_ffi.so" \
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64.so.gz"
fi
}
build_x86_64_musl() {
sudo apt-get install -y musl-tools
cargo clean
cargo build --target x86_64-unknown-linux-musl "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
BUILD_SCRIPT=$(cat <<EOM
apk add --no-cache musl-dev gcc && \
cd /scratch && \
ar -x libpact_ffi.a && \
gcc -shared *.o -o libpact_ffi.so && \
rm -f *.o
EOM
)
docker run \
--platform=linux/amd64 \
--rm \
-v "$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release:/scratch" \
alpine \
/bin/sh -c "$BUILD_SCRIPT"
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/libpact_ffi.a" \
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64-musl.a.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/libpact_ffi.so" \
"$ARTIFACTS_DIR/libpact_ffi-linux-x86_64-musl.so.gz"
fi
}
install_cross() {
cargo install cross@0.2.5
}
build_aarch64_gnu() {
install_cross
cargo clean
cross build --target aarch64-unknown-linux-gnu "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/libpact_ffi.a" \
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64.a.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/libpact_ffi.so" \
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64.so.gz"
fi
}
build_aarch64_musl() {
install_cross
cargo clean
cross build --target aarch64-unknown-linux-musl "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
BUILD_SCRIPT=$(cat <<EOM
apk add --no-cache musl-dev gcc && \
cd /scratch && \
ar -x libpact_ffi.a && \
gcc -shared *.o -o libpact_ffi.so && \
rm -f *.o
EOM
)
docker run \
--platform=linux/arm64 \
--rm \
-v "$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release:/scratch" \
alpine \
/bin/sh -c "$BUILD_SCRIPT"
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/libpact_ffi.a" \
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64-musl.a.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/libpact_ffi.so" \
"$ARTIFACTS_DIR/libpact_ffi-linux-aarch64-musl.so.gz"
fi
}
build_header() {
rustup toolchain install nightly
rustup run nightly cbindgen \
--config cbindgen.toml \
--crate pact_ffi \
--output "$ARTIFACTS_DIR/pact.h"
rustup run nightly cbindgen \
--config cbindgen-c++.toml \
--crate pact_ffi \
--output "$ARTIFACTS_DIR/pact-cpp.h"
}
build_x86_64_gnu
build_x86_64_musl
build_aarch64_gnu
build_aarch64_musl
build_header