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

x/tools/cmd/stringer: tries to check imported cgo package and fails #27010

Closed
jclc opened this issue Aug 15, 2018 · 2 comments
Closed

x/tools/cmd/stringer: tries to check imported cgo package and fails #27010

jclc opened this issue Aug 15, 2018 · 2 comments

Comments

@jclc
Copy link

jclc commented Aug 15, 2018

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

go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN="/home/vhns/projects/go/bin"
GOCACHE="/home/vhns/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/vhns/projects/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build621405833=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Added a go:generate stringer pragma for an enum. The same package includes imports to vulkan-go.

import (
	"github.com/vulkan-go/glfw/v3.3/glfw"
	vk "github.com/vulkan-go/vulkan"
)
/* ... */
type Action uint

//go:generate stringer -type=Action

const (
	Exit Action = iota
	OpenMenu
)

What did you expect to see?

An output file named action_string.go.

What did you see instead?

$  go generate ./...
stringer: checking package: input.go:8:2: could not import gitlab.com/jclc/game/graphics (type-checking package "gitlab.com/jclc/game/graphics" failed (/home/vhns/projects/go/src/gitlab.com/jclc/game/graphics/globals.go:8:5: could not import github.com/vulkan-go/vulkan (type-checking package "gitlab.com/jclc/game/vendor/github.com/vulkan-go/vulkan" failed (/home/vhns/projects/go/src/gitlab.com/jclc/game/vendor/github.com/vulkan-go/vulkan/vk_null64.go:11:28: cannot convert nil (untyped nil value) to Semaphore))))
input/actions.go:58: running "stringer": exit status 1

The type Semaphore is a C type in this context. The package itself builds and works fine.

@gopherbot gopherbot added this to the Unreleased milestone Aug 15, 2018
@adamdecaf
Copy link
Contributor

adamdecaf commented Aug 22, 2018

@jclc Could this be a problem with the vulkan project? I noticed they're initializing cgo values to nil, which isn't what the docs say:

vulkan source:

	// NullHandle defines a platform-specfic NULL handle.
	NullHandle unsafe.Pointer = nil
	// NullSemaphore defines a platform-specfic NULL Semaphore.
	NullSemaphore Semaphore = nil
	// NullFence defines a platform-specfic NULL Fence.
	NullFence Fence = nil

Because of this change, values of the affected types need to be zero-initialized with the constant 0 instead of the constant nil. Go 1.10 provides gofix modules to help with that rewrite:

go tool fix -r cftype <pkg>
go tool fix -r jni <pkg>

https://tip.golang.org/doc/go1.10#cgo

@jclc
Copy link
Author

jclc commented Aug 22, 2018

I see, so go build doesn't actually check if cgo values are valid? I'll make a ticket on the vulkan project.

@jclc jclc closed this as completed Aug 25, 2018
@golang golang locked and limited conversation to collaborators Aug 25, 2019
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

3 participants