-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathcrosscompile.sh
More file actions
executable file
·72 lines (64 loc) · 1.61 KB
/
crosscompile.sh
File metadata and controls
executable file
·72 lines (64 loc) · 1.61 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
#!/usr/bin/env bash
set -eux
VARIANT="${1:-}"
if [ -z "$VARIANT" ]; then
echo "Usage: $0 (x86_64|armv6|armv6_rpi|arm64)"
exit 1
fi
# Get the tag associated with the current commit
VERSION="$(git tag --points-at HEAD)"
VERSION="${VERSION#v}"
# Validate and map variant to compilation envs
if [ "$VARIANT" = "x86_64" ]; then
TARGET="x86-64-linux-gnu"
TRIPLET="x64-linux"
GOARCH="amd64"
GOAMD64="v1"
GOARM=""
GOCC="gcc"
elif [ "$VARIANT" = "armv6" ]; then
TARGET="arm-linux-gnueabihf"
TRIPLET="arm-linux"
GOARCH="arm"
GOAMD64=""
GOARM="6"
GOCC="arm-linux-gnueabihf-gcc"
elif [ "$VARIANT" = "armv6_rpi" ]; then
TARGET="arm-rpi-linux-gnueabihf"
TRIPLET="arm-linux-rpi"
GOARCH="arm"
GOAMD64=""
GOARM="6"
GOCC="arm-rpi-linux-gnueabihf-gcc"
elif [ "$VARIANT" = "arm64" ]; then
TARGET="aarch64-linux-gnu"
TRIPLET="arm64-linux"
GOARCH="arm64"
GOAMD64=""
GOARM=""
GOCC="aarch64-linux-gnu-gcc"
else
echo "Unsupported variant: $VARIANT"
exit 1
fi
DOCKER_IMAGE_NAME="go-librespot-build-${VARIANT}"
# Build the image for cross-compilation
docker build \
--build-arg "TARGET=$TARGET" \
--build-arg "VERSION=$VERSION" \
--build-arg "TRIPLET=$TRIPLET" \
--build-arg "GOARCH=$GOARCH" \
--build-arg "GOAMD64=$GOAMD64" \
--build-arg "GOARM=$GOARM" \
--build-arg "GOCC=$GOCC" \
-f Dockerfile.build \
-t "$DOCKER_IMAGE_NAME" \
.
# Build go-librespot using the cross-compilation image
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$PWD":/src \
"$DOCKER_IMAGE_NAME"
# Print info about the built binary
mv "./go-librespot" "./go-librespot-$VARIANT"
file "./go-librespot-$VARIANT"