-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·35 lines (30 loc) · 916 Bytes
/
Copy pathbuild.sh
File metadata and controls
executable file
·35 lines (30 loc) · 916 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
#!/bin/bash
set -euo pipefail
VERSION="${1:-v0.1}"
BINARY="${BINARY:-amap}"
GOOS="${GOOS:-linux}"
GOARCH="${GOARCH:-amd64}"
echo "=== AstraMap static release build ==="
echo "Version: ${VERSION}"
echo "Target: ${GOOS}/${GOARCH}"
echo "Output: ${BINARY}"
CC=musl-gcc \
CGO_ENABLED=1 \
GOOS="${GOOS}" \
GOARCH="${GOARCH}" \
go build \
-tags "netgo osusergo" \
-ldflags "-s -w -extldflags '-static' -X main.version=${VERSION}" \
-o "${BINARY}" \
./cmd/amap
FILE_OUTPUT="$(file "${BINARY}")"
printf '%s\n' "${FILE_OUTPUT}"
LDD_OUTPUT="$(ldd "${BINARY}" 2>&1 || true)"
if printf '%s\n' "${FILE_OUTPUT}" | grep -q "statically linked" &&
! printf '%s\n' "${LDD_OUTPUT}" | grep -Eq "=>|ld-linux|libc\\.so"; then
echo "static link verified: ${BINARY} has no glibc runtime dependency"
else
echo "static link verification failed: ${BINARY} is dynamically linked" >&2
printf '%s\n' "${LDD_OUTPUT}" >&2
exit 1
fi