Skip to content

affected/package: go command #58672

Closed
Closed
@jsoneaday

Description

@jsoneaday

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions