bazel-contrib / bazel-contrib/rules_go
Use cases for go_embed_data
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 762
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
This may simply be a case of improved documentation (re: https://github.com/bazelbuild/rules_go/issues/2161). My apologies if it is.
### What version of rules_go are you using?
0.19.1
### What version of gazelle are you using?
0.18.1
### What version of Bazel are you using?
0.28.1
### Does this issue reproduce with the latest releases of all the above?
I was able to reproduce it using Bazel 0.28.1
### What operating system and processor architecture are you using?
macOS 10.14.5
### Any other potentially useful information about your toolchain?
Go 1.12.7
### What did you do?
I'm currently migrating several existing Go projects over to Bazel. Many of these projects make use of data files (e.g. template files, configuration yaml files, etc.). Prior to moving to Bazel we used a library (https://github.com/cookieo9/resources-go/tree/v2.1) to handle loading of these assets. This library provided useful functionality such as:
* Loading the files directly from the filesystem in the case of local development.
* Or bundle the files into the binary as a zip archive, making releases to the production environment very straightforward. This bundling was handled by running the binary with the `--bundle-resources` flag which would create a new version of the binary with the files included.
On first pass it seemed as though `go_embed_data` would be necessary to replicate this when moving to Bazel. As a result I wrote something like:
```
load("@io_bazel_rules_go//go:def.bzl", "go_embed_data")
go_embed_data(
name = "resources",
srcs = glob(["**/*.tmpl"]),
package = "main",
visibility = ["//visibility:public"],
)
```
I then added `:resources` to the sources list of the app I'm building.
In general without `go_embed_data` things seem to work as our resources library is aware of the project root and can go from there. However, when using `go_image` it falls apart as the resource files are not copied into it.
### What did you expect to see?
Honestly I was really hoping for a drop in replacement. 😀
### What did you see instead?
Ok, so I saw that a `resources.go` file was created with a map of filepaths to contents. This seems bizarre to me and I feel like I'm missing something here.
* Is the intent that I update my code to access the file contents via this map?
* What is the workflow supposed to be? IDE behavior seems less than ideal as this resources file is dynamic and only seems to exist during the Bazel BUILD process.
* Can I no longer use the file interface?
Should I be approaching this differently? It seems like I could write a custom rule to execute the `--bundle-resources` step as part of my build process.
Any help would be appreciated. Thanks.
Contributor guide
Research direction
Start with the linked rules_go issue 2161 and the go_embed_data and go_image entry points mentioned here. Determine the intended workflow for embedding data, whether the generated resources.go map replaces filesystem access, and how embedded resources should behave in images. Done means documenting the supported use cases, IDE implications, and recommended approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100