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

Failing to install sqlc v1.5.0 / latest #654

Closed
brunoluiz opened this issue Aug 6, 2020 · 13 comments · Fixed by #665 or #744
Closed

Failing to install sqlc v1.5.0 / latest #654

brunoluiz opened this issue Aug 6, 2020 · 13 comments · Fixed by #665 or #744
Labels
bug Something isn't working documentation Improvements or additions to documentation upstream Issue is caused by a dependency

Comments

@brunoluiz
Copy link

brunoluiz commented Aug 6, 2020

Issue

go install github.com/kyleconroy/sqlc/cmd/sqlc seems to be failing due to dolphin changes

How to reproduce

As there are some C dependencies in sqlc, we have the following target on our Makefile:

install-generators:
	# more tools...
	tmp_dir=sqlc-$(shell date +'%s') && mkdir -p /tmp/$$tmp_dir && cd /tmp/$$tmp_dir && go mod init tmp && GO11MODULE=on go install github.com/kyleconroy/sqlc/cmd/sqlc && cd - # it has C dependencies that would be a headache using go mod vendor

But now it crashes with the following error:

go: creating new go.mod: module tmp
go: finding module for package github.com/kyleconroy/sqlc/cmd/sqlc
go: found github.com/kyleconroy/sqlc/cmd/sqlc in github.com/kyleconroy/sqlc v1.5.0
# github.com/kyleconroy/sqlc/internal/engine/dolphin
/Users/brunosilva/go/pkg/mod/github.com/kyleconroy/sqlc@v1.5.0/internal/engine/dolphin/convert.go:197:13: n.Schema undefined (type *"github.com/pingcap/parser/ast".FuncCallExpr has no field or method Schema)
/Users/brunosilva/go/pkg/mod/github.com/kyleconroy/sqlc@v1.5.0/internal/engine/dolphin/convert.go:216:14: n.Offset undefined (type *"github.com/pingcap/parser/ast".FuncCallExpr has no field or method Offset)

Solution for now:

We've changed the script to download a specific version for now

install-generators:
	# more tools...
	tmp_dir=sqlc-$(shell date +'%s') && mkdir -p /tmp/$$tmp_dir && cd /tmp/$$tmp_dir && go mod init tmp && go mod edit -require github.com/kyleconroy/sqlc@v1.4.0 && go install github.com/kyleconroy/sqlc/cmd/sqlc && cd - # it has C dependencies that would be a headache using go mod vendor

EDIT: Above solution as a bash/shell script (above one is for Makefile):

tmp_dir=sqlc-$(date +'%s') && \
mkdir -p /tmp/$tmp_dir && \
cd /tmp/$tmp_dir && \
go mod init tmp && \
go mod edit -replace github.com/pingcap/parser=github.com/kyleconroy/parser@v0.0.0-20200728181224-b006e3bf3ed9 && \
go get github.com/kyleconroy/sqlc/cmd/sqlc@v1.5.0 && \
cd - # it has C dependencies that would be a headache using go mod vendor
@brunoluiz brunoluiz changed the title Failing to install sqlc v1.5.0 Failing to install sqlc v1.5.0 / latest Aug 6, 2020
@kyleconroy
Copy link
Collaborator

Hmm, not sure why that's failing. What version of Go are you using?

I will say that installing via the go tool is my least recommended method, as things like this tend to crop up from time to time, especially because sqlc depends on packages that use cgo.

@brunoluiz
Copy link
Author

brunoluiz commented Aug 7, 2020

My go version:

go version go1.14.3 darwin/amd64

I would use through brew, but I run generators on our CI (linux) and most people use Macs for development. Hence why we used the go install as mentioned.

I had a look today and it seems it is due to this line in go.mod:

replace github.com/pingcap/parser => github.com/kyleconroy/parser v0.0.0-20200728181224-b006e3bf3ed9

If I change add to the go.mod on the tmp folder it works fine

The Makefile target looks like this now:

	@tmp_dir=sqlc-$(shell date +'%s') && \
		mkdir -p /tmp/$$tmp_dir && \
		cd /tmp/$$tmp_dir && \
		go mod init tmp && \
		go mod edit -replace github.com/pingcap/parser=github.com/kyleconroy/parser@v0.0.0-20200728181224-b006e3bf3ed9 && \
		go get github.com/kyleconroy/sqlc/cmd/sqlc@v1.5.0 && \
		cd - # it has C dependencies that would be a headache using go mod vendor

@Ximik
Copy link

Ximik commented Aug 7, 2020

Hey. Have the same issue when trying to update to 1.5.0.


# github.com/kyleconroy/sqlc/internal/engine/dolphin
../../go/pkg/mod/github.com/kyleconroy/sqlc@v1.5.0/internal/engine/dolphin/convert.go:197:13: n.Schema undefined (type *"github.com/pingcap/parser/ast".FuncCallExpr has no field or method Schema)
../../go/pkg/mod/github.com/kyleconroy/sqlc@v1.5.0/internal/engine/dolphin/convert.go:216:14: n.Offset undefined (type *"github.com/pingcap/parser/ast".FuncCallExpr has no field or method Offset)

I've also tried to clean up my GOSRC, which hasn't helped.

go version go1.14.2 linux/amd64
Linux 4.19.44-gentoo

@brunoluiz
Copy link
Author

@Ximik Are you using just go get github.com/kyleconroy/sqlc/cmd/sqlc? If so, I guess you might need to create a temp go module and then add the mod replacement to make it work properly.

The following should work from the terminal:

tmp_dir=sqlc-$(date +'%s') && \
mkdir -p /tmp/$tmp_dir && \
cd /tmp/$tmp_dir && \
go mod init tmp && \
go mod edit -replace github.com/pingcap/parser=github.com/kyleconroy/parser@v0.0.0-20200728181224-b006e3bf3ed9 && \
go get github.com/kyleconroy/sqlc/cmd/sqlc@v1.5.0 && \
cd - # it has C dependencies that would be a headache using go mod vendor

#654 (comment)

@kyleconroy
Copy link
Collaborator

Whoops, I didn't mean to close this when merging #665.

The problem is that the replace directive only applies inside the sqlc project itself. When you try to bring it in, you need to add the replace directive. Sadly, the replace directive is needed until I get my changes to the MySQL parser merged upstream.

@kyleconroy kyleconroy reopened this Aug 19, 2020
@chaitan94
Copy link

I can confirm the issue. I faced the same:

$ go install github.com/kyleconroy/sqlc/cmd/sqlc
go: finding module for package github.com/kyleconroy/sqlc/cmd/sqlc
go: found github.com/kyleconroy/sqlc/cmd/sqlc in github.com/kyleconroy/sqlc v1.5.0
# github.com/kyleconroy/sqlc/internal/engine/dolphin
/home/kc/go/pkg/mod/github.com/kyleconroy/sqlc@v1.5.0/internal/engine/dolphin/convert.go:197:13: n.Schema undefined (type *"github.com/pingcap/parser/ast".FuncCallExpr has no field or method Schema)
/home/kc/go/pkg/mod/github.com/kyleconroy/sqlc@v1.5.0/internal/engine/dolphin/convert.go:216:14: n.Offset undefined (type *"github.com/pingcap/parser/ast".FuncCallExpr has no field or method Offset)

However, using 1.4.0 works for now, so I am currently relying on that. This works:

go mod edit -require github.com/kyleconroy/sqlc@v1.4.0
go install github.com/kyleconroy/sqlc/cmd/sqlc

@warent
Copy link

warent commented Sep 2, 2020

This is happening for me as well. Looking at the docs:
https://godoc.org/github.com/pingcap/parser/ast#FuncCallExpr

FuncCallExpr is defined as:

type FuncCallExpr struct {
    Tp     FuncCallExprType
    Schema model.CIStr
    // FnName is the function name.
    FnName model.CIStr
    // Args is the function args.
    Args []ExprNode
    // contains filtered or unexported fields
}

Trying to access some field Offset
https://github.com/kyleconroy/sqlc/blob/master/internal/engine/dolphin/convert.go#L343

But it doesn't seem to be defined:
https://github.com/pingcap/parser/blob/master/ast/functions.go#L351

Nor in the embedded structs:
https://github.com/pingcap/parser/blob/53ac409ed043f89a850043d2440aaaa7dd863a1c/ast/base.go#L92
https://github.com/pingcap/parser/blob/53ac409ed043f89a850043d2440aaaa7dd863a1c/ast/base.go#L64
https://github.com/pingcap/parser/blob/53ac409ed043f89a850043d2440aaaa7dd863a1c/ast/base.go#L20

@warent
Copy link

warent commented Sep 2, 2020

@kyleconroy
Copy link
Collaborator

Sorry, I should have offered a clearer explanation in my previous comment.

sqlc currently uses my fork (https://github.com/kyleconroy/parser) of pingcap's MySQL parser. The fork adds the Offset field to FuncCallExpr. This is necessary to support named arguments via sqlc.arg(). I'm using the fork via the replace directive in go.mod, which apparently doesn't work when installing via go get.

I'll be able to move off my fork once pingcap/parser#984 has been merged. Until then, builds using go get will fail. Please install via Docker or the download links in the README in the time being.

@kyleconroy kyleconroy added bug Something isn't working documentation Improvements or additions to documentation upstream Issue is caused by a dependency labels Sep 2, 2020
@warent
Copy link

warent commented Sep 2, 2020

Oh I see! Thanks for the explanation & quick response. I just figured it out after cloning the repo and successfully building from source, leading me to find the go.mod replacement 😄

@rochacon
Copy link

I use sqlc in different projects with different versions. Calling it via //go:generate go run .../cmd/sqlc generate is a way to avoid having the binary in a different version then the one in the project's go.mod.
Including the same replace directive from the v1.5.0 release in my go.mod file was the workaround I took.

@kyleconroy
Copy link
Collaborator

Re-opening this until the next version is released.

@kyleconroy
Copy link
Collaborator

This has been fixed since the release of v1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation upstream Issue is caused by a dependency
Projects
None yet
6 participants