如何 select C/C++ 编译器用于 GitHub 动作作业?

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

有没有办法 select 默认 C/C++ 编译器(例如 gcc 或 clang)用于 GitHub Actions 作业?

准确地说,我希望 CMake 在不修改 CMake 命令的情况下选择不同的编译器。

理想情况下,通过扩展构建矩阵。类似于 Node.js 版本,如官方文档中所述: https://help.github.com/en/articles/configuring-a-workflow#configuring-a-build-matrix

类似的东西:

[..]
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 看看如何使用矩阵。这是他们显示的示例片段:

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 }}

如您所见,在 matrix: 下指定一个 foo 变量然后会创建一个 matrix.foo 值,您可以在别处引用该值。所以你会做这样的事情:

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