Skip to content

Commit 9a5e9f0

Browse files
committed
Compile dynlinked and static binaries for different platforms
1 parent 81a23c2 commit 9a5e9f0

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

scripts/dist.sh

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,33 @@ fi
3030
# docker build -t ethermint/ethermint-builder scripts/ethermint-builder/
3131
# docker run --rm -v "$(pwd)":/go/src/github.com/tendermint/ethermint ethermint/ethermint-builder ./scripts/dist_build.sh
3232
# Get the git commit
33-
GIT_COMMIT="$(git rev-parse --short HEAD)"
33+
GIT_COMMIT="$(git rev-parse HEAD)"
3434
GIT_DESCRIBE="$(git describe --tags --always)"
3535
GIT_IMPORT="github.com/tendermint/ethermint/version"
3636

3737
# Determine the arch/os combos we're building for
3838
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
3939
XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"}
40+
4041
IGNORE=("darwin/arm solaris/amd64 freebsd/amd64")
42+
NON_STATIC=("darwin/386 darwin/amd64")
43+
4144
TARGETS=""
45+
NON_STATIC_TARGETS=""
46+
4247
for os in $XC_OS; do
4348
for arch in $XC_ARCH; do
4449
target="$os/$arch"
4550

4651
case ${IGNORE[@]} in *$target*) continue;; esac
47-
TARGETS="$os/$arch,$TARGETS"
52+
case ${NON_STATIC[@]} in *$target*)
53+
NON_STATIC_TARGETS="$target,$NON_STATIC_TARGETS"
54+
continue;;
55+
esac
56+
57+
TARGETS="$target,$TARGETS"
4858
done
4959
done
50-
# Remove last comma
51-
TARGETS=${TARGETS::${#TARGETS}-1}
5260

5361
# Delete the old dir
5462
echo "==> Removing old directory..."
@@ -62,13 +70,27 @@ make tools
6270
make get_vendor_deps
6371

6472
# Build!
65-
echo "==> Building..."
66-
xgo -go="latest" \
73+
if [ ! -z "$TARGETS" ]; then
74+
echo "==> Building Static Binaries..."
75+
TARGETS=${TARGETS::${#TARGETS}-1}
76+
xgo -go="latest" \
6777
-targets="${TARGETS}" \
68-
-ldflags "-X ${GIT_IMPORT}.GitCommit='${GIT_COMMIT}' -X ${GIT_IMPORT}.GitDescribe='${GIT_DESCRIBE}'" \
69-
-dest "build/pkg" \
70-
-tags="${BUILD_TAGS}" \
71-
github.com/tendermint/ethermint/cmd/ethermint
78+
-ldflags "-extldflags '-static' -X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT} -X ${GIT_IMPORT}.GitDescribe=${GIT_DESCRIBE}" \
79+
-dest "build/pkg" \
80+
-tags="${BUILD_TAGS}" \
81+
${DIR}/cmd/ethermint
82+
fi
83+
84+
if [ ! -z "$NON_STATIC_TARGETS" ]; then
85+
echo "==> Building Non-Static Binaries..."
86+
NON_STATIC_TARGETS=${NON_STATIC_TARGETS::${#NON_STATIC_TARGETS}-1}
87+
xgo -go="latest" \
88+
-targets="${NON_STATIC_TARGETS}" \
89+
-ldflags "-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT} -X ${GIT_IMPORT}.GitDescribe=${GIT_DESCRIBE}" \
90+
-dest "build/pkg" \
91+
-tags="${BUILD_TAGS}" \
92+
${DIR}/cmd/ethermint
93+
fi
7294

7395
echo "==> Packaging..."
7496
for FILE in $(ls ./build/pkg); do

0 commit comments

Comments
 (0)