Skip to content

Commit 2d735b5

Browse files
committed
Make release parallel
1 parent c040b72 commit 2d735b5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

make/buf/scripts/release.bash

+20-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ RELEASE_DOCKER_IMAGE="bufrelease-tag"
88
DIR="$(CDPATH= cd "$(dirname "${0}")/../../.." && pwd)"
99
cd "${DIR}"
1010

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+
1117
fail() {
1218
echo "error: $@" >&2
1319
exit 1
@@ -84,6 +90,8 @@ rm -rf "${RELEASE_DIR}"
8490
mkdir -p "${RELEASE_DIR}"
8591
cd "${RELEASE_DIR}"
8692

93+
i=0
94+
8795
for os in Darwin Linux Windows; do
8896
for arch in x86_64 riscv64 arm64 armv7; do
8997
# 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
105113
if [[ ! "${arch}" =~ x86_64|arm64 ]] && [ "${os}" != "Linux" ]; then
106114
continue
107115
fi
116+
((i=i%NUM_JOBS)) || true; ((i++==0)) && wait
108117
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"
111119
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
114121
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}" &
116125
done
117126
done
118127
done
119128

129+
wait
130+
120131
for os in Darwin Linux Windows; do
121132
for arch in x86_64 riscv64 arm64 armv7; do
122133
if [[ ! "${arch}" =~ x86_64|arm64 ]] && [ "${os}" != "Linux" ]; then
@@ -140,6 +151,8 @@ for os in Darwin Linux Windows; do
140151
done
141152
done
142153

154+
i=0
155+
143156
for os in Darwin Linux; do
144157
for arch in x86_64 riscv64 arm64 armv7; do
145158
if [[ ! "${arch}" =~ x86_64|arm64 ]] && [ "${os}" != "Linux" ]; then
@@ -148,11 +161,12 @@ for os in Darwin Linux; do
148161
if [ "${os}" == "Linux" ] && [ "${arch}" == "arm64" ]; then
149162
arch="aarch64"
150163
fi
164+
((i=i%NUM_JOBS)) || true; ((i++==0)) && wait
151165
dir="${os}/${arch}/${BASE_NAME}"
152166
tar_context_dir="$(dirname "${dir}")"
153167
tar_dir="${BASE_NAME}"
154168
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}" &
156170
done
157171
done
158172

0 commit comments

Comments
 (0)