smish.dev
"Custom Compiler Explorer Instance"

Overview

Compiler Explorer is an incredibly useful web-based tool for quickly prototyping, sharing, analyzing, and assessing portability of C++ code (but it also works with other languages as well). The official website maintains a specific set of different compilers to test on, and also includes a selection of commonly-used C++ libraries (e.g. abseil, boost, enoki, google benchmark, etc.) to enable users to write more complicated code without going through the headache of manually installing libraries and managing their dependencies.

Compiler Explorer is also open-source software:

https://github.com/compiler-explorer/compiler-explorer

so, it's easy to get a copy, and run it locally. There are a handful of reasons one might be interested in using it locally, as opposed to going through the official website:

The steps below were what I did to set up a local instance of compiler explorer, and customize it for my specific needs.

Running Compiler Explorer Locally

The first step is to clone a copy of compiler explorer from its repo

It is a Node.js-based project, so (at the time this was written) it requires node 16 LTS. On my ubuntu 20.04 machine, this can be done by running the following shell commands

followed by actually installing

From here, all we need to do is run the commands

This will detect some of the available compilers on your machine, and host a local instance of compiler explorer, which can be accessed by opening up http://localhost:10240/.

Customizing Compiler Explorer

The files in path/to/compiler-explorer/etc/config contain the information about where it looks to find the compilers and libraries that will be accessible from the client. For example:

So, by changing the entries in these lists, we can point it to the specific compilers we want. Similarly, setting appropriate entries for the libs variable will let us build and link against locally available libraries. Using mfem as an example, we can put the following lines in c++.defaults.properties:

note: the code above assumes that we have an available build of mfem to point at.

As far as I can tell, the different variables above have the following effects (for gcc/clang compilers):

So, when all of that is configured, we can run make (or make dev, which is supposed to build slightly faster) and we should be able to see: