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/vgo: won't compile a program that embeds a struct from another library #26198

Closed
kevinmichaelchen opened this issue Jul 3, 2018 · 4 comments
Milestone

Comments

@kevinmichaelchen
Copy link

Please answer these questions before submitting your issue. Thanks!

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

$ go version
go version go1.10.2 darwin/amd64

$ vgo version
go version go1.10.2 darwin/amd64 vgo:2018-02-20.1

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kevinchen/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/kevinchen/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2q/bsx7tl7d4tj4s6pb3gxflb2r0000gp/T/go-build691247737=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I've reproduced the issue with 2 minimal repos

Running vgo install ./... from inside vgo-embedded-struct gives the error

# github.com/kevinmichaelchen/vgo-embedded-struct
./main.go:7:2: undefined: foo.Cow

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

I think I expected it to compile, unless I'm missing something.

What did you see instead?

I saw vgo install ./... give the aforementioned error.

@AlexRouSg
Copy link
Contributor

AlexRouSg commented Jul 3, 2018

https://github.com/kevinmichaelchen/vgo-embedded-struct/blob/master/main.go

package main

import "fmt"
import "github.com/kevinmichaelchen/foo"

type A struct {
	foo.Cow
}

func main() {
	fmt.Println("vim-go")
}

https://github.com/kevinmichaelchen/foo/blob/master/foo.go

package foo

type Bar struct {
}

Cuz there is no Cow type in package foo. This has nothing to do with vgo.

@kevinmichaelchen
Copy link
Author

kevinmichaelchen commented Jul 3, 2018

@AlexRouSg Yup, my bad. Fixed it and vgo build -o woo_built_with_vgo . now works.

I was trying (unsuccessfully) to reproduce an issue in github.com/sfreiberg/gotwilio:

# works
$ go build -o woo_built_with_go .

# fails
$ vgo build -o woo_built_with_vgo .
./access_token.go:93:2: undefined: jwt.StandardClaims

@AlexRouSg
Copy link
Contributor

AlexRouSg commented Jul 3, 2018

Check your go.mod file, jwt.StandardClaims was added in v3.0.0.

As vgo doesn't allow using > v1 without a go.mod file present, and since there is a v1.0.0 tag. I suspect it defaults to v1.0.0. As legacy packages would use either v1.0.0 or the pseudo version v0.0.0-date-hash, since v1.0.0 is "newer" than v0.0.0 it uses that.

I feel like I've seen a issue to fix the order, but I cannot find it. So if using the latest vgo is still showing the same behavior then what you can do is either get the package maintainer of github.com/dgrijalva/jwt-go to add a go.mod file and change the import paths of github.com/sfreiberg/gotwilio to use github.com/dgrijalva/jwt-go/v3 or change your go.mod file to use the v0.0.0-date-hash syntax.

@FiloSottile FiloSottile changed the title vgo won't compile a program that embeds a struct from another library x/vgo: won't compile a program that embeds a struct from another library Jul 3, 2018
@gopherbot gopherbot added this to the vgo milestone Jul 3, 2018
@kevinmichaelchen
Copy link
Author

@AlexRouSg thanks, so this has nothing to do with vgo. I was just had wrong configurations.

This is what I ended up with:

require (
    github.com/dgrijalva/jwt-go v0.0.0-20180308231308-06ea1031745c
)

@golang golang locked and limited conversation to collaborators Jul 3, 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