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

support build tag #760

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.js.map

# Conformance test output and transient files.
conformance/failing_tests.txt
conformance/failing_tests.txt
/.idea
9 changes: 9 additions & 0 deletions protoc-gen-gogo/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ type Generator struct {

customImports []string
writtenImports map[string]bool // For de-duplicating written imports

buildTag string
}

type pathType int
Expand Down Expand Up @@ -536,6 +538,8 @@ func (g *Generator) CommandLineParameters(parameter string) {
if v == "true" {
g.annotateCode = true
}
case "build_tag":
g.buildTag = v
default:
if len(k) > 0 && k[0] == 'M' {
g.ImportMap[k[1:]] = v
Expand Down Expand Up @@ -1197,6 +1201,11 @@ func (g *Generator) generate(file *FileDescriptor) {
g.usedPackageNames[name] = true
}

if g.buildTag != "" {
g.P("//go:build ", g.buildTag)
g.P("// +build ", g.buildTag)
}

g.P("// This is a compile-time assertion to ensure that this generated file")
g.P("// is compatible with the proto package it is being compiled against.")
g.P("// A compilation error at this line likely means your copy of the")
Expand Down