Skip to content
Open
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
34 changes: 34 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Checks: >
-*,
bugprone-*,
performance-*,
modernize-*,
-readability-braces-around-statements,
readability-misleading-indentation,
readability-redundant-smartptr-get,
-modernize-use-trailing-return-type,
-modernize-avoid-c-arrays,
-modernize-use-nodiscard,
-bugprone-easily-swappable-parameters

# These warnings have determined to be critical and are as such treated as errors
WarningsAsErrors: >
clang-analyzer-*,
bugprone-use-after-move,
bugprone-dangling-handle,
bugprone-infinite-loop,
bugprone-narrowing-conversions,
bugprone-undefined-memory-manipulation,
bugprone-move-forwarding-reference,
bugprone-incorrect-roundings,
bugprone-sizeof-expression,
bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-memset-usage,

HeaderFilterRegex: '(include/livekit|src|bridge/(include|src)|examples)'

FormatStyle: file

CheckOptions:
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
115 changes: 99 additions & 16 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ on:

permissions:
contents: read
actions: read
packages: read

env:
CARGO_TERM_COLOR: always
Expand All @@ -53,22 +55,22 @@ jobs:
name: linux-x64
build_cmd: ./build.sh release-examples
build_dir: build-release
- os: ubuntu-24.04-arm
name: linux-arm64
build_cmd: ./build.sh release-examples
build_dir: build-release
- os: macos-latest
name: macos-arm64
build_cmd: ./build.sh release-examples
build_dir: build-release
- os: macos-latest
name: macos-x64
build_cmd: ./build.sh release-examples --macos-arch x86_64
build_dir: build-release
- os: windows-latest
name: windows-x64
build_cmd: .\build.cmd release-examples
build_dir: build-release
# - os: ubuntu-24.04-arm
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note to remove

# name: linux-arm64
# build_cmd: ./build.sh release-examples
# build_dir: build-release
# - os: macos-latest
# name: macos-arm64
# build_cmd: ./build.sh release-examples
# build_dir: build-release
# - os: macos-latest
# name: macos-x64
# build_cmd: ./build.sh release-examples --macos-arch x86_64
# build_dir: build-release
# - os: windows-latest
# name: windows-x64
# build_cmd: .\build.cmd release-examples
# build_dir: build-release

name: Build (${{ matrix.name }})
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -244,6 +246,16 @@ jobs:
${{ matrix.build_dir }}/bin/
retention-days: 7

- name: Upload compile database (for clang-tidy)
if: matrix.name == 'linux-x64'
uses: actions/upload-artifact@v4
with:
name: compile-database
path: |
${{ matrix.build_dir }}/compile_commands.json
${{ matrix.build_dir }}/generated/
retention-days: 1

# ---------- Cleanup ----------
- name: Clean after build (best-effort)
if: always()
Expand Down Expand Up @@ -382,3 +394,74 @@ jobs:
cmake -S . -B build -DLIVEKIT_LOCAL_SDK_DIR=/opt/livekit-sdk
cmake --build build --parallel
'

clang-tidy:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could i buy you a beer to put this clang tidy work into cpp-example-collection as well? 🙏🏼 🍻

name: clang-tidy
needs: build
runs-on: ubuntu-latest
continue-on-error: false
if: ${{ !cancelled() }}
permissions:
contents: read
pull-requests: write

steps:
- name: Checkout (with submodules)
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Install dependencies
run: |
set -eux
sudo apt-get update
sudo apt-get install -y \
clang-tidy \
llvm-dev libclang-dev clang \
libssl-dev \
libprotobuf-dev protobuf-compiler \
libabsl-dev \
libspdlog-dev \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we already have a lot of these deps in other stages -- should we just add clang-tidy to a stage(s) that already has deps of the lib?

libva-dev libdrm-dev libgbm-dev libx11-dev libgl1-mesa-dev \
libxext-dev libxcomposite-dev libxdamage-dev libxfixes-dev \
libxrandr-dev libxi-dev libxkbcommon-dev \
libasound2-dev libpulse-dev \
libwayland-dev libdecor-0-dev

- name: Download compile database
uses: actions/download-artifact@v4
with:
name: compile-database
path: build-release/

- name: Run clang-tidy
uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: ''
tidy-checks: ''
database: build-release
files-changed-only: false
lines-changed-only: false
ignore: 'build-*|client-sdk-rust|vcpkg_installed'
file-annotations: true
thread-comments: update
step-summary: true
tidy-review: true
passive-reviews: true
no-lgtm: true

- name: Check warning thresholds
env:
TIDY_FINDINGS: ${{ steps.linter.outputs.clang-tidy-checks-failed }}
MAX_TIDY_FINDINGS: '396'
run: |
echo "clang-tidy findings: ${TIDY_FINDINGS}"
if [ "${TIDY_FINDINGS}" -gt "${MAX_TIDY_FINDINGS}" ]; then
echo "::warning::clang-tidy found ${TIDY_FINDINGS} issue(s), threshold is ${MAX_TIDY_FINDINGS}"
exit 1
fi
echo "clang-tidy findings within threshold"
6 changes: 5 additions & 1 deletion bridge/src/bridge_audio_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ BridgeAudioTrack::BridgeAudioTrack(
: name_(std::move(name)), sample_rate_(sample_rate),
num_channels_(num_channels), source_(std::move(source)),
track_(std::move(track)), publication_(std::move(publication)),
participant_(participant) {}
participant_(participant) {
std::cout << "Bad name use: " << name << "\n"; // Should invoke clang-tidy warning
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy diagnostic

bridge/src/bridge_audio_track.cpp:42:42: error: [bugprone-use-after-move]

'name' used after it was moved

   42 |         std::cout << "Bad name use: " << name << "\n"; // Should invoke clang-tidy warning
      |                                          ^
/home/runner/work/client-sdk-cpp/client-sdk-cpp/bridge/src/bridge_audio_track.cpp:38:7: note: move occurred here
   38 |     : name_(std::move(name)), sample_rate_(sample_rate),
      |       ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy diagnostic

bridge/src/bridge_audio_track.cpp:42:42: error: [bugprone-use-after-move]

'name' used after it was moved

   42 |         std::cout << "Bad name use: " << name << "\n"; // Should invoke clang-tidy warning
      |                                          ^
/home/runner/work/client-sdk-cpp/client-sdk-cpp/bridge/src/bridge_audio_track.cpp:38:7: note: move occurred here
   38 |     : name_(std::move(name)), sample_rate_(sample_rate),
      |       ^

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was induced just to show how this works, not an actual issue on this branch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy diagnostic

bridge/src/bridge_audio_track.cpp:42:42: error: [bugprone-use-after-move]

'name' used after it was moved

   42 |         std::cout << "Bad name use: " << name << "\n"; // Should invoke clang-tidy warning
      |                                          ^
/home/runner/work/client-sdk-cpp/client-sdk-cpp/bridge/src/bridge_audio_track.cpp:38:7: note: move occurred here
   38 |     : name_(std::move(name)), sample_rate_(sample_rate),
      |       ^


while(true); // should invoke another warning
}

BridgeAudioTrack::~BridgeAudioTrack() { release(); }

Expand Down
2 changes: 1 addition & 1 deletion src/ffi_client.cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now way we only had two files NOT clang tidy'd 😅

Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void FfiClient::PushEvent(const proto::FfiEvent &event) const {

void LivekitFfiCallback(const uint8_t *buf, size_t len) {
proto::FfiEvent event;
event.ParseFromArray(buf, len);
event.ParseFromArray(buf, static_cast<int>(len)); // TODO: this fixes for now, what if len exceeds int?

FfiClient::instance().PushEvent(event);
}
Expand Down
Loading