Bazel & Introduction: Part One – The Old

Today

Today, I finished my 2800 line odyssey to set up Valkyrie’s monolithic, cross-platform build system, which uses Bazel. That was a lot of long words. Let’s break it down!

Build System

Something that you may not have noticed during the year, is that behind the scenes plenty of utilities are working hard to get your code on your robot in a format that the robot can read. Let’s discuss the old, before we discuss the new. The old system had two different components: ant, and prebuilt-WPILib.

Note that Java is completely different from C++.

Prebuilt-WPILib

WPILib is a library in two parts. One part is written in Java, and another portion is written in C++. The C++ portion is built on their servers in a format which is compatible with the RoboRIO (more on that later). This C++ version is then wrapped in what we call (no surprise) a ‘wrapper.’ The wrapper is written in Java, but calls the C++ WPILib code through the JNI: Java Native Interface. In plain terms, it allows the Java Virtual Machine to call C++ code. This is how WPILib is fundamentally built.Unfortunately, it means that it’s very hard to edit WPILib, and even more annoying to debug when something goes wrong.

ant

The next step in the process is a piece of Apache software called ‘ant’. This part requires an explanation of the history of build files (at least as far as I can recall hearing). In the beginning, there was nothing. Literally. In the beginning, programs came written in machine language which didn’t require you to build it. In fact, what you’d consider programs were just the operating system. This is the computers-the-size-of-rooms era. Next, compilers happened (again, my grasp of this is minimal. Don’t trust me.). People would use shell scripts to run a series of commands which would build/execute all of their code.

Next, we used utilities from many different places, the most well-known of which is GNU Make. Yes, back in the day, people used to compile Java using GNU Makefiles. In fact, my first Java project was built with a 12 line Makefile (Java 5 LOL). Around 2011, I stopped doing Java so I’m not sure what happened. Apparently, everyone started using ant, and then maven and then Gradle. Not gonna bother to explain the latter two, as they’re rather modern, and too good for this rant.

Anyway. Back to ant. Essentially, someone thought it would be a really good idea to create a build system not based on plaintext, like GNU Make, or on scripting languages, but instead on XML, the Extensible Markup Language. Yes. XML. The one language neither computers nor humans can read. Anyway, Eclipse runs this lovely XML thing and then that builds your Java, links it into the C++ WPILib, and then uses the shell to put it on the robot.

That’s pretty much how the old system used to work. Compile using javac, link with C++, deploy to robot.

Conclusion

This was far more disconnected and long than I thought. Please check back in soon for the next post in this series, which will cover the concepts of building C++.

edit: Next post available here