Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for *BSD (e.g: FreeBSD) #44

Closed
prologic opened this issue Mar 21, 2022 · 22 comments
Closed

Support for *BSD (e.g: FreeBSD) #44

prologic opened this issue Mar 21, 2022 · 22 comments

Comments

@prologic
Copy link
Contributor

Can we add support for FreeBSD and perhaps other *BSD(s)?

As reported here this library doesn't work on FreeBSD due to some missing implemtnation?

Let's fix this!

@gen2brain
Copy link
Owner

Support for BSDs is added here #14, just some build tags. As I can see from your link the problem is godbus/dbus with *unixTransport does not implement transport (missing SendNullByte method), so not sure what can be done in beeep.

@prologic
Copy link
Contributor Author

@gen2brain That was my point? I can't compile on FreeBSD with your library right now. Can we fix this? I quite like beep :)

@gen2brain
Copy link
Owner

But that is not controlled by me, it is another repo, dbus?

@gen2brain
Copy link
Owner

There is also this issue godbus/dbus#315, are you cross-compiling? Can you try on actual FreeBSD?

@gen2brain
Copy link
Owner

Also, this one godbus/dbus#237, as stated there, is the only platform that uses CGO, so in order to cross-compile, you will need FreeBSD toolchain on Linux.

@gen2brain
Copy link
Owner

Ok, so it looks like there is no bug, after all, godbus/dbus just happens to use CGO on FreeBSD, so it should work if you compile it on FreeBSD (not cross-compile).

What I can do here to make it easier for you is to add e.g. nodbus build tag, and a new file that will only use notify-send/kdialog (they are currently used only as a fallback), so you can build without CGO, but it will require one of those apps to be installed in PATH and it will just call them with exec.Command. Does that help and do you need it? Not sure when will I find time to do it though.

@prologic
Copy link
Contributor Author

There is also this issue godbus/dbus#315, are you cross-compiling? Can you try on actual FreeBSD?

I was cross-compiling yes.

But the user that had a problem was not.

@prologic
Copy link
Contributor Author

There is also this issue godbus/dbus#315, are you cross-compiling? Can you try on actual FreeBSD?

Why do we depend on dbus here anyway? How is this getting pulled in?

@prologic
Copy link
Contributor Author

Ok, so it looks like there is no bug, after all, godbus/dbus just happens to use CGO on FreeBSD, so it should work if you compile it on FreeBSD (not cross-compile).

What I can do here to make it easier for you is to add e.g. nodbus build tag, and a new file that will only use notify-send/kdialog (they are currently used only as a fallback), so you can build without CGO, but it will require one of those apps to be installed in PATH and it will just call them with exec.Command. Does that help and do you need it? Not sure when will I find time to do it though.

Oh! So you're using dbus here for something? And that forces CGO to be used? If so, yes please, if we can have a CGO-less option here that would be great 👌

@prologic
Copy link
Contributor Author

@gen2brain I'm still not sure why we depend on dbus in the first place, but if we do for a good reason, is there a way we can interop with dbus without CGO? Is there a better library we can use here? I mean D-Bus has an API right?

@gen2brain
Copy link
Owner

D-Bus is used to send notifications, i.e org.freedesktop.Notifications, and it uses CGO only on FreeBSD (maybe some other *BSD, not sure). On Linux, it does not and everything is native.
I don't know the reason for that, but there must be one otherwise devs will avoid CGO usage if possible. Sometimes that is the only possible way (i.e. OpenGL, or on Darwin where syscall is not possible etc.).

@srlehn
Copy link

srlehn commented Mar 21, 2022

The cgo requirement comes from this file here: https://github.com/godbus/dbus/blob/master/transport_unixcred_freebsd.go
It would be great if someone finds a way to replace it with go.

Building with dbus on FreeBSD could be guarded with the "cgo" build tag and use a fallback like notify-send for CGO_ENABLED=0 .

@gen2brain
Copy link
Owner

Well, the first line in that file is the reason The UnixCredentials system call is currently only implemented on Linux. So BSD doesn't have one. It is not possible to find a way and replace it with Go, the BSD kernel must implement that system call.

As I said, I can add nodbus tag and copy notify_unix.go to notify_unix_nodbus.go, remove dbus code, add build tags etc. so it only uses notify-send or kdialog if first is not found in path. That can be a workaround.

The other, more complicated solution for you would be to compile FreeBSD toolchain on Linux (maybe there are ready-made Docker or scripts) and compile with something similar to this:
CC=x86_64-pc-freebsd-gcc CGO_ENABLED=1 GOOS=freebsd GOARCH=amd64 go build

@prologic
Copy link
Contributor Author

D-Bus is used to send notifications, i.e org.freedesktop.Notifications, and it uses CGO only on FreeBSD (maybe some other *BSD, not sure). On Linux, it does not and everything is native. I don't know the reason for that, but there must be one otherwise devs will avoid CGO usage if possible. Sometimes that is the only possible way (i.e. OpenGL, or on Darwin where syscall is not possible etc.).

Can we file (you should probably) upstream to the author of that dbus library to fix this? We should get native support there too!

@prologic
Copy link
Contributor Author

@gen2brain Please do this 👌 Let's not ruin a good "notification" library just because *BSD hasn't implement something Linux has had for a while 😂 cough 🤣

gen2brain added a commit that referenced this issue Mar 22, 2022
@gen2brain
Copy link
Owner

Added nodbus in 0d84a3d

@prologic
Copy link
Contributor Author

Added nodbus in 0d84a3d

Nice one! 👌 Would you mind also tagging a new release when you're done too? 🙇‍♂️

@prologic
Copy link
Contributor Author

I'm trying to see if your commit lets me cross-compile (when I do releases) but something is not working for me :/

   ⨯ release failed after 3.91s error=failed to build for freebsd_arm64: exit status 2: # github.com/godbus/dbus/v5
../../go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/transport_unix.go:52:3: cannot use t (type *unixTransport) as type transport in return argument:
        *unixTransport does not implement transport (missing SendNullByte method)
../../go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/transport_unix.go:58:3: cannot use t (type *unixTransport) as type transport in return argument:
        *unixTransport does not implement transport (missing SendNullByte method)

(⎈ |local:default)
prologic@Jamess-iMac
Wed Mar 23 23:08:15
~/Projects/saltyim
 (master) 1
$ sift nodbus
Makefile:41:                -tags "netgo static_build nodbus" \
.goreleaser.yml:12:      - -tags=netgo static_build nodbus

What am I doing wrong?

@prologic
Copy link
Contributor Author

@gen2brain
Copy link
Owner

I really don't have time to debug your project. You are probably not passing tag everywhere, for go test etc.

@prologic
Copy link
Contributor Author

I really don't have time to debug your project. You are probably not passing tag everywhere, for go test etc.

I wasn't expecting you to, and that came across as a "tad bit rude", I hope you didn't mean for that to happen 🤗 I'll work it out don't worry 😅

@gen2brain
Copy link
Owner

Of course, I didn't mean to be rude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants