gobazeldep

Is there a link between dep and the bazel Go rules?


Intro: dep is a tool to manage dependencies of Go projects. bazel is a build tool that produces stable, reproducable builds. There is a bazel rule set for Go projects, including an automatic build-file generator, gazelle, that generates Bazel build files following the conventions that go build would apply, using the dependencies declared in the bazel WORKSPACE.

The WORKSPACE, though, I have to create by hand or by help of a little hackish helper tool, wtool. dep, on the other hand, helps track dependencies, is able to download them into a vendor/ directory and locking specific versions.

To me it appears that the Gopkg.lock file that dep uses to specify versions of dependencies (usually by their VCS commit hash) would be easily translated into a bazel WORKSPACE file. I have successfully done so manually in a company-internal project as well.

Is there an existing link between bazel and its Go rules and dep that I could have used instead of doing this manually?

(Additionally: Is anybody else doing this? Should I be doing this at all?)


Solution

  • There's no existing tool for this, but it should be pretty straightforward to convert entries in the lock file to WORKSPACE.

    We're thinking of a command to the Gazelle build file generator to help with this (not just for dep, but other tools as well). The main plan is for Gazelle to automatically add repositories that are missing, but that will take more time to implement.