Cross-compiling using GitHub Actions and QEMU

Sneha Gaonkar
3 min readMar 21, 2022


Image credits:

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production. It goes beyond just DevOps and lets you run workflows when other events happen in your repository.

GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows; each workflow run executes in a fresh, newly-provisioned virtual machine. If you need a different operating system or require a specific hardware configuration, you can host your own runners. However, if you don’t have the hardware resources with required OS or architecture to host your own runners, then you can QEMU emulator that uses the current operating system to run other architectures.

In this blog, I will share the approach I used to cross-compile opensource packages using GitHub Action and publish the built artifact as a release. We shall refer this repository created for building Terraform for ppc64le architecture.

Create Build script

First, create a build script that will install required dependencies, clone the package repository and execute commands for building the package binary in the required environment. In this example, I have created a script used for building Terraform for Power architecture.

Create workflows in GitHub Action

Create workflows to detect new official release of the package and build the package binary to be published as a release for required OS or architecture.

  1. Polling official package repository

The aim of this workflow is to poll the official source code repository of the package to detect if there is any new release. Compare the latest release from official source with the latest release in your local repository. If new release is detected, then trigger the workflow to build new release for your required environment. In this example, I have used cron job to schedule this workflow. Refer this workflow used for polling official Terraform repository.

2. Building and publishing new release

This workflow will be triggered only when the previous workflow detects new release in the official package repository. The goal here is to simply build the new version of the package in the required environment. In this approach, I have used GitHub Action run-on-arch-action which is responsible for executing commands on non-x86 architectures via QEMU. It takes architecture, distribution and commands to be executed as input parameters. In this example, we are mounting volume to save the built artifact for Terraform.

Next, we need to create release for the artifacts built in the required environment. In this approach, I have used GitHub Action release-action for creating release and uploading built artifact to it. This action also allows release updates.

That’s all folks! Thank you for reading. I hope you found this tutorial helpful :)