Search code examples
bazel

Bazel folder naming convention


I know that bazel does not impose any specific file structure, but there are some folder naming conventions that are followed by products using Bazel, and some of them (e.g. "third_party") do have a special treatment (it requires the licenses to be specified).

So I don't quite understand the difference between tools and third_party. For example, if I want to put a "ruby toolchain" it's a tool, since it's the language interpreter, but it's also a third_party, because it has been developed by a community. Where should it go?

And what about bazel rules? Where should the be placed idiomatically?


Solution

  • I'm a Bazel developer, and I agree, the usage here can be a little confusing.

    Generally, we recommend that third_party be used for any external code you're importing to use in your project. Bazel itself, for example, has a lot of libraries in there for Python flag parsing, Java compilation, and a lot of other things.

    Tools, on the other hand, would be for code you've written to help with your project as a standalone program. For example, if you wrote a script that converts a static text file into code (maybe so you can access the data as in-language constants), I'd say that could go into tools, since it's a standalone, but useful for your project.

    (As a note, Bazel's tools directory is a bit different from this: we actually package those up and include them in the Bazel binary so they can be used at run-time, not at build-time).

    If you're writing custom Skylark rules, you can put that wherever makes sense, but I'd like to ask that if you think they might be useful beyond your project, you create a separate repository for them so other developers can use them. It's much easier to use custom rules from a dedicated repository, since you just need to use the http_archive() rule in a WORKSPACE to get them. If they're mixed in with the rest of your project, it's harder for other people to re-use.