bazel-contrib / bazel-contrib/rules_go
go_embed_data generates different output when it's in an external dependency
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 762
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
If a workspace declaring a go_embed_data target is used as an external dependency for another workspace, the generated Go source's map keys contain external/the_dep_name/ prefixes. This makes it difficult to use from a repo that can be built standalone or as part of a larger project.
Reproduction:
# WORKSPACE
workspace(name = "test_go_embed_data")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.18.0/rules_go-0.18.0.tar.gz"],
sha256 = "301c8b39b0808c49f98895faa6aa8c92cbd605ab5ad4b6a3a652da33a1a2ba2e",
)
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
local_repository(
name = "subrepo",
path = "subrepo",
)
# subrepo/BUILD
load("@io_bazel_rules_go//extras:embed_data.bzl", "go_embed_data")
go_embed_data(
name = "test_embed",
srcs = [":BUILD"],
package = "test_embed",
)
$ bazel build @subrepo//:test_embed
Target @subrepo//:test_embed up-to-date:
bazel-bin/external/subrepo/darwin_amd64_stripped/test_embed.go
$ grep -A 2 'var Data' bazel-bin/external/subrepo/darwin_amd64_stripped/test_embed.go
var Data = map[string][]byte{
"external/subrepo/BUILD": Data_0,
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the WORKSPACE and subrepo/BUILD examples, then inspect the go_embed_data entry point loaded from @io_bazel_rules_go//extras:embed_data.bzl and compare standalone and external builds. Done means the generated Data map uses the same key for BUILD in both contexts, without an external/subrepo/ prefix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100