paint-brush
Getting Started with Buck build on Travis CIby@buckaroo.pm
823 reads
823 reads

Getting Started with Buck build on Travis CI

by Buckaroo - C/C++ PackageJune 14th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<a href="https://travis-ci.org/" target="_blank">Travis CI</a> is a service that offers free build servers for open-source projects (<a href="https://www.crunchbase.com/organization/travis-ci/timeline#/timeline/index" target="_blank">thanks, VCs!</a>). It has tight integration with GitHub, allowing you to automatically build and test code in a pull request before merging. This is great for projects with multiple contributors, because you can run tests without checking-out the code yourself.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Getting Started with Buck build on Travis CI
Buckaroo - C/C++ Package HackerNoon profile picture

Travis CI is a service that offers free build servers for open-source projects (thanks, VCs!). It has tight integration with GitHub, allowing you to automatically build and test code in a pull request before merging. This is great for projects with multiple contributors, because you can run tests without checking-out the code yourself.

But how do you integrate a Buck based project with Travis CI?

To follow this guide you will need the following:

TL;DR

Grab the relevant files from the example repo on GitHub.

Create a .travis.yml File

At the heart of a Travis project is the .travis.yml file. This is a YAML file that defines the build steps and build environment for your project. The most important property is script, which is the list of Bash commands.

For example:

Run build.sh on Ubuntu “Trusty”

Install Build Dependencies

Buck is not packaged with any of the Travis system images, so we will need to add an installation step to the Travis file. Installation steps live under the before_install element.

The easiest way to get Buck running on Linux is via Linuxbrew, the Linux port of Homebrew. Like Homebrew, Linuxbrew allows us to easily install packages in userland, and it is mostly package-compatibile.

This snippet runs before the project is built. First, it installs Linuxbrew, then it uses Linuxbrew to install Buck.

You might have noticed that we did not use the provided Linuxbrew install script. This is because it is best to keep everything in the home folder, which ensures that the Travis user has read and write access.

Once we have Buck installed, the script portion of .travis.yml can call Buck:

Pulling everything together, we have the following:

Add this file to the root of your project, and be sure to change the buck build command to point to the correct Buck target!

Connect Travis CI to GitHub

Once the Travis file is in place, you need to connect Travis CI to your GitHub project. Create an account on Travis CI, then flick the switch on the project you want to integrate.

Travis will now be integrated with your project, and it will start building master. You will also notice useful notifications appear in your pull requests!

Accelerating the Build

The build will take a while because it has to install all of the dependencies each time! We can improve this massively by taking advantage of Travis CI’s cache feature.

Travis CI allows you to mark a directory as cached, which means it gets re-used between builds. Since we installed Linuxbrew in userland, we can just cache the whole ~/.linuxbrew directory. On subsequent builds, Linuxbrew will detect that our dependencies are already installed and skip the installation step.

We also need to make sure that we do not git clone Linuxbrew twice:

Pulling everything together gives us the finished Travis file:

Conclusion

And that’s it! The full Travis file should be enough to get started, or you can grab the relevant files from the example repo on GitHub.