Skip to content

Commit 330a231

Browse files
authored
multi-arch build script and version fixes (#435)
1 parent 498baa3 commit 330a231

File tree

3 files changed

+86
-9
lines changed

3 files changed

+86
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# Generated binaries
1313
/bin/
14+
/release-bin/
1415

1516
# Test binary, built with `go test -c`
1617
*.test

cliutil/utils.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,42 @@ func GetVersion() string {
9999
return "unknown-version"
100100
}
101101

102-
commitHash := "???????"
103-
dirty := ""
102+
commitHash := ""
103+
sourcesModified := false
104104

105105
for _, setting := range info.Settings {
106106
switch setting.Key {
107107
case "vcs.revision":
108108
commitHash = setting.Value
109109
case "vcs.modified":
110110
if setting.Value == "true" {
111-
dirty = "-dirty"
111+
sourcesModified = true
112112
}
113113
}
114114
}
115115

116-
return fmt.Sprintf("%s %.7s%s-%s",
117-
info.Main.Version, // " (devel)" unless passing a git tagged version to `go install`
118-
commitHash, // 7 bytes is what "git rev-parse --short HEAD" returns
119-
dirty, // add "-dirty" to commit hash if repo was not clean
120-
info.GoVersion,
121-
)
116+
var version strings.Builder
117+
118+
// The first part a go.mod style version if using "go install" directly with
119+
// github. If installing from locally checked out source, the string will be
120+
// "(devel)".
121+
version.WriteString(info.Main.Version)
122+
version.WriteByte(' ')
123+
124+
// The commit hash will be present if installing from locally checked out
125+
// sources, or empty if installing directly from the repo's github URL.
126+
if commitHash != "" {
127+
// 7 bytes is what "git rev-parse --short HEAD" returns
128+
version.WriteString(fmt.Sprintf("%.7s", commitHash))
129+
if sourcesModified {
130+
version.WriteString("-dirty")
131+
}
132+
}
133+
134+
version.WriteByte('-')
135+
version.WriteString(info.GoVersion)
136+
137+
return version.String()
122138
}
123139

124140
// ReadUnsignedDecimalFlag reads a string flag and parses it into an *apd.Decimal.

scripts/release-build.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
# Fail script on any error (do not change)
4+
set -e
5+
6+
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
7+
cd "${PROJECT_ROOT}"
8+
9+
# Make sure no one is sourcing the script, as we export variables
10+
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
11+
echo "Execute ${BASH_SOURCE[0]} instead of souring it"
12+
exit 1
13+
fi
14+
15+
version="HEAD" # use "latest" for most recent tagged release
16+
install_targets=(
17+
"github.com/athanorlabs/atomic-swap/cmd/swapd@${version}"
18+
"github.com/athanorlabs/atomic-swap/cmd/swapcli@${version}"
19+
"github.com/athanorlabs/atomic-swap/cmd/bootnode@${version}"
20+
)
21+
22+
# turn on echo
23+
set -x
24+
25+
dest_dir=release-bin
26+
rm -rf "${dest_dir}"
27+
mkdir "${dest_dir}"
28+
29+
# Note: We don't bother with static builds (larger binaries) as swapd depends on
30+
# a local monero-wallet-rpc binary and all releases of monero-wallet-rpc depend
31+
# on glibc.
32+
unset CGO_ENABLED
33+
34+
# Unfortunately, GOBIN can't be set when doing cross platform builds and
35+
# go install doesn't take an -o flag:
36+
# https://github.com/golang/go/issues/57485
37+
# We are inside a go module project right now and we'll confuse tooling
38+
# if we put the GOPATH inside of the project. We are using "go install",
39+
# so nothing will go wrong even if a go.mod exists at the top of /tmp.
40+
build_dir="$(mktemp -d /tmp/release-build-XXXXXXXXXX)"
41+
42+
for os in linux darwin; do
43+
for arch in amd64 arm64; do
44+
GOPATH="${build_dir}" GOOS="${os}" GOARCH="${arch}" \
45+
go install -tags=prod "${install_targets[@]}"
46+
from_dir="${build_dir}/bin/${os}_${arch}"
47+
to_dir="${dest_dir}/${os/darwin/macos}-${arch/amd64/x64}"
48+
if [[ -d "${from_dir}" ]]; then
49+
# non-native binaries
50+
mv "${from_dir}" "${to_dir}"
51+
else
52+
# native binaries
53+
mkdir "${to_dir}"
54+
mv "${build_dir}/bin/"* "${to_dir}"
55+
fi
56+
done
57+
done
58+
59+
chmod -R u+w "${build_dir}"
60+
rm -rf "${build_dir}"

0 commit comments

Comments
 (0)