-
Notifications
You must be signed in to change notification settings - Fork 652
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 with embedsrcs attribute #2806
Conversation
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 bazelbuild#2775
@bazelbuild/go-maintainers Please comment if you have any thoughts on this. I'm happy to answer any questions, too. This is a good template for adding new attributes and understanding how the rules work. |
Any updates yet? I am waiting eagerly for this exact feature and I was hoping it would make the Go 1.16 release. |
any pointers on how to try this out before it's released would be greatly appreciated too :) |
@nicolai86 you can, as always load from any path you want with a |
so I've replaced my simple change:
and straight forward transformation of
smooth sailing with 1.16. <3 |
Another question: we currently have a target :ui which runs react-scripts. react-scripts comes with a webpack config that generates a variable number of files. The files mostly look like "chunk.[sha256].js" or something like that (containing a hash so that the files can be cached indentinitely). As far as I know, Bazel requires static input / output files and therefore our :ui rule generates a "ui.tar" file containing the variable number of files. Later, we use a custom go_bindata rule to extract the tar archive and generate an ui_bindata.go which is then compiled into the binary. How would one archive a similar result with the new emedsrcs attribute? Is there a way to pass a "variable collection of files"? Should we also support passing tar achives? Embedding the tar archive directly would be possible, but has several disadvantages. Embedding a zip might work however (since zip also implements fs.FS) so that could be a possible workaround. |
@nicolai86 Thanks for trying it out! Glad it works. @tux21b Not sure if this is an option for you, but rules can declare output directories using @achew22 I'm still working on generating |
@jayconrod embedsrcs works fine for me, too, thanks! One issue, though: I'm embedding a directory with an arbitrary number of files. If one of them changes, or a file is added, these changes don't get picked up by bazel. They do get picked up after a "bazel clean", and also when running via plain old "go run". Is this behavior desired, or am I doing something wrong? |
@rsippl Sounds like something isn't going right. Files in |
@rsippl I've had something similar before (though not with this feature in particular), but I wasn't using a |
@jayconrod this is true for files (e.g. |
@jayconrod turns out I was wrong, |
If you're embedding static files in a directory, you do need to specify them individually or with a If you have a rule that generates a directory (declared with |
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