diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml new file mode 100644 index 000000000..0d9fe85ff --- /dev/null +++ b/.github/workflows/clang-tidy.yml @@ -0,0 +1,53 @@ +name: Clang-Tidy Code Scanning + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + merge_group: + types: [checks_requested] + pull_request: + +permissions: {} + +jobs: + clang-tidy: + name: Run Clang-Tidy + + runs-on: ubuntu-latest + + permissions: + contents: read + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 # Required for diffing later on + submodules: "true" + + - name: Setup sccache + uses: hendrikmuhs/ccache-action@v1.2.20 + with: + variant: sccache + + - name: Install Nix + uses: cachix/install-nix-action@v31 + + - name: Run build + # TODO(@getchoo): Figure out how to make this work with PCH + run: | + nix develop --command bash -c ' + cmake -B build -D Launcher_USE_PCH=OFF -D CMAKE_CXX_COMPILER_LAUNCHER=sccache && cmake --build build + ' + + # TODO: Use SARIF after https://github.com/psastras/sarif-rs/issues/638 is fixed + - name: Run clang-tidy-diff + env: + BASE_REF: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }} + run: | + nix develop --command bash -c ' + git diff -U0 --no-color "$BASE_REF" | clang-tidy-diff.py -p1 + ' diff --git a/CMakeLists.txt b/CMakeLists.txt index d2ef01c0c..f084fd42f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,19 @@ if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR MATCHES "^Ninja" set(CMAKE_EXPORT_COMPILE_COMMANDS ON) endif() +option(USE_CLANG_TIDY "Enable the use of clang-tidy during compilation" OFF) + +if(USE_CLANG_TIDY) + find_program(CLANG_TIDY clang-tidy OPTIONAL) + if(CLANG_TIDY) + message(STATUS "Using clang-tidy during compilation") + set(CLANG_TIDY_COMMAND "${CLANG_TIDY}" "--config-file=${CMAKE_SOURCE_DIR}/.clang-tidy") + set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND}) + else() + message(WARNING "Unable to find `clang-tidy`. Not using during compilation") + endif() +endif() + option(DEBUG_ADDRESS_SANITIZER "Enable Address Sanitizer in Debug builds" OFF) # If this is a Debug build turn on address sanitiser diff --git a/flake.nix b/flake.nix index 6e0fa5844..c8779909c 100644 --- a/flake.nix +++ b/flake.nix @@ -86,6 +86,7 @@ let pkgs = nixpkgsFor.${system}; llvm = pkgs.llvmPackages_19; + python = pkgs.python3; mkShell = pkgs.mkShell.override { inherit (llvm) stdenv; }; packages' = self.packages.${system}; @@ -137,10 +138,27 @@ inputsFrom = [ packages'.prismlauncher-unwrapped ]; - packages = with pkgs; [ - ccache + packages = [ + pkgs.ccache llvm.clang-tools - python3 # Required for `run-clang-tidy`, etc. + python # NOTE(@getchoo): Required for run-clang-tidy, etc. + + (pkgs.stdenvNoCC.mkDerivation { + pname = "clang-tidy-diff"; + inherit (llvm.clang) version; + + nativeBuildInputs = [ + pkgs.installShellFiles + python.pkgs.wrapPython + ]; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + + postInstall = "installBin ${llvm.libclang.python}/share/clang/clang-tidy-diff.py"; + postFixup = "wrapPythonPrograms"; + }) ]; cmakeBuildType = "Debug"; diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index acecf8700..361baa26d 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -818,23 +818,6 @@ SET(LAUNCHER_SOURCES KonamiCode.h KonamiCode.cpp - # Bundled resources - resources/backgrounds/backgrounds.qrc - resources/multimc/multimc.qrc - resources/pe_dark/pe_dark.qrc - resources/pe_light/pe_light.qrc - resources/pe_colored/pe_colored.qrc - resources/pe_blue/pe_blue.qrc - resources/breeze_dark/breeze_dark.qrc - resources/breeze_light/breeze_light.qrc - resources/OSX/OSX.qrc - resources/iOS/iOS.qrc - resources/flat/flat.qrc - resources/flat_white/flat_white.qrc - resources/documents/documents.qrc - resources/shaders/shaders.qrc - "${CMAKE_CURRENT_BINARY_DIR}/../${Launcher_Branding_LogoQRC}" - # Icons icons/MMCIcon.h icons/MMCIcon.cpp @@ -1305,6 +1288,7 @@ qt_add_resources(LAUNCHER_RESOURCES resources/OSX/OSX.qrc resources/iOS/iOS.qrc resources/flat/flat.qrc + resources/flat_white/flat_white.qrc resources/documents/documents.qrc resources/shaders/shaders.qrc "${CMAKE_CURRENT_BINARY_DIR}/../${Launcher_Branding_LogoQRC}"