Building go plugins with gazelle

76 views Asked by At

I'm building a project written in go with the bazel build system and its gazelle extension to automatically generate BUILD files.

The project's file tree is similar to this:

project-root/
... cmd/
... ... cmd1/
... ... cmd2/
... internal/
... ... internalPackage1/
... ... internalPackage2/
... plugins/
... ... plugin1/
... ... plugin2/
... ... pluginCategory/
... ... ... plugin3/
... ... ... plugin4/
... go.mod

The commands and the internal packages are built correctly, but when it comes to building the plugins, I've read that I need to compile them using go build -buildmode=plugin. If I were to manually write the BUILD files, I could add to the go_binary rule the linkmode = "plugin" argument.

Now, for my questions:

  • Is there any configuration or parameters I can pass to gazelle in order to add this argument to all BUILD files generated under a specific directory (plugin/) and preferably its sub-directories (to support the plugin categories as shown above)?
  • If not, is there a tool other than gazelle to generate bazel BUILD files that supports plugins like that?
  • What is the industry's best practice on building go plugins with bazel?

Thank you in advance.

0

There are 0 answers