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
24 changes: 24 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
BasedOnStyle: LLVM
Language: Cpp
Standard: c++20
ColumnLimit: 120
IndentWidth: 2
ContinuationIndentWidth: 4
NamespaceIndentation: All
AccessModifierOffset: -2
PointerAlignment: Right
QualifierAlignment: Left
ReferenceAlignment: Right
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Attach
InsertBraces: true
IncludeBlocks: Preserve
SortIncludes: CaseSensitive
FixNamespaceComments: true
SpaceAfterTemplateKeyword: true
...
48 changes: 48 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# Every disabled check has a reason; everything else is fixed, or NOLINT(check) with a reason where it can't be.
Checks: >
-*,
bugprone-*,
cert-*,
clang-analyzer-*,
concurrency-*,
cppcoreguidelines-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-modernize-use-trailing-return-type,
-misc-include-cleaner,
-misc-multiple-inheritance,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
-cppcoreguidelines-pro-type-static-cast-downcast

# modernize-use-trailing-return-type: libwebrtc and pybind11 APIs, which we override and mirror, use leading returns
# misc-include-cleaner: pybind11 and libwebrtc are used through umbrella headers the check maps to internal ones
# misc-multiple-inheritance: libwebrtc observer interfaces (not pure virtual) are implemented next to our bases
# cppcoreguidelines-owning-memory: libwebrtc takes raw `new` into its refcounting, and there's no GSL owner<>
# cppcoreguidelines-pro-bounds-*: libwebrtc frames and audio are raw planes with strides, indexed per sample
# cppcoreguidelines-pro-type-static-cast-downcast: libwebrtc has no RTTI, tracks are downcast by kind() as it does

WarningsAsErrors: '*'
HeaderFilterRegex: '.*/python-webrtc/cpp/src/.*'
FormatStyle: file

CheckOptions:
# running out of memory terminates anyway, and so does calling an empty std::function, a bug
bugprone-exception-escape.IgnoredExceptions: 'bad_alloc,bad_array_new_length,length_error,bad_function_call'
# pybind11 dataclass-like models (def_readwrite) are plain structs
misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
# `m` for the pybind11 module, `pc` for a peer connection, coordinates and iterators
readability-identifier-length.IgnoredVariableNames: '^(m|pc|id|it|x|y|u|v|uv|i|j)$'
readability-identifier-length.IgnoredParameterNames: '^(m|pc|id|it|x|y|u|v|uv|i|j)$'
readability-identifier-length.IgnoredLoopCounterNames: '^[ijkxy_]$'
# a width and a height, in the order everything takes them
bugprone-easily-swappable-parameters.IgnoredParameterNames: '"";iterator;Iterator;begin;Begin;end;End;first;First;last;Last;lhs;LHS;rhs;RHS;width;height'
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: true
...
38 changes: 38 additions & 0 deletions .github/scripts/tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
#
# Runs clang-tidy (see .clang-tidy) over the extension sources, against a configured (not built) tree in build/tidy.
#
# .github/scripts/tidy.sh [run-clang-tidy arguments, e.g. -fix or a file regex]
#
# The LLVM version is pinned to match clang-format in the Makefile.

set -euo pipefail

SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
BUILD="${WRTC_TIDY_BUILD_DIR:-$SRC/build/tidy}"
LLVM_VERSION=22.1.8

if [ ! -x "$BUILD/venv/bin/python" ]; then
uv venv -q "$BUILD/venv" --python 3.13
fi
uv pip install -q --python "$BUILD/venv/bin/python" cmake ninja "pybind11>=3.0" "clang-tidy==$LLVM_VERSION"
export PATH="$BUILD/venv/bin:$PATH"

# libwebrtc for Linux is compiled against Chromium's libc++, which needs Clang
if [ "$(uname)" = Linux ]; then
export CC="${CC:-clang}" CXX="${CXX:-clang++}"
fi
cmake -S "$SRC" -B "$BUILD" -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DPython_EXECUTABLE="$BUILD/venv/bin/python" \
-Dpybind11_DIR="$("$BUILD/venv/bin/python" -m pybind11 --cmakedir)" > /dev/null

EXTRA=()
if [ "$(uname)" = Darwin ]; then
# the wheel's clang doesn't know the SDK Apple Clang uses implicitly
EXTRA+=(-extra-arg=-isysroot"$(xcrun --show-sdk-path)")
fi

cd "$SRC"
python "$BUILD/venv/bin/run-clang-tidy.py" -p "$BUILD" -quiet -j "$(getconf _NPROCESSORS_ONLN)" \
${EXTRA[@]+"${EXTRA[@]}"} "$@" "$SRC/python-webrtc/cpp/src/"
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ permissions:
jobs:
lint:
runs-on: ubuntu-latest
env:
WRTC_CACHE_DIR: ${{ github.workspace }}/.wrtc-cache
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
- run: uvx ruff check
- run: uvx ruff format --check
- run: make format-check
# clang-tidy reads the libwebrtc headers, from the cache the wheels use
- uses: actions/cache@v6
with:
path: .wrtc-cache
key: libwebrtc-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('cmake/libwebrtc.cmake', 'cmake/libcxx/*.sha256') }}
- run: make tidy

sdist:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ project(python_webrtc
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# for clang-tidy (make tidy) and editors
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
# libwebrtc is linked against the static release CRT
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
Expand Down
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.PHONY: dev test asan tsan lint format stub wheels doc clean
.PHONY: dev test asan tsan lint format format-check tidy stub wheels doc clean

# pinned to the clang-tidy of .github/scripts/tidy.sh
CLANG_FORMAT := uvx clang-format==22.1.8
CPP_SRC = $(shell find python-webrtc/cpp/src -name '*.cpp' -o -name '*.h')

# editable install; the extension is rebuilt automatically on import after C++ changes
dev:
Expand All @@ -16,13 +20,21 @@ asan:
tsan:
SANITIZE=thread .github/scripts/sanitizers-macos.sh $(O)

lint:
lint: format-check
uvx ruff check
uvx ruff format --check

format:
uvx ruff check --fix
uvx ruff format
$(CLANG_FORMAT) -i $(CPP_SRC)

format-check:
@$(CLANG_FORMAT) --dry-run --Werror $(CPP_SRC)

# clang-tidy over the extension, see .clang-tidy
tidy:
.github/scripts/tidy.sh $(O)

stub:
uv run --no-sync pybind11-stubgen wrtc -o build/stubs
Expand Down
Loading
Loading