Bake, A build system for building, testing and running C & C++ projects
Bake, A build system for building, testing and running C & C++ projects
The Dutch IRS has a catchy slogan, which goes like this: "Leuker kunnen we 't niet maken, wel makkelijker". Roughly translated this means: "We can't make it more fun, but we can make it easier". Bake adopts a similar philosophy. Building C/C++ code will never be fun, but with bake you'll probably spend a little less time worrying about it.
Here's how bake tries to alleviate some of the pain:
Bake is verified on the following platforms:
Bake is verified on the following compilers
Bake is used as the primary build system for Flecs.
Install bake using the following commands:
On Linux/MacOS:
git clone https://github.com/SanderMertens/bake
bake/setup.shOn Windows:
Requires Visual Studio Build Tools or the full Visual Studio Community IDE installed with the C++ CMake tools for Windows and Windows SDK individual components included in the Desktop development with C++ workload:
git clone https://github.com/SanderMertens/bake
cd bake
setupOn MacOS/Linux bake will install a single script in /usr/local/bin which calls the bake binary in ~/bake, which may prompt for your password during installation. This script allows you to call bake from any location without having to make changes to your environment.
If you'd rather not install this script, you can install bake in local mode:
git clone https://github.com/SanderMertens/bake
cd bake
make -C build-$(uname) clean all
./bake setup --localAfter the setup has finished, the bake executable will be stored in ~/bake. Make sure to add this directory to your PATH variable before using bake.
You can upgrade bake to the latest version by running this command:
bake upgradeThe following commands are useful for getting started with bake. Also, check out the bake --help command, which lists all the options and commands available in the bake tool.
To create and run a new bake application project called my_app, run the following commands:
bake new my_app
bake run my_appYou can also run projects in interactive mode. This will automatically rebuild and restart an application when a project file changes. To run in interactive mode, simply add --interactive to the bake command:
bake run my_app --interactiveThis example shows a simple configuration with a dependency on the foo.bar package and links with pthread.
{
"id": "my_app",
"type": "application",
"value": {
"use": ["foo.bar"]
},
"lang.c": {
"lib": ["pthread"]
}
}bake
bake rebuild
bake cleanSpecify a build configuration:
bake --cfg releaseBuild a project and its dependencies directly from a git repository using this command:
bake clone https://github.com/SanderMertens/exampleBake can manage environment variables that must be set during the build. To export an environment variable to the bake environment, use this command:
bake export VAR=valueAlternatively, if you want to add a path to an environment variable like PATH or LD_LIBRARY_PATH, use this:
bake export PATH+=/my/pathThese variables are stored in a configuration file called bake.json in the root of the bake environment, which by default is $HOME/bake.
To export the bake environment to a terminal, use:
export `bake env`No. As long as you do not distribute bake (either as source or binary) as part of your (closed source) deliverable, you can use bake for building your projects. This is no different than when you would use make for your projects, which is also GPL licensed.
Yes. As long as your customers use the open source version of bake, and you do not distribute bake binaries or source files with your product, your customers can use bake.
No. Bake uses premake to generate its makefiles (we would've used bake to build bake- but chicken & egg etc). The generated makefiles are included in the bake repository, so you won't need premake to use bake.
To put it bluntly, existing tools for C/C++ aren't great.
No. Bake has package-management like features, like resolving projects by logical name, automatic project discovery & associate projects with git repositories, but it does not pretend to be a full-fledged package manager. The only reason bake has these features is because it makes the build process easier.
All C/C++ project build configurations basically boil down to the same set of rules to translate source files into objects, and objects into shared objects or application binaries. Yet with most build systems you'll find yourself copy-pasting the same rules every time you create a new project.
Bake doesn't need to be told how to build C/C++ code. It just needs three pieces of information:
src and include directoryMakefiles and Visual Studio files are just elaborate front-ends for how to call compilers. Bake calls the compiler directly. It has builtin drivers for gcc, clang, msvc and emcc, and it automatically detects for which compiler it's building.
GNU make is a low-level tool that requires you to explicitly list all the rules required to translate code to binaries. Bake is a high-level tool that already knows how to build the code, and can do this with minimal configuration.
CMake is a tool that generates other build configurations. When you use CMake you still need to use another tool like Make or Visual Studio to actually build your project. Bake builds your code directly.
Another big difference is that CMake requires you to specify project configuration in a custom language, whereas Bake configuration is specified in JSON. Here is a CMake configuration and a Bake configuration for the same project:
CMake:
cmake_minimum_required (VERSION 2.6)
include_directories ("bar")
add_subdirectory (bar)
set (EXTRA_LIBS ${EXTRA_LIBS} bar)
project (foo)
add_executable(foo foo.c)
target_link_libraries (foo ${EXTRA_LIBS})Bake:
{
"id": "foo",
"type": "application",
"value": {
"use": ["bar"]
}
}A difference that jumps out from the examples is that the bake configuration is agnostic to its environment. It knows where to find project bar, whereas in CMake this needs to be explicitly specified.
Premake is a lot like CMake, but with a Lua-based project configuration that's slightly less verbose. Premake also generates build configurations, and requires additional tools to actually build your code.
Out of all build systems, bake and bazel come closest in the way they approach building code. The biggest differences are:
Yes. This example shows how to link with libm:
{
"id": "my_app",
"type": "application",
"lang.c": {
"lib": ["m"]
}
}This can be improved by ensuring that libm is only added on Linux (MacOS/Windows don't have libm):
{
"id": "my_app",
"type": "application",
"${os linux}": {
"lang.c": {
"lib": ["m"]
}
}
}It would be nice if we could wrap libm.so from the previous example in a bake math package, so we don't have to repeat this configuration for every project. Bake lets us do this with the "dependee" attribute:
{
"id": "math",
"type": "package",
"value": {
"language": "none"
},
"dependee": {
"${os linux}": {
"lang.c": {
"lib": ["m"]
}
}
}
}This creates a new "math" package that you can now specify as regular bake dependency. The "language": "none" attribute lets bake know that there is no code to build, and this is a configuration-only project. The dependee attribute tells bake to not apply the settings inside the JSON object to the math project, but to the projects that depend on math.
We can now use the math package like this:
{
"id": "my_app",
"type": "application",
"value": {
"use": ["math"]
}
}You can find language-specific configuration options in the README of the language driver projects:
For C: https://github.com/SanderMertens/bake/tree/master/drivers/lang/c
For C++: https://github.com/SanderMertens/bake/tree/master/drivers/lang/cpp
All of the rules and instructions in bake that actually builds code is organized in bake "drivers". Drivers are share
No open issues yet, or sync has not completed.