-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
78 lines (66 loc) · 1.66 KB
/
build.sh
File metadata and controls
78 lines (66 loc) · 1.66 KB
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
#!/bin/bash
# Cross-compile phantom for all platforms
set -e
VERSION="0.1.0"
LDFLAGS="-s -w"
BINS="setup auth relay client ui"
OUT="dist"
rm -rf "$OUT"
platforms=(
"windows amd64 .exe"
"windows arm64 .exe"
"linux amd64 "
"linux arm64 "
"linux arm:7 "
"linux arm:6 "
"darwin amd64 "
"darwin arm64 "
"freebsd amd64 "
"freebsd arm64 "
)
for platform in "${platforms[@]}"; do
read -r os arch ext <<< "$platform"
# Handle arm versions
goarm=""
goarch="$arch"
label="$os-$arch"
if [[ "$arch" == arm:* ]]; then
goarm="${arch#arm:}"
goarch="arm"
label="$os-armv$goarm"
fi
echo " building $label..."
dir="$OUT/$label"
mkdir -p "$dir"
for bin in $BINS; do
GOOS=$os GOARCH=$goarch GOARM=$goarm CGO_ENABLED=0 \
go build -ldflags="$LDFLAGS" -o "$dir/phantom-$bin$ext" ./cmd/$bin
done
done
echo ""
echo "=== Build complete ==="
echo ""
# Show sizes
for dir in "$OUT"/*/; do
name=$(basename "$dir")
total=$(du -sh "$dir" | awk '{print $1}')
relay_size=$(ls -lh "$dir"phantom-relay* 2>/dev/null | awk '{print $5}')
printf " %-20s total: %-6s relay: %s\n" "$name" "$total" "$relay_size"
done
echo ""
echo "=== Packaging ==="
mkdir -p "$OUT/release"
for dir in "$OUT"/*/; do
name=$(basename "$dir")
[ "$name" = "release" ] && continue
archive="phantom-$VERSION-$name"
if echo "$name" | grep -q windows; then
(cd "$dir" && zip -q "../release/$archive.zip" *)
echo " $archive.zip"
else
tar -czf "$OUT/release/$archive.tar.gz" -C "$dir" .
echo " $archive.tar.gz"
fi
done
echo ""
ls -lhS "$OUT/release/"