Introduction
After using GNU Make for automating the build step in my projects, I had this idea of making my own build automation tool like Make.
I originally wanted to use Makefile-like syntax for the config file but instead settled with TOML after thinking about it for a while. I also used Rust to write this since I am kinda familiar with the language.
Rust has a TOML crate for parsing TOML files. It also provides support for deserialization and serialization using serde.
It’s also extremely easy to use:
| |
I didn’t include the other structs to make the snippet smaller. This was also the first time I used rust macros in a project, as you can see with the printb! macro. All it does is print
Baker: <message> as coloured output.
| |
Configuring baker
The configuration file is put in the root directory of the project, just like the Makefile.
If Baker is unable to find a config file (called recipe.toml), it auto generates one.
Here’s an example config:
| |
Baker is invoked using bake and by default checks for the build field in the recipe.toml.
The cmd value is then executed during build.
You can set environment variables using the env field.
You can also add custom fields using custom. It also checks for a run value that is used to check whether the command should be run
after build or not. So if run = true, then the command is run after build.
Baker also checks for an optional pre field that contains commands which should be run before build. Like for example, if you wish to
format your code or something before compiling.
You may have noticed a name value in the custom and pre fields ([custom.name]). This is used to identify each field, and for the custom field,
the name is set as an argument when Baker is invoked.
For example, if I have a custom field called setup:
| |
You can run bake setup to directly execute the command inside the field.
Baker is open source and you can find the repo here. I wrote it in like 2 days, so it may have bugs which I was not able to find, so all suggestions are welcome!
That’s it for this blog, see you soon!