简体   繁体   中英

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]
[..]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM