pen-solid
Visual Studio Code + Bazel
GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

The Build in Detail

What happend

  1. When you ran bazel build //..., bazel read the .bazelrc file in this directory.
  2. .bazelrc instructed bazel to download all of the dependencies to the build directory under projects.
    • The dependency cache is placed here so we can reference our GoLang, Java, Protobuf, and Downloaded dependencies using relative paths.
  3. Bazel then reads the WORKSPACE, and each recursive BUILD file to create a set of dependencies, this includes all of the binaries for Java, Go, etc.
  4. You either had the right directory, or you made some changes and edited the workspace.
    • This is how the Java and Go environments are setup, so it’s pretty important.
    • Again, with the workspace limitations, Java Projects MAY NOT have multiple Java dependencies, this ONLY impacts the IDEs ability to do auto complete, but DOES NOT represent the compile or runtime dependencies. This MAY cause problems.

Build Details

Just so you know what’s happening behind the scenes when we execute bazel build //.... From above, we have a rough understanding, this section will provide a little more detail, starting from the WORKSPACE.

  1. As bazel reads the workspace, it determines which languages and features will be supported. From top to bottom:
    • Protocol Buffers
    • The Protol Buffer Tool Chain (Protoc)
    • GRPC
    • GRPC Documentation Generator
    • Go Toolchain (version 1.19.1)
    • Gazelle (A build and dependency helper for bazel)
    • Go GRPC rules.
    • The Java Tool Chain (Java 17)
    • The internal Maven Tool Chain
    • The project Maven Dependencies
    • Hugo Site Generation Tools
    • A Hug Theme (GeekDoc)
  2. Onces those tool chains have been loaded, each directory BUILD file is read, and a dependency graph is created. That dependency graph determines the build order.
    • API - Is built first because Java and Go depend on it, it uses the GRPC toolchain.
    • Java - Is built, using the Java Toolchain, maven dependencies, and the protocol definitions. The output of the generated files are in the ‘build’ directory.
    • Go - Is built, using the Go Tool Chain, and the dependencies from the Gazelle (go_deps.bzl) file.
  3. The docs directory is built using the Hugo toolchain and theme.