joshuar / go-hass-agent

A Home Assistant, native app for desktop/laptop devices.
MIT License
128 stars 9 forks source link

[FEATURE REQUEST] armhf architecture #191

Open rapiertg opened 2 months ago

rapiertg commented 2 months ago

Is your feature request related to a problem? Please describe. There are some devices like rpi 2 prior to 1.2v with armhf processor architecture, unfortunatelly go-hass-agent cannot be installed with either arm or arm64 package there.

Describe the solution you'd like I see both arm and arm64 so maybe enabling armhf would be possible?

joshuar commented 2 months ago

Hey thanks for trying out Go Hass Agent. Yep, this should be possible. Currently, the arm build targets armv7, is the rpi 2 you are using armv6 or something else?

If you are unsure which arm revision it is running, if you can install go, you can run go env and see what the values of GOARCH and GOARM are?

rapiertg commented 2 months ago

Hey, according to go env it shows:

GOARCH="arm"
GOARM="6"

Some more info from uname -a: Linux raspberrypi 6.6.31+rpt-rpi-v7 #1 SMP Raspbian 1:6.6.31-1+rpt1 (2024-05-29) armv7l GNU/Linux

let me know if you need anything else

joshuar commented 2 months ago

Brilliant, thank you. So I should be able to add binaries and packages for this architecture for subsequent releases!

joshuar commented 2 months ago

Hey @rapiertg, packages will now be built for both armv6 and armv7 architectures. You can try out the very latest build for armv6, that will likely become the next release, from the artifacts here. That is a zip file that contains all the packages for armv6, please extract and use the one that is most appropriate for your needs.

frostworx commented 1 month ago

Hello,

first of all, thank you very much for this very promising (and well documented) project!

I have a similar, but not identical problem. I hope it is ok, to recycle this open issue instead of opening a new one. I received an OnePlus6 (armv8) device yesterday and installed postmarketos on it (https://wiki.postmarketos.org/wiki/OnePlus_6_(oneplus-enchilada))

postmarketos is based on alpine and alpine is using musl instead of glibc. therefore, the provided aarm64 binary is incompatible:

Error relocating /usr/local/bin/go-hass-agent: __vsnprintf_chk: symbol not found
Error relocating /usr/local/bin/go-hass-agent: __fprintf_chk: symbol not found
Error relocating /usr/local/bin/go-hass-agent: __vfprintf_chk: symbol not found
Error relocating /usr/local/bin/go-hass-agent: __memcpy_chk: symbol not found
Error relocating /usr/local/bin/go-hass-agent: __sprintf_chk: symbol not found
Error relocating /usr/local/bin/go-hass-agent: __snprintf_chk: symbol not found

(installing gcompat fixed the missing ld-linux-aarch64.so but not the undefined references)

so I wanted to build the project from source, but it stops with

package github.com/joshuar/go-hass-agent
    imports github.com/joshuar/go-hass-agent/internal/agent
    imports github.com/joshuar/go-hass-agent/internal/agent/ui/fyneUI
    imports fyne.io/fyne/v2/app
    imports fyne.io/fyne/v2/internal/driver/glfw
    imports fyne.io/fyne/v2/internal/driver/common
    imports fyne.io/fyne/v2/internal/painter/gl
    imports github.com/go-gl/gl/v3.1/gles2: build constraints exclude all Go files in /root/go/pkg/mod/github.com/go-gl/gl@v0.0.0-20211210172815-726fda9656d6/v3.1/gles2

I don't know anything about go, but go clean -modcache which was suggested somewhere with a very similar error didn't fix this.

# go env | grep GOA

only returns

GOARCH='arm64'

GOARM does not exist

# uname -m
aarch64

is not very specific as well :)

I wanted to work around the issue using docker, but no dice:

 # docker pull ghcr.io/joshuar/go-hass-agent:latest
latest: Pulling from joshuar/go-hass-agent
no matching manifest for linux/arm64/v8 in the manifest list entries

Would be great if you have some hints.

joshuar commented 1 month ago

Thanks for the nice comments. I hope you are getting some use out of the project!

So for your issues, I think there is a path through...

First up, the UI part of the agent uses Fyne, which requires CGO, so first step is you'll need to set CGO_ENABLED (i.e., export CGO_ENABLED=1) before running any go build. But you'll also need to install the distro dependencies of Fyne (see Getting Started in the Fyne docs). For alpine it looks like the following will install all the necessary packages:

sudo apk add go gcc libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev linux-headers mesa-dev

There is also a couple of go tools that will need to be installed:

go install golang.org/x/tools/cmd/stringer@latest
go install golang.org/x/text/cmd/gotext@latest

Once the distro libraries and go tools are installed and CGO is enabled, you'll need to run go generate ./... before go build. But hopefully at this point it should build 🤞

I was looking at whether I can base the containers off of Alpine...I would be interested to hear how you get on with this. I'm also interested to know how well it works on something like postmarketOS. I haven't considered that use case so it would be interesting to see what works and what doesn't!

frostworx commented 1 month ago

thank you very much for taking the time to explain the cgo problem :) to be honest I'm no longer that sure if the project helps with my specific case (I'd like to send custom sensors from a separate network while traveling to my home home-assistant through nabu casa. meanwhile I found out the simply using webhooks is probably the easiest approach)

anyway I'll try to create a postmarkedos binary shortly, and report back my findings.

just installing go-hass-agent-bin from AUR on my main regular machine (thx, author, just upvoted) :)

frostworx commented 1 month ago

unfortunately

go generate ./...

fails with moq and stringer not being installed. moq upstream is https://github.com/matryer/moq, go get github.com/matryer/moq didn't help :) haven't searched for stringer, likely some go tool as well :)

joshuar commented 1 month ago

Oh sorry, my bad, these are additional Go command-line tools I use during development. Moq allows me to make mock objects for testing and stringer generates some string variables easily. You can install both of those with a slightly different command-line:

go install golang.org/x/tools/cmd/stringer@latest
go install golang.org/x/text/cmd/gotext@latest # also needed, mentioned earlier
go install github.com/matryer/moq@0bf2e8a069abaefdfd07e4902d204441cca17298
frostworx commented 1 month ago

thanks for the heads-up. meanwhile I re-flashed my postmarket installation and will go on a roadtrip starting from tomorrow, so I won't be able to test too quickly.

frostworx commented 1 month ago

I'm back and already tested the build process again from scratch.

An additional

apk add musl-dev

was required to resolve the missing stdlib.h header required by

go install golang.org/x/text/cmd/gotext@latest

but everything else worked fine. The resulting binary was executable and opened a window. I haven't tested further functionality on this device, but I'm sure it works as expected.

Thank you for the pointers for compiling it for musl and keep up your great work! :)

frostworx commented 4 weeks ago

to summarize:

sudo apk add go gcc libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev linux-headers mesa-dev musl-dev git
go install golang.org/x/tools/cmd/stringer@latest
go install golang.org/x/text/cmd/gotext@latest
go install github.com/matryer/moq@0bf2e8a069abaefdfd07e4902d204441cca17298

git clone https://github.com/joshuar/go-hass-agent.git
cd go-hass-agent
export CGO_ENABLED=1
export PATH=$PATH:~/go/bin/
go generate ./...
go build

generates a working binary on postmarkedos/alpine the (stripped ~ 28mb) binary go-hass-agent binary copied to /usr/local/bin/

registered fine on my home assistant server through nabu casa and provides 117 entities ootb.

joshuar commented 4 weeks ago

Thank you for all these details and it is great to know if works on this device + architecture combo and with Alpine Linux! That's awesome. I may switch the container builds to use Alpine as it further saves some space over using Ubuntu and in doing so, update the mage build framework to support building on either Ubuntu or Alpine, which would reduce the steps needed.

frostworx commented 4 weeks ago

Nice :) Thank you very much for your awesome project and keep up your great work!