Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 1978da4

Browse files
committed
Fix cgo cross compilation
Appearently our sqlite3 library uses C, so we need different gcc compilers for different platforms.
1 parent ed422b1 commit 1978da4

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

distribute.sh

+32-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env bash
22

33
name=plexStats
4+
export CGO_ENABLED=1
5+
6+
platforms=(
7+
linux-amd64 windows-amd64
8+
linux-386 windows-386
9+
linux-armv5 linux-armv6 linux-armv7
10+
#linux-armv8
11+
)
412

513
checkCommand() {
614
which "$1" >/dev/null 2>&1
@@ -16,13 +24,6 @@ checkCommand zip
1624

1725
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1826

19-
# NOTE: The build process is somewhat similar to https://github.com/syncthing/syncthing, thanks for that!
20-
platforms=(
21-
linux-amd64 windows-amd64 darwin-amd64 dragonfly-amd64 freebsd-amd64 netbsd-amd64 openbsd-amd64 solaris-amd64
22-
freebsd-386 linux-386 netbsd-386 openbsd-386 windows-386
23-
linux-arm linux-arm64 linux-ppc64 linux-ppc64le
24-
)
25-
2627
cd "$DIR"
2728
commit="$(git rev-parse --short HEAD 2>/dev/null)"
2829
date="$(date --iso-8601=seconds)"
@@ -42,18 +43,37 @@ rm -Rf ./bin/
4243
mkdir ./bin/ 2>/dev/null
4344

4445
for plat in "${platforms[@]}"; do
45-
echo Building "$plat" ...
46-
47-
GOOS="${plat%-*}"
48-
GOARCH="${plat#*-}"
46+
export GOOS="${plat%-*}"
47+
export GOARCH="${plat#*-}"
4948

5049
if [ "$GOOS" != "windows" ]; then
5150
tmpFile="/tmp/${name}/bin/${name}"
5251
else
5352
tmpFile="/tmp/${name}/bin/${name}.exe"
5453
fi
5554

56-
GOOS="${plat%-*}" GOARCH="${plat#*-}" go build -ldflags '-X main.VERSION='"$version"' -X main.BUILD_COMMIT='"$commit"' -X main.BUILD_DATE='"$date" \
55+
if [ "$CGO_ENABLED" == 1 ]; then
56+
if [ "$plat" = "windows-amd64" ]; then
57+
export CC=x86_64-w64-mingw32-gcc
58+
elif [ "$plat" = "windows-386" ]; then
59+
export CC=i686-w64-mingw32-gcc
60+
elif [ "${GOARCH%v*}" = "arm" ]; then
61+
export GOARM="${GOARCH#*v}"
62+
if [ "GOARM" = 8 ]; then
63+
unset GOARM=""
64+
export CC=armv8l-linux-gnueabihf-gcc
65+
export GOARCH="arm64"
66+
else
67+
export CC=arm-linux-gnueabihf-gcc
68+
export GOARCH="arm"
69+
fi
70+
else
71+
export CC=gcc
72+
fi
73+
fi
74+
75+
echo Building "$plat" with "$CC" ...
76+
go build -ldflags '-extld='"$CC"' -X main.VERSION='"$version"' -X main.BUILD_COMMIT='"$commit"' -X main.BUILD_DATE='"$date" \
5777
-o "$tmpFile" "$DIR"/*.go
5878

5979
if [ "$?" != 0 ]; then

0 commit comments

Comments
 (0)