bazel repo: Starting a monorepo
I love monorepos and it was not the case prevously but I do think that monorepos shine in scenarios where:
- The code is tightly coupled together.
- One needs to ensure that resources on dev-tooling are efficiently spent.
- Migrations can be completed atomically.
Bazel is a really good build system, which allows reproducible and reasonably fast builds and the build system is configured with starlark, which can be used to write custom build rules, which allow to do linting or ensure consistency in packaging, etc.
I use bazel at work and I do not want to have to remember how to use two
build systems or build my make targets and maintain them across multiple
repositories. For this reason I decide to attempt to create a monorepo for
myself, which would leverage bazel to:
- Write in multiple languages:
- Rust
- Go
- Shell
- Have common packaging for all.
- Have reproducible builds and leverage caching in between the builds.
In a few hours I could complete a repository setup, which:
- Uses
direnvto setup dev environment. - Uses
bazeliskto download the predefinedbazelversion. - Setup a custom
shellcheckrule which lints all files with.shextension in mytoolsdirectory. - Setup
gazellefor upcoming go code. - Setup
buldifierto ensure that myBUILD.bazelfiles are formatted. - Setup a CI script to ensure that my repository is clean.
See it at aignas/c.
Future ideas:
- Setup Travis CI or GitHub actions.
- A toy
goCLI to iron out wrinkles in thegazelleand CI setup. - A toy
rustCLI to try outcargo-raze. - Add tests for my
shellscripts to test outsh_testrules. - Generalize the
shellcheckbazelrule and put it into a separate repository. - Write a
shfmtrule. bazelpackaging rule for ArchLinux.- Make the setup work on all OSes:
- The
bazeliskbootstrap script should check the OS before downloadingbazeliskbinary. shellcheckrule should detect the OS and download the appropriateshellcheckbinary for the host architecture.
- The
Disclaimer: whilst I do intend to continue experimenting with this and post future updates here, I have other hobbies and it may take some time before I advance this experiment further.
Posted in Programming Monorepo with : bazel git go