Bazel has a concept it calls runfiles for files that a binary uses during execution. For example, a binary might need to read in a CSV, an ssh key, or a .json file. These files are generally specified separately from your sources for a couple of reasons: Bazel can understand that it is a runtime,Continue reading “Collecting transitive runfiles with skylark”
Category Archives: Bazel
Using a generated header file as a dependecy
Someone asked me today about how to use a generated header as a C++ dependency in Bazel, so I figured I’d write up a quick example. Create a BUILD file with a genrule that generates the header and a cc_library that wraps it, say, foo/BUILD: genrule( name = “header-gen”, outs = [“my-header.h”], # This commandContinue reading “Using a generated header file as a dependecy”
configure: error: lib_i_don’t_care_about.so not found.
I work on Bazel, so I don’t usually get to see it from a user’s point of view. However, yesterday I added seven new projects to Bazel’s continuous integration, all of which promptly broke. I started cloning them and trying to fix them. These projects were various user-contributed rules for Bazel: rules for building Go,Continue reading “configure: error: lib_i_don’t_care_about.so not found.”
Flag-Friday: debugging tests with –java_debug
To step through a Java test that you’re running with bazel test, use the –java_test flag: $ bazel test –java_debug //src/test/java/com/example:hello-test WARNING: Streamed test output requested so all tests will be run locally, without sharding, one at a time. INFO: Found 1 test target… Listening for transport dt_socket at address: 5005 At this point, switchContinue reading “Flag-Friday: debugging tests with –java_debug”
Saving the (prod) environment
You can create different environments (e.g., testing, prod, mobile, rainforest) with Bazel, then use them to make sure that targets only build with the right environment. This is a cool feature that’s undocumented (because it’s still in development, shhhhh, don’t tell anyone I told you about it). Let’s say you have a prod SSH keyContinue reading “Saving the (prod) environment”
Combining projects without converting to a monorepo
Bazel allows you to combine multiple directories from across your filesystem and pretend all of the sources are part of your project. This is a little hard to picture, so let’s use a concrete example. Let’s say you have two projects you’re working on, checked out at ~/gitroot/spaghetti-stable and ~/gitroot/meatballs-master. You don’t want to combineContinue reading “Combining projects without converting to a monorepo”
One weird trick for fast CI
Compilers hate this! (Just kidding, compilers are easy-going.) For many build systems, you have to do a clean build to be sure you’re getting the correct result, so your CI has to always do a clean build. On the other hand, Bazel is designed so that you never have to do a bazel clean (ifContinue reading “One weird trick for fast CI”
Creating a javadoc rule for Bazel
A couple of users have asked about how to generate javadoc with Bazel. There’s no built-in way, but I figured it might be useful to whip together a new rule to do so. Here it is. If you’d like to use this rule, download it to your workspace, load it in your build file, andContinue reading “Creating a javadoc rule for Bazel”
Build, y u go slow?
When a build is taking too long, it can be very helpful to know what it’s doing. Bazel has built-in tooling that lets you visualize what each thread is doing at any given moment of a build and which build steps are slowing down your overall build. To try out Bazel’s profiling tools, build yourContinue reading “Build, y u go slow?”
Debugging flaky tests with Bazel
Suppose you have a test that is passing… most of the time. When you start debugging it, you might try running the test and, unhelpfully, it passes: $ bazel test :flaker INFO: Found 1 test target… Target //:flaker up-to-date: bazel-bin/flaker INFO: Elapsed time: 0.223s, Critical Path: 0.04s //:flaker PASSED Executed 1 out of 1 tests:Continue reading “Debugging flaky tests with Bazel”