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

go: support go:embed directives in 1.16 #2775

Closed
jayconrod opened this issue Jan 5, 2021 · 0 comments · Fixed by #2806
Closed

go: support go:embed directives in 1.16 #2775

jayconrod opened this issue Jan 5, 2021 · 0 comments · Fixed by #2806

Comments

@jayconrod
Copy link
Contributor

Go 1.16 allows embedding files within a compiled package by imported the embed package and using one or more //go:embed directives. For example:

package main

import (
  _ "embed"
  "fmt"
)

func main() {
  //go:embed quine.go
  var s string
  fmt.Print(s)
}

rules_go should support this.

go_library, go_binary, go_test, and perhaps also go_proto_library should support a new embedsrcs attribute specifying a list of targets that could provide embeddable files. It's unfortunate we can't just call it embed, but that already means something else.

The rules should pass these files to the builder, which should match the //go:embed patterns against these files to produce an embedcfg file, which may be passed to the compiler.

The builder should produce a sensible error messages if //go:embed directives are used Go versions lower than 1.16.

Until this is implemented, go_embed_data may be used instead.

jayconrod pushed a commit to jayconrod/rules_go that referenced this issue Feb 2, 2021
go_library, go_binary, and go_test now support the //go:embed
directive in Go 1.16. When building a package containing a //go:embed
directive, they'll match patterns against embedable files to generate
an embedcfg file to pass to the compiler.

Embeddable files must be listed in the new embedsrcs attribute.

The GoSource provider now has an embedsrcs field to support this.

Fixes bazel-contrib#2775
jayconrod pushed a commit that referenced this issue Feb 24, 2021
go_library, go_binary, and go_test now support the //go:embed
directive in Go 1.16. When building a package containing a //go:embed
directive, they'll match patterns against embedable files to generate
an embedcfg file to pass to the compiler.

Embeddable files must be listed in the new embedsrcs attribute.

The GoSource provider now has an embedsrcs field to support this.

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

Successfully merging a pull request may close this issue.

1 participant