mage
mage copied to clipboard
Zero Install instructions do not work for Go 1.14 or 1.15
The problem
Following the "Zero Install" instructions at https://magefile.org/zeroinstall/ does not work with Go 1.14 or 1.15 when using go mod vendor
.
The // +build ignore
build constraint in the mage.go
file causes the problem. With that build constraint go mod vendor
does not vendor the github.com/magefile/mage
package or its dependencies. The go mod docs explain that go mod tidy
(and I guess also go mod vendor
) has a special case for that specific build constraint.
go mod tidy acts as if all build tags are enabled, so it will consider platform-specific source files and files that require custom build tags, even if those source files wouldn't normally be built. There is one exception: the ignore build tag is not enabled, so a file with the build constraint // +build ignore will not be considered.
Without those packages in the vendor dir go run mage.go
fails when using Go 1.14 or 1.15 with the following message.
mage.go:8:2: cannot find package "." in:
/path/to/project/vendor/github.com/magefile/mage/mage
This behavior is expected with Go 1.14 or higher as described in the release notes.
When the main module contains a top-level vendor directory and its go.mod file specifies go 1.14 or higher, the go command now defaults to -mod=vendor for operations that accept that flag.
The work around
If I change the build constraint to something else, such as tool
then go mod vendor
pulls in the necessary packages and go run mage.go
works.
Recommended fix
Update the "Zero Install" docs to recommend a build constraint other than ignore
.
I confirm that this also happens on 1.16
on darwin/arm64
.
The workaround you mentioned also did not work for me, I get:
No .go files marked with the mage build tag in this directory.
exit status 1