Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select the C/C++ compiler used for a GitHub Actions Job?

Is there a way to select the default C/C++ compiler (such as gcc or clang) for a GitHub Actions job?

To be precise, I want CMake to pick up different compilers without hacking the CMake command.

Ideally, by extending the build matrix. Similar to the Node.js version, as described in the official docs: https://help.github.com/en/articles/configuring-a-workflow#configuring-a-build-matrix

Something like that:

[..]
strategy:
  matrix:
    compiler: [gcc, clang]
[..]
like image 598
duddel Avatar asked Sep 05 '19 17:09

duddel


People also ask

What can you do with GitHub actions?

GitHub Actions. Automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you'd like, including CI/CD, and combine actions in a completely customized workflow. Quickstart Reference.

How long does it take to get started with GitHub actions?

Try out the features of GitHub Actions in 5 minutes or less. You only need a GitHub repository to create and run a GitHub Actions workflow. In this guide, you'll add a workflow that demonstrates some of the essential features of GitHub Actions.

Where can I find the GitHub actions starter workflow list?

You can browse the full list of starter workflow in the actions/starter-workflows repository. The example workflow you just added runs each time code is pushed to the branch, and shows you how GitHub Actions can work with the contents of your repository.

What can you do with a GitHub repository?

Your repository can contain multiple workflows that trigger different jobs based on different events. You can use a workflow to install software testing apps and have them automatically test your code on GitHub's runners. GitHub Actions can help you automate nearly every aspect of your application development processes.


1 Answers

https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler recommends using the CC and CXX environment variables to choose a compiler, and I like your idea of using a matrix to run under different compilers. So now we just need to look at https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix and see how to use the matrix. Here's the example snippet they show:

runs-on: ${{ matrix.os }}
strategy:
  matrix:
    os: [ubuntu-16.04, ubuntu-18.04]
    node: [6, 8, 10]
steps:
  - uses: actions/setup-node@v1
    with:
      node-version: ${{ matrix.node }}

As you can see, specifying a foo variable under matrix: then creates a matrix.foo value that you can reference elsewhere. So you'd do something like this:

name: Build master

on: [push]

strategy:
  matrix:
    compiler: [gcc, clang]
jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Run CMake
      env:
        CC: ${{ matrix.compiler }}
      run: cmake --your-args-here
like image 125
rmunn Avatar answered Nov 15 '22 22:11

rmunn