syscall: go generate fails because golang.org/x/sys/windows/mkwinsyscall command isn't vendored
alexbrainman opened this issue · 8 comments
$ go version go version devel +5d1378143b Thu Oct 8 00:28:09 2020 +0000 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/a/.cache/go-build" GOENV="/home/a/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/a/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/a" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/a/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/a/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/a/go/src/go.mod" 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-build066767711=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I tried to regenerate $GOROOT/syscall/zsyscall_windows.go file. I run go generate in syscall directory.
What did you expect to see?
I expected to see no errors. And have zsyscall_windows.go file updated.
What did you see instead?
$ go generate
cannot find package "." in:
/home/a/go/src/golang.org/x/sys/windows/mkwinsyscall
syscall.go:29: running "go": exit status 1
$
and my zsyscall_windows.go does not change.
It appears golang.org/x/sys/windows/mkwinsyscall is broken now that we have to use modules.
We also need to update internal/syscall/windows and internal/syscall/windows/registry package. I also use mkwinsyscall in a couple of my own projects. I also suspect that some people use it too. So we need some easy to use solution.
@bcmills for suggestions. I am happy to use whatever approach you suggest.
Thank you.
Alex
Change https://golang.org/cl/260860 mentions this issue: all: use latest version of golang.org/x/sys/windows/mkwinsyscall
I'm not able to reproduce this failure mode locally:
~/src/golang.org/x/sys/windows$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~/src/golang.org/x/sys/windows$ go version
go version devel +5d1378143b Thu Oct 8 00:28:09 2020 +0000 linux/amd64
~/src/golang.org/x/sys/windows$ go generate
~/src/golang.org/x/sys/windows$
[Edit: I should have read more carefully. You are generating syscall, not golang.org/x/sys/windows.]
Ah, now I understand. There are several issues at play here:
-
When your working directory is
$GOROOT/src/syscall, you are working within thestdmodule, and the dependency ongolang.org/x/sys/windows/mkwinsyscallis not vendored, because it is not part of thecmdimport graph (see #25922). -
Because the
stdmodule has a vendor directory, thegocommand defaults to-mod=vendorinstead of the usual-mod=readonly. -
For some reason, the error message from
go/buildin this case is not helpful. (This may or may not be a bad interaction with the special case for standard-library vendoring.)
As an immediate workaround, GOFLAGS=-mod=readonly seems to work.
As a longer-term fix, we should either add the go:generate dependencies of the std module to std/vendor, or set -mod=readonly explicitly in the go:generate command.
I'll file a separate issue for the poor diagnostic. It seems to be closely related to #38748, but may or may not share a root cause.
Change https://golang.org/cl/261499 mentions this issue: internal/tools: add a dummy package that imports mkwinsyscall
As an immediate workaround,
GOFLAGS=-mod=readonlyseems to work.
I am not big module expert. So I used
GO111MODULE=off go generate
in https://go-review.googlesource.com/c/go/+/260860 (I am still waiting for reviewers). I hope it is OK for the moment.
Alex