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

Fallback comment "//+build !test" missing for "//go:build !test" for Go versions v.16.x #1577

Closed
chombium opened this issue Mar 15, 2022 · 4 comments
Assignees

Comments

@chombium
Copy link
Collaborator

BUG REPORT

  1. What were you trying to achieve?
    Build mainflux with make build or separate microservices with go build . .

  2. What are the expected results?
    The build process finishes successfully.

  3. What are the received results?

 make
CGO_ENABLED=0 GOOS= GOARCH=amd64 GOARM= go build -mod=vendor -ldflags "-s -w -X 'github.com/mainflux/mainflux.BuildTime=2022-03-14_23:37:37' -X 'github.com/mainflux/mainflux.Version=0.12.1' -X 'github.com/mainflux/mainflux.Commit=f3ed852b36219278ab873cf7af4f1aaadca628b4'" -o build/mainflux-users cmd/users/main.go
cmd/users/main.go:35:2: //go:build comment without // +build comment
make: *** [Makefile:78: users] Error 1
cd <path_to_cloned_mainflux_repo>/cmd/users
 go build .
main.go:35:2: //go:build comment without // +build comment
  1. What are the steps to reproduce the issue?
  • clone the repo
  • try do build Mainflux or one of its services with go version earlier that v17.0.0
  1. In what environment did you encounter the issue?
go version
go version go1.16.15 linux/amd64

I've encountered this issue with go 1.16.15, but I wanted to see with which go version does the problem starts. I found out that the problem appears with go v1.16 and disappears with go v17.0.

  1. Additional information you deem important:

I've checked what the Go design proposals and I've found this draft proposal. In this document it is specified that the new notation is as we have it in the master at the moment //go:build <comment>, //go:build !test. It is also specified that as a transition that:

Go 1.(N−1) would prepare for the transition with minimal changes. In Go 1.(N−1):

- Builds will fail when a Go source file contains //go:build lines without // +build lines.

This is why I could not build with go v1.16.15. The fix to support go v16.x in our case is to simply add another // +build !test line right after each // go:build !test line. If we add the // +build !test line it will be used as fallback for the older versions. The changes of the go build tag were introduced in the code with the MF-1308 PR.

The fix would be to add the following pair wherever we have the build tag:

//go:build !test
//+build !test

I've done test adding the lines above in few files and I could build successfully with go v16.x.

@mainflux/contributors What do you think? Should I create a PR with a fix?

@drasko
Copy link
Contributor

drasko commented Mar 15, 2022

@chombium yes, please go ahead - we will support the latest Go version on the master.

@dborovcanin
Copy link
Collaborator

dborovcanin commented Mar 15, 2022

I think that simply setting the minimum Go version to 1.17, which implicitly solves this problem, is perfectly fine. In go.mod file we also use 1.17, and I've been even using go mod tidy -compat=1.17 command when updating dependencies. This will solve both #1578 and #1577. I see no real benefits of keeping compatibility with Go 1.16 or below.

@drasko
Copy link
Contributor

drasko commented Mar 15, 2022

Agreed with @dusanb94

@drasko drasko closed this as completed Mar 15, 2022
@chombium
Copy link
Collaborator Author

@dusanb94 I agree completely with you. I was thinking to fix this for go v16.x as there is is the stable bugfix release for the latest and latest - 1 release version for the go language itself. If we say we always need the latest stable version its also good, but we need to adjust the docs accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants