devgianlu / go-librespot

Yet another open source Spotify client, written in Go.
GNU General Public License v3.0
52 stars 7 forks source link

Help requested: building on raspbian bullseye #20

Closed txoof closed 5 months ago

txoof commented 5 months ago

I'm rather new to GO and trying to build go-librespot on Raspbian Bullseye. I'm a little stuck with the building and hope that someone can point me in the right direction.

I've attempted to build using the default golang package (go 1.19), but I get the message:

audio/decryptor.go:31:17: undefined: bytes.Clone
note: module requires Go 1.20

Unfortunately, the debian bookworm-backports 1.21 version of Go isn't available for RaspberryPi OS.

Attempting to build from go 1.22.0-linux-armv6l obtained from go.dev aborts with the message below. After some googling, I gather this has something to do with cross compiling, but I'm a bit lost as to where to start with resolving this.

go: downloading golang.org/x/net v0.11.0
# runtime/cgo
gcc: error: unrecognized command-line option '-marm'

Any suggestions you all can offer are greatly appreciated.

For good measure:

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

EDIT:

It looks like the env variable CGO_ENABLED is playing a part in this, but disabling it causes this:

$ CGO_ENABLED=0 go build -o go-librespot-daemon ./cmd/daemon                                                              (master) /
# go-librespot/output
output/output.go:8:3: undefined: output
output/output.go:45:14: undefined: newOutput
# go-librespot/audio
audio/metadata.go:51:23: undefined: vorbis.OggSyncState
audio/metadata.go:52:9: undefined: vorbis.OggSyncInit
audio/metadata.go:55:10: undefined: vorbis.OggSyncClear
audio/metadata.go:62:16: undefined: vorbis.OggSyncBuffer
audio/metadata.go:64:9: undefined: vorbis.OggSyncWrote
audio/metadata.go:69:18: undefined: vorbis.OggPage
audio/metadata.go:70:19: undefined: vorbis.OggSyncPageout
audio/metadata.go:74:25: undefined: vorbis.OggStreamState
audio/metadata.go:75:9: undefined: vorbis.OggStreamInit
audio/metadata.go:75:44: undefined: vorbis.OggPageSerialno
audio/metadata.go:75:44: too many errors
txoof commented 5 months ago

I've resolved this issue, but I'm not entirely sure why it works. Can anyone explain why this works?

env GOARCH=arm64 GOOS=linux CGO_ENABLED=1 go build -o go-librespot-daemon ./cmd/daemon
devgianlu commented 5 months ago

Thank you for your interestin go-librespot!

The CGO_ENABLED flag set to 1 is required for building the code interfaces with the ALSA C library and therefore cannot be disabled.

With GOOS and GOARCH you are telling the compiler which operating system and architecture to target.

For additional insigth you can have a look at how the pre-made binaries are built: https://github.com/devgianlu/go-librespot/blob/0774e632a8dfa14c9ac248586d3e8f57afd8a512/.github/workflows/release.yml

txoof commented 5 months ago

@devgianlu Thanks for that explanation. I've got it working properly now.