@@ -8,6 +8,12 @@ RELEASE_DOCKER_IMAGE="bufrelease-tag"
8
8
DIR=" $( CDPATH= cd " $( dirname " ${0} " ) /../../.." && pwd) "
9
9
cd " ${DIR} "
10
10
11
+ if [ -z " ${NUM_JOBS} " ]; then
12
+ # Go compiler itself already make use of multi-threading.
13
+ # So we are not using the count of cpu directly here.
14
+ NUM_JOBS=$(( $(nproc) / 3 ))
15
+ fi
16
+
11
17
fail () {
12
18
echo " error: $@ " >&2
13
19
exit 1
@@ -84,6 +90,8 @@ rm -rf "${RELEASE_DIR}"
84
90
mkdir -p " ${RELEASE_DIR} "
85
91
cd " ${RELEASE_DIR} "
86
92
93
+ i=0
94
+
87
95
for os in Darwin Linux Windows; do
88
96
for arch in x86_64 riscv64 arm64 armv7; do
89
97
# our goal is to have the binaries be suffixed with $(uname -s)-$(uname -m)
@@ -105,18 +113,21 @@ for os in Darwin Linux Windows; do
105
113
if [[ ! " ${arch} " =~ x86_64| arm64 ]] && [ " ${os} " != " Linux" ]; then
106
114
continue
107
115
fi
116
+ (( i= i% NUM_JOBS)) || true ; (( i++== 0 )) && wait
108
117
if [ " ${arch} " == " armv7" ]; then
109
- CGO_ENABLED=0 GOOS=$( goos " ${os} " ) GOARCH=$( goarch " ${arch} " ) GOARM=7 \
110
- go build -a -ldflags " -s -w" -trimpath -buildvcs=false -o " ${dir} /bin/${binary}${extension} " " ${DIR} /cmd/${binary} "
118
+ extra_go_env=" GOARM=7"
111
119
else
112
- CGO_ENABLED=0 GOOS=$( goos " ${os} " ) GOARCH=$( goarch " ${arch} " ) \
113
- go build -a -ldflags " -s -w" -trimpath -buildvcs=false -o " ${dir} /bin/${binary}${extension} " " ${DIR} /cmd/${binary} "
120
+ unset extra_go_env
114
121
fi
115
- cp " ${dir} /bin/${binary}${extension} " " ${binary} -${os} -${arch}${extension} "
122
+ env CGO_ENABLED=0 GOOS=$( goos " ${os} " ) GOARCH=$( goarch " ${arch} " ) $extra_go_env \
123
+ go build -a -ldflags " -s -w" -trimpath -buildvcs=false -o " ${dir} /bin/${binary}${extension} " " ${DIR} /cmd/${binary} " && \
124
+ cp " ${dir} /bin/${binary}${extension} " " ${binary} -${os} -${arch}${extension} " &
116
125
done
117
126
done
118
127
done
119
128
129
+ wait
130
+
120
131
for os in Darwin Linux Windows; do
121
132
for arch in x86_64 riscv64 arm64 armv7; do
122
133
if [[ ! " ${arch} " =~ x86_64| arm64 ]] && [ " ${os} " != " Linux" ]; then
@@ -140,6 +151,8 @@ for os in Darwin Linux Windows; do
140
151
done
141
152
done
142
153
154
+ i=0
155
+
143
156
for os in Darwin Linux; do
144
157
for arch in x86_64 riscv64 arm64 armv7; do
145
158
if [[ ! " ${arch} " =~ x86_64| arm64 ]] && [ " ${os} " != " Linux" ]; then
@@ -148,11 +161,12 @@ for os in Darwin Linux; do
148
161
if [ " ${os} " == " Linux" ] && [ " ${arch} " == " arm64" ]; then
149
162
arch=" aarch64"
150
163
fi
164
+ (( i= i% NUM_JOBS)) || true ; (( i++== 0 )) && wait
151
165
dir=" ${os} /${arch} /${BASE_NAME} "
152
166
tar_context_dir=" $( dirname " ${dir} " ) "
153
167
tar_dir=" ${BASE_NAME} "
154
168
tarball=" ${BASE_NAME} -${os} -${arch} .tar.gz"
155
- tar -C " ${tar_context_dir} " -cvzf " ${tarball} " " ${tar_dir} "
169
+ tar -C " ${tar_context_dir} " -cvzf " ${tarball} " " ${tar_dir} " &
156
170
done
157
171
done
158
172
0 commit comments