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
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
BasedOnStyle: Google
Language: Cpp
Standard: c++17

# LiveKit modifications to Google style below

ColumnLimit: 120 # more width on modern screens
SpacesBeforeTrailingComments: 1 # one space for trailing namespace comments, e.g. `} // namespace foo` (Google uses 2)
Comment thread
alan-george-lk marked this conversation as resolved.
AccessModifierOffset: -2 # left-align public/protected/private with the class keyword (Google indents by 1)
40 changes: 40 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ on:
- docker/Dockerfile.base
- docker/Dockerfile.sdk
- .github/workflows/**
- .clang-format
- scripts/clang-format.sh
pull_request:
branches: ["main"]
paths:
Expand All @@ -33,6 +35,8 @@ on:
- docker/Dockerfile.base
- docker/Dockerfile.sdk
- .github/workflows/**
- .clang-format
- scripts/clang-format.sh
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -513,6 +517,42 @@ jobs:
cmake --build build --parallel
'

clang-format:
Comment thread
alan-george-lk marked this conversation as resolved.
name: clang-format
runs-on: ubuntu-latest
continue-on-error: false
permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# No submodules: scripts/clang-format.sh only walks our own src/ tree
fetch-depth: 1

- name: Install clang-format 22
run: |
set -eux
# Pin clang-format 22 to match the current macOS Homebrew LLVM
# Ubuntu 24.04's default clang-format ships with LLVM 18
sudo install -m 0755 -d /etc/apt/keyrings
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key \
| sudo tee /etc/apt/keyrings/llvm.asc >/dev/null
sudo chmod a+r /etc/apt/keyrings/llvm.asc
codename=$(lsb_release -cs)
echo "deb [signed-by=/etc/apt/keyrings/llvm.asc] http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-22 main" \
| sudo tee /etc/apt/sources.list.d/llvm-22.list >/dev/null
sudo apt-get update
sudo apt-get install -y clang-format-22
sudo ln -sf /usr/bin/clang-format-22 /usr/local/bin/clang-format
clang-format --version

- name: Run clang-format
env:
FORMAT_BLOB_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: ./scripts/clang-format.sh
Comment thread
alan-george-lk marked this conversation as resolved.

clang-tidy:
name: clang-tidy
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ All source files must have the LiveKit Apache 2.0 copyright header. Use the curr
### Readability and Performance
Code should be easy to read and understand. If a sacrifice is made for performance or readability, it should be documented.

Adhere to clang-format checks configured in `.clang-format`. Run `./scripts/clang-format.sh` if needed to confirm code styling.

### Static Analysis
Adhere to clang-tidy checks configured in `.clang-tidy`.
Adhere to clang-tidy checks configured in `.clang-tidy`. Run `./scripts/clang-tidy.sh` if needed to confirm code quality.

## Dependencies

Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,9 @@ This SDK leverages various tools and checks to ensure the highest quality of the
### Clang Tools

- `clang-tidy`: static analysis checks to catch common C++ pitfalls. See [.clang-tidy](./.clang-tidy) for the list of current checks (enforced in CI on PR)
- `clang-format`: (coming soon) code formatting and style consistency
- `clang-format`: code formatting and style consistency. See [.clang-format](./.clang-format) for the list of style configurations (enforced in CI on PR)

> **Note**: clang-tidy is not currently supported on Windows for this project because the Visual Studio CMake generator does not produce the compile_commands.json database that clang-tidy requires.
> **Note**: For Windows, `clang-tidy` is not currently supported for this project because the Visual Studio CMake generator does not produce the compile_commands.json database that `clang-tidy` requires. Similarly, `clang-format` must be installed and run manually on Windows, referencing the root `.clang-format` file.

To run locally, first install the following:

Expand All @@ -542,7 +542,13 @@ This installs `clang-format`, `clang-tidy`, and `run-clang-tidy`. Homebrew may a
sudo apt-get install clang-format clang-tidy clang-tools
```

To run:
**Pre-commit hook**

```bash
printf '#!/bin/sh\nFILES=$(git diff --cached --name-only --diff-filter=ACMR -- "*.c" "*.cc" "*.cpp" "*.cxx" "*.h" "*.hpp" "*.hxx")\n[ -z "$FILES" ] && exit 0\necho "$FILES" | xargs ./scripts/clang-format.sh --fix\necho "$FILES" | xargs git add\n' > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
```

To run `clang-tidy`:

1. Generate `compile_commands.json` and the protobuf headers via a release build:

Expand All @@ -566,6 +572,24 @@ The wrapper forwards extra arguments to `run-clang-tidy`, examples below:

Output is captured to `clang-tidy.log` at the repo root. This is done as a convenience feature, as often times the terminal buffer is not large enough for all the output.

To run `clang-format`:

```bash
./scripts/clang-format.sh
```

With no arguments, runs `clang-format` against every relevant file in the repository against defined `.clang-format` rules.

Pass flags or paths as needed, examples below:

```bash
./scripts/clang-format.sh --fix # Rewrite files in place
./scripts/clang-format.sh src/room.cpp include/livekit/room.h # Check just these files
./scripts/clang-format.sh --fix src/room.cpp # Fix just this file
```

Output is captured to `clang-format.log` at the repo root.

### Memory Checks

Run valgrind on various examples or tests to check for memory leaks and other issues.
Expand Down
Loading
Loading