diff --git a/.bazelrc b/.bazelrc index 46ba4c9..5abd333 100644 --- a/.bazelrc +++ b/.bazelrc @@ -57,3 +57,10 @@ build:arm64-qnx --config=_common build:arm64-qnx --platforms=@score_bazel_platforms//:aarch64-qnx-sdp_8.0.0-posix build:arm64-qnx --extra_toolchains=@score_qcc_aarch64_toolchain//:aarch64-qnx-sdp_8.0.0 build:arm64-qnx --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_aarch64_unknown_nto_qnx800 + +# ------------------------------------------------------------------------------- +# Clang-tidy (score_cpp_policies) +# ------------------------------------------------------------------------------- +test:clang-tidy --aspects=//tools/lint:linters.bzl%clang_tidy_aspect +test:clang-tidy --output_groups=+rules_lint_report +test:clang-tidy --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..810810d --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,29 @@ +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* +Checks: >- + -*, + clang-analyzer-*, + cert-*, + cppcoreguidelines-*, + bugprone-*, + misc-*, + performance-*, + readability-*, + modernize-* + +WarningsAsErrors: >- + clang-analyzer-* + +HeaderFilterRegex: 'score/test_scenarios_cpp/' + +FormatStyle: none diff --git a/.github/workflows/build_scenarios.yml b/.github/workflows/build_scenarios.yml index c9364cd..e2717d1 100644 --- a/.github/workflows/build_scenarios.yml +++ b/.github/workflows/build_scenarios.yml @@ -35,3 +35,34 @@ jobs: - name: Run tests run: | bazel test //... --config=x86_64-linux + + clang-tidy: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.15.0 + with: + bazelisk-version: 1.26.0 + + - name: Run clang-tidy + run: | + bazel test --config=clang-tidy //score/test_scenarios_cpp:clang_tidy + + clippy: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@1.92.0 + with: + components: clippy + + - name: Run clippy + working-directory: score/test_scenarios_rust + run: | + cargo clippy --locked --all-targets -- -D warnings diff --git a/BUILD b/BUILD index a6bda84..c1d49eb 100644 --- a/BUILD +++ b/BUILD @@ -13,6 +13,8 @@ load("@rules_python//python:pip.bzl", "compile_pip_requirements") load("@score_tooling//:defs.bzl", "setup_starpls") +exports_files([".clang-tidy"]) + setup_starpls( name = "starpls_server", visibility = ["//visibility:public"], diff --git a/MODULE.bazel b/MODULE.bazel index 778be38..2406d14 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -20,7 +20,7 @@ module( bazel_dep(name = "rules_python", version = "1.4.1") bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "rules_cc", version = "0.1.1") -bazel_dep(name = "aspect_rules_lint", version = "1.0.3") +bazel_dep(name = "aspect_rules_lint", version = "2.5.0", dev_dependency = True) bazel_dep(name = "buildifier_prebuilt", version = "7.3.1") bazel_dep(name = "platforms", version = "1.0.0") @@ -32,9 +32,12 @@ bazel_dep(name = "score_rust_policies", version = "0.0.5") # Toolchains and extensions bazel_dep(name = "rules_rust", version = "0.68.1-score") -bazel_dep(name = "score_bazel_cpp_toolchains", version = "0.5.1", dev_dependency = True) +bazel_dep(name = "score_bazel_cpp_toolchains", version = "0.5.4", dev_dependency = True) bazel_dep(name = "score_toolchains_rust", version = "0.8.0", dev_dependency = True) +bazel_dep(name = "score_cpp_policies", version = "0.1.1", dev_dependency = True) +bazel_dep(name = "toolchains_llvm", version = "1.8.0", dev_dependency = True) + # Others gcc = use_extension("@score_bazel_cpp_toolchains//extensions:gcc.bzl", "gcc", dev_dependency = True) gcc.toolchain( @@ -53,7 +56,7 @@ gcc.toolchain( ) gcc.toolchain( name = "score_qcc_x86_64_toolchain", - sdp_version = "8.0.0", + sdp_version = "8.0.4", target_cpu = "x86_64", target_os = "qnx", use_default_package = True, @@ -61,7 +64,7 @@ gcc.toolchain( ) gcc.toolchain( name = "score_qcc_aarch64_toolchain", - sdp_version = "8.0.0", + sdp_version = "8.0.4", target_cpu = "aarch64", target_os = "qnx", use_default_package = True, @@ -75,6 +78,22 @@ use_repo( "score_qcc_x86_64_toolchain", ) +llvm = use_extension( + "@toolchains_llvm//toolchain/extensions:llvm.bzl", + "llvm", + dev_dependency = True, +) +llvm.toolchain( + cxx_standard = {"": "c++17"}, + link_libs = {"": [ + "-lrt", + "-latomic", + ]}, + llvm_version = "22.1.7", + stdlib = {"": "stdc++"}, +) +use_repo(llvm, "llvm_toolchain") + PYTHON_VERSION = "3.12" python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) diff --git a/score/test_scenarios_cpp/BUILD b/score/test_scenarios_cpp/BUILD index 3461231..983eaf9 100644 --- a/score/test_scenarios_cpp/BUILD +++ b/score/test_scenarios_cpp/BUILD @@ -12,6 +12,7 @@ # ******************************************************************************* load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_cc//cc:cc_test.bzl", "cc_test") +load("//tools/lint:linters.bzl", "clang_tidy_test") cc_library( name = "test_scenarios_cpp", @@ -52,3 +53,11 @@ cc_test( "@googletest//:gtest_main", ], ) + +clang_tidy_test( + name = "clang_tidy", + srcs = [ + ":test_scenarios_cpp", + ], + tags = ["manual"], +) diff --git a/tools/lint/BUILD.bazel b/tools/lint/BUILD.bazel new file mode 100644 index 0000000..206c4e4 --- /dev/null +++ b/tools/lint/BUILD.bazel @@ -0,0 +1,17 @@ +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +exports_files( + ["linters.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tools/lint/linters.bzl b/tools/lint/linters.bzl new file mode 100644 index 0000000..f5a9ddc --- /dev/null +++ b/tools/lint/linters.bzl @@ -0,0 +1,23 @@ +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +"""Clang-tidy aspect and test rule, using the score_cpp_policies baseline.""" + +load("@score_cpp_policies//clang_tidy:defs.bzl", "make_clang_tidy_aspect", "make_clang_tidy_test") + +clang_tidy_aspect = make_clang_tidy_aspect( + binary = Label("@llvm_toolchain//:clang-tidy"), + local_configs = [Label("//:.clang-tidy")], +) + +clang_tidy_test = make_clang_tidy_test(aspect = clang_tidy_aspect)