Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build Status

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- uses: ./setup

- name: Verify tools (Linux / macOS)
run: |
clang-format --dry-run --Werror tests/hello.cpp
ccache c++ tests/hello.cpp -o hello
./hello
ccache --show-stats
shell: bash
if: runner.os != 'Windows'

- name: Verify tools (Windows)
run: |
if not "%CC%"=="sccache cl" exit /b 1
where cl
where sccache
clang-format --dry-run --Werror tests\hello.cpp
sccache cl /nologo /EHsc tests\hello.cpp /Fe:hello.exe
hello.exe
sccache --show-stats
shell: cmd
if: runner.os == 'Windows'
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# cpp

Helper actions for C++ projects

| Name | Action Reference | Description |
|:-----|:-----------------|:------------|
| [setup](./setup) | actions-ext/cpp/setup | Setup CCache (Linux / Macos only) |
| Name | Action Reference | Description |
| :--------------- | :-------------------- | :------------------------------------------------------------------ |
| [setup](./setup) | actions-ext/cpp/setup | Configure MSVC, clang-format, and compiler caching across platforms |
19 changes: 16 additions & 3 deletions setup/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# setup
An action to setup and enable CCache for use with C++ compilation.

Configure a C++ toolchain for GitHub Actions:

- Activate MSVC on Windows.
- Install clang-format when unavailable.
- Configure ccache on Linux and macOS.
- Configure sccache and set `CC`/`CXX` for MSVC on Windows.

## Usage

```yaml
- name: Setup C++
uses: actions-ext/cpp/setup@v1
uses: actions-ext/cpp/setup@51c484ef64088c62434226039d0e3359f5fc8df6
```

**NOTE:** Windows setup is not yet available.
## Inputs

| Name | Default | Description |
| :------------- | :------ | :------------------------------------- |
| `cache` | `true` | Enable compiler caching. |
| `cache_key` | `cpp` | Additional compiler cache key. |
| `clang_format` | `true` | Install clang-format when unavailable. |
| `msvc_arch` | `x64` | MSVC target architecture on Windows. |
76 changes: 60 additions & 16 deletions setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,70 @@
name: Setup C++
description: 'Ensure C++ utilities are available, and setup CCache caching'
description: 'Configure the C++ toolchain, clang-format, and compiler caching'

inputs:
cache:
description: 'Enable ccache on Linux/macOS and sccache on Windows'
default: 'true'
cache_key:
description: 'Additional compiler cache key'
default: 'cpp'
clang_format:
description: 'Install clang-format when it is not already available'
default: 'true'
msvc_arch:
description: 'MSVC target architecture on Windows'
default: 'x64'

runs:
using: 'composite'
steps:
##########
# Caches #
##########
################
################
# CCache Assets
- name: Setup CCache Cache
uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23
- name: Configure MSVC
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
with:
key: ${{ runner.os }}-ccache-
arch: ${{ inputs.msvc_arch }}
if: ${{ runner.os == 'Windows' }}

- name: Install clang-format (Linux)
shell: bash
run: |
if ! command -v clang-format >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install --yes clang-format
fi
clang-format --version
if: ${{ inputs.clang_format == 'true' && runner.os == 'Linux' }}

- name: Use CCache for builds (Linux)
- name: Install clang-format (macOS)
shell: bash
run: echo 'PATH=/usr/lib/ccache:'"$PATH" >> $GITHUB_ENV
if: ${{ runner.os == 'Linux' }}
run: |
if ! command -v clang-format >/dev/null 2>&1; then
brew install clang-format
fi
clang-format --version
if: ${{ inputs.clang_format == 'true' && runner.os == 'macOS' }}

- name: Install clang-format (Windows)
shell: pwsh
run: |
if (-not (Get-Command clang-format -ErrorAction SilentlyContinue)) {
choco install llvm --no-progress --yes
$env:Path = "C:\Program Files\LLVM\bin;$env:Path"
"C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
}
clang-format --version
if: ${{ inputs.clang_format == 'true' && runner.os == 'Windows' }}

- name: Setup compiler cache
uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23
with:
key: ${{ runner.os }}-${{ inputs.cache_key }}
variant: ${{ runner.os == 'Windows' && 'sccache' || 'ccache' }}
create-symlink: ${{ runner.os != 'Windows' }}
if: ${{ inputs.cache == 'true' }}

- name: Use CCache for builds (Mac)
- name: Use sccache for MSVC
shell: bash
run: echo "PATH=$(brew --prefix)/opt/ccache/libexec:$PATH" >> $GITHUB_ENV
if: ${{ runner.os == 'macOS' }}
run: |
echo 'CC=sccache cl' >> "$GITHUB_ENV"
echo 'CXX=sccache cl' >> "$GITHUB_ENV"
if: ${{ inputs.cache == 'true' && runner.os == 'Windows' }}
6 changes: 6 additions & 0 deletions tests/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "hello\n";
return 0;
}
Loading