forked from shenwei356/rush
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackaging.sh
More file actions
executable file
·50 lines (42 loc) · 1023 Bytes
/
Copy pathpackaging.sh
File metadata and controls
executable file
·50 lines (42 loc) · 1023 Bytes
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
#!/usr/bin/env sh
set -eu
name=rush
output_dir=binaries
targets="
linux/386
linux/amd64
linux/arm64
darwin/amd64
darwin/arm64
windows/386
windows/amd64
windows/arm64
openbsd/amd64
openbsd/arm64
freebsd/amd64
freebsd/arm64
"
staging_dir=$(mktemp -d "${TMPDIR:-/tmp}/$name-packaging.XXXXXX")
trap 'rm -rf "$staging_dir"' EXIT HUP INT TERM
mkdir -p "$output_dir"
for target in $targets; do
goos=${target%/*}
goarch=${target#*/}
extension=
if [ "$goos" = windows ]; then
extension=.exe
fi
binary="${name}${extension}"
archive="${name}_${goos}_${goarch}${extension}.tar.gz"
printf 'Building %s/%s\n' "$goos" "$goarch"
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" \
go build -trimpath -tags netgo \
-ldflags "-extldflags '-static' -w -s" \
-o "$staging_dir/$binary" .
tar -C "$staging_dir" -zcf "$output_dir/$archive" "$binary"
(
cd "$output_dir"
md5sum "$archive" > "$archive.md5.txt"
)
rm -f "$staging_dir/$binary"
done