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

affected/package: go command #58672

Closed
jsoneaday opened this issue Feb 24, 2023 · 0 comments
Closed

affected/package: go command #58672

jsoneaday opened this issue Feb 24, 2023 · 0 comments

Comments

@jsoneaday
Copy link

jsoneaday commented Feb 24, 2023

What version of Go are you using (go version)? 1.20.1

Does this issue reproduce with the latest release? Yes

What operating system and processor architecture are you using (go env)?

GO111MODULE=""
GOARCH="amd64" // note also tried on arm64
GOBIN=""
GOCACHE="/Users/davidchoi/Library/Caches/go-build"
GOENV="/Users/davidchoi/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/davidchoi/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/davidchoi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3l/kkjsj0695q9_n194jp473bjh0000gn/T/go-build2986864533=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. I have a project with a single go file in it.
package main
import "C"
import (
	"fmt"

	"github.com/99designs/keyring"
)
func Get() {
	ring, _ := keyring.Open(keyring.Config{
		ServiceName: "example",
	})
	_ = ring.Set(keyring.Item{
		Key:  "foo",
		Data: []byte("secret-bar"),
	})
	i, _ := ring.Get("foo")

	fmt.Printf("%s", i.Data)
}
func main() {}
  1. This project imports several other dependencies like:
    github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
    github.com/99designs/keyring v1.2.2
    github.com/danieljoos/wincred v1.1.2 // indirect
    github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
    github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
    github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
    github.com/mtibben/percent v0.2.1 // indirect
    golang.org/x/sys v0.5.0 // indirect
    golang.org/x/term v0.5.0 // indirect
  2. If I build with this command go build -trimpath -buildmode=c-shared -ldflags '-w -s -extldflags "-lresolv"' -o keyring.so main.go it builds without error, but it does not generate a C header file and so I cannot use it.
  3. However if I switch to a main file that does not have these external dependencies like this simple file, the exact same build command generates both the .so file and a header.
package main
import "C"
import (
	"sort"
	"sync"
)
var count int
var mtx sync.Mutex
//export Add
func Add(a, b int) int {
	return a + b
}
//export Sort
func Sort(vals []int) {
	sort.Ints(vals)
}
func main() {}

What did you expect to see?

I expected item 4 to generate a C header too

What did you see instead?

Only a .so file was generated

@golang golang locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants