Hi!
I'm trying to create a bazel rule for Ent. Ent is an entity framework with a code generator called entc. A schema is defined as go source and entc builds and runs the schema code to produce an intermediate specification. entc's code generator then produces a plethora of source files, including some in subpackages/subdirectories.
I managed to create an initial rule that allows entc to call "go run" under the hood and generate all the source files from the schema. However, now I'm stuck as I can't see a way to expose the go files in the subpackages. It seems like rules_go does not support that and the question is also if gazelle would be able to properly resolve importpath when go packages are defined in a parent directory.
I can do this manually, so I know that bazel can do this.
go_library(
name = "subpkg",
srcs = [
"subpkg/foo.go",
],
importpath = ".../generated/ent/subpkg",
)
go_library(
name = "ent",
srcs = [
"ent.go",
],
importpath = ".../generated/ent",
deps = [
":subpkg",
],
)
This works fine. I can depend on either individually elsewhere: //generated/ent and //generated/ent:subdir.
My current rule uses go_context() and returns the GoLibrary, GoSource, GoArchive providers. Can I make it produce these go subpackages in the same bazel package or is there another way to do this, so that gazelle doesn't get confused and gopackagedriver can handle this? Despite rules_go's complexity I find its helper functions actually to be really nicely done, but it just seems that GoContext won't even allow changing the target label nor am I sure I can override the importpath.
Thanks,
Folke