zalando / go-keyring

Cross-platform keyring interface for Go
MIT License
882 stars 86 forks source link

Build issue in 0.2.0 #73

Closed jefferai closed 2 years ago

jefferai commented 2 years ago

In 0.2.0, the file keyring_linux.go was renamed to keyring_unix.go to enable dbus on more platforms.

Unfortunately, the dbus implementation in godbus/dbus requires cgo for both dragonflybsd and freebsd. This means that if you are building with cgo disabled to build static binaries or for easier cross-compilation, upgrading to v0.2.0 results in build failures, with no way to disable this functionality.

One option would be to put a build tag constraint on cgo in keyring_unix.go to not compile in the code if cgo is disabled. That would probably require a copy of the file to be available for non-dragonflybsd/freebsd platforms that still compiles if cgo is disabled.

mikkeloscar commented 2 years ago

@jefferai What are the flags used for compiling? I'm trying to replicate the issue, but fail with this simple example:

package main

import (
    "log"

    "github.com/zalando/go-keyring"
)

func main() {
    service := "my-app"
    user := "anon"
    password := "secret"

    // set password
    err := keyring.Set(service, user, password)
    if err != nil {
        log.Fatal(err)
    }

    // get password
    secret, err := keyring.Get(service, user)
    if err != nil {
        log.Fatal(err)
    }

    log.Println(secret)
}
CGO_ENABLED=0 GOOS=linux go build
file go-keyring
go-keyring: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=3YHhCPmk4UlD9_lXoVn1/N8KAugbp9D6MWwgxw4DH/ztCw71yTYMPVgjk8hI8h/yBdWR56JPIAmab6xbFtI, not stripped
jefferai commented 2 years ago

Try GOOS=freebsd GOARCH=amd64

Probably only GOOS is needed though (and keeping CGO_ENABLED=0)

mikkeloscar commented 2 years ago

@jefferai New version v0.2.1 addresses the issue.

jefferai commented 2 years ago

Thank you!