diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..5171352 --- /dev/null +++ b/.clang-tidy @@ -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' diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 1a7dfef..62b1fb7 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -35,6 +35,8 @@ on: permissions: contents: read + actions: read + packages: read env: CARGO_TERM_COLOR: always @@ -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 + # 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 }} @@ -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() @@ -382,3 +394,74 @@ jobs: cmake -S . -B build -DLIVEKIT_LOCAL_SDK_DIR=/opt/livekit-sdk cmake --build build --parallel ' + + clang-tidy: + 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 \ + 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" diff --git a/bridge/src/bridge_audio_track.cpp b/bridge/src/bridge_audio_track.cpp index 5816cfc..0e93581 100644 --- a/bridge/src/bridge_audio_track.cpp +++ b/bridge/src/bridge_audio_track.cpp @@ -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 + + while(true); // should invoke another warning + } BridgeAudioTrack::~BridgeAudioTrack() { release(); } diff --git a/src/ffi_client.cpp b/src/ffi_client.cpp index 9c20691..82f4d1c 100644 --- a/src/ffi_client.cpp +++ b/src/ffi_client.cpp @@ -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(len)); // TODO: this fixes for now, what if len exceeds int? FfiClient::instance().PushEvent(event); }