diff --git a/.bazelrc b/.bazelrc index d1e338ba..05172656 100644 --- a/.bazelrc +++ b/.bazelrc @@ -78,3 +78,17 @@ test:asan_ubsan_lsan --copt -g3 test:asan_ubsan_lsan --platform_suffix=asan_ubsan_lsan test:asan_ubsan_lsan --test_env=ASAN_OPTIONS="exitcode=55 allow_addr2line=1 verbosity=1 coverage=1 check_initialization_order=1 detect_stack_use_after_return=1 print_stats=1 halt_on_error=1 allocator_may_return_null=1 detect_leaks=1" test:asan_ubsan_lsan --test_env=UBSAN_OPTIONS="exitcode=55 allow_addr2line=1 verbosity=1 coverage=1 print_stacktrace=1 halt_on_error=1" + +build:clang_format --config=_bl_stub +build:clang_format --output_groups=clang_format_output +build:clang_format --aspects=@score_bazel_tools_cc//quality:defs.bzl%clang_format_aspect +build:clang_format --@score_bazel_tools_cc//quality:clang_format_config=//:clang_format_config + +build:clang_tidy --config=_bl_stub +build:clang_tidy --@score_bazel_tools_cc//quality:quality_clang_tidy_config=//:clang_tidy_config +build:clang_tidy --aspects=@score_bazel_tools_cc//quality:defs.bzl%quality_clang_tidy_aspect +build:clang_tidy --build_tag_filters="-tidy_suite" +build:clang_tidy --force_pic +build:clang_tidy --incompatible_enable_cc_toolchain_resolution +build:clang_tidy --output_groups=clang_tidy_output +build:clang_tidy --verbose_failures diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..92df3942 --- /dev/null +++ b/.clang-format @@ -0,0 +1,48 @@ +# For changes please present first the motivation in the TAL round +BasedOnStyle: Google +AccessModifierOffset: -2 +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +# Empty is required in AllowShortFunctionsOnASingleLine over Inline because Inline contradicts with AUTOSAR rule A7-1-7 +# Such rule is no longer existing in MISRA C++:2023, once we are fully migrated to MISRA C++:2023, switching to Inline +# could be reconsidered +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: false +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false +BreakBeforeBraces: Custom +ColumnLimit: 120 +DerivePointerAlignment: false +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^(<|")(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdargh|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h(>|")$' + Priority: 2 + - Regex: '^(<|")(cstdlib|csignal|csetjmp|cstdarg|typeinfo|typeindex|type_traits|bitset|functional|utility|ctime|chrono|cstddef|initializer_list|tuple|any|optional|variant|new|memory|scoped_allocator|memory_resource|climits|cfloat|cstdint|cinttypes|limits|exception|stdexcept|cassert|system_error|cerrno|cctype|cwctype|cstring|cwchar|cuchar|string|string_view|array|vector|deque|list|forward_list|set|map|unordered_set|unordered_map|stack|queue|algorithm|execution|teratorslibrary|iterator|cmath|complex|valarray|random|numeric|ratio|cfenv|iosfwd|ios|istream|ostream|iostream|fstream|sstream|strstream|iomanip|streambuf|cstdio|locale|clocale|codecvt|regex|atomic|thread|mutex|shared_mutex|future|condition_variable|filesystem|ciso646|ccomplex|ctgmath|cstdalign|cstdbool)(>|")$' + Priority: 3 + - Regex: '^(<|").*(>|")$' + Priority: 1 +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +QualifierAlignment: Left +CommentPragmas: '^.*A2Lfactory:' +--- +# Make sure language specific settings are below the generic settings to be compatible to all languages. +Language: Cpp +Standard: c++17 diff --git a/.clang-tidy-minimal b/.clang-tidy-minimal new file mode 100644 index 00000000..038a27c4 --- /dev/null +++ b/.clang-tidy-minimal @@ -0,0 +1,60 @@ +--- +Checks: > + -*, + misc-confusable-identifiers, + misc-misleading-bidirectional, + misc-misleading-identifier, + misc-uniqueptr-reset-release, + misc-unused-alias-decls, + readability-avoid-nested-conditional-operator, + readability-const-return-type, + readability-delete-null-pointer, + readability-enum-initial-value, + readability-identifier-naming, + readability-misleading-indentation, + readability-redundant-string-init, + readability-reference-to-constructed-temporary, + readability-simplify-subscript-expr, + readability-string-compare, + readability-uniqueptr-delete-release, + +CheckOptions: + - key: misc-uniqueptr-reset-release.IncludeStyle + value: "llvm" + + - key: readability-avoid-return-with-void-value.StrictMode + value: true + + - key: readability-enum-initial-value.AllowExplicitZeroFirstInitialValue + value: true + - key: readability-enum-initial-value.AllowExplicitSequentialInitialValues + value: true + + - key: readability-identifier-naming.MacroDefinitionCase + value: UPPER_CASE + - key: readability-identifier-naming.NamespaceCase + value: lower_case + + - key: readability-simplify-subscript-expr.Types + value: > + ::score::futurecpp::basic_string_view; + ::score::futurecpp::pmr::basic_string; + ::score::futurecpp::pmr::vector; + ::score::futurecpp::span; + ::score::safecpp::basic_zstring_view; + ::std::array; + ::std::basic_string_view; + ::std::basic_string; + ::std::vector; + ::std::span + + - key: readability-string-compare.StringLikeClasses + value: > + ::score::futurecpp::basic_string_view; + ::score::futurecpp::pmr::basic_string; + ::score::safecpp::basic_zstring_view; + ::std::basic_string_view; + ::std::basic_string + + - key: readability-uniqueptr-delete-release.PreferResetCall + value: true diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index ebe7cb6a..e0e28bea 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -22,3 +22,18 @@ on: jobs: formatting-check: uses: eclipse-score/cicd-workflows/.github/workflows/format.yml@main + clang-format: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.18.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.job }} + repository-cache: true + cache-save: ${{ github.event_name == 'push' }} + - name: Bazel Build with clang-format + run: | + bazel build --config clang_format -- //... || true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..95811f81 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,39 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* +name: Linter checks +permissions: + contents: read +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: + - main + merge_group: + types: [checks_requested] +jobs: + clang-tidy: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.18.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.job }} + repository-cache: true + cache-save: ${{ github.event_name == 'push' }} + - name: Bazel Build with clang-tidy + run: | + bazel build --config clang_tidy -- //... diff --git a/BUILD b/BUILD index 09ad0cb1..411d7b4d 100644 --- a/BUILD +++ b/BUILD @@ -11,6 +11,7 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* +load("@score_bazel_tools_cc//quality:defs.bzl", "clang_format_config", "quality_clang_tidy_config") load("@score_docs_as_code//:docs.bzl", "docs") load("@score_tooling//:defs.bzl", "copyright_checker", "use_format_targets") load(":qemu.bzl", "qemu_aarch64") @@ -38,6 +39,45 @@ copyright_checker( visibility = ["//visibility:public"], ) +qemu_aarch64() + use_format_targets() -qemu_aarch64() +clang_format_config( + name = "clang_format_config", + config_file = "//:.clang-format", + target_types = [ + "cc_binary", + "cc_library", + "cc_test", + ], + visibility = ["//visibility:public"], +) + +filegroup( + name = "clang_tidy_config_files", + srcs = [ + ".clang-tidy-minimal", + ], + visibility = ["//visibility:public"], +) + +quality_clang_tidy_config( + name = "clang_tidy_config", + additional_flags = [], + clang_tidy_binary = "@llvm_toolchain//:clang-tidy", + default_feature = "strict", + dependency_attributes = [ + "deps", + "srcs", + ], + excludes = [], + feature_mapping = { + "//:.clang-tidy-minimal": "strict", + }, + target_types = [ + "cc_library", + ], + unsupported_flags = [], + visibility = ["//visibility:public"], +) diff --git a/MODULE.bazel b/MODULE.bazel index 94d7af33..a278ee1d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -79,6 +79,14 @@ bazel_dep(name = "rules_python", version = "1.8.3") PYTHON_VERSION = "3.12" python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) +python.single_version_override( + python_version = "3.8.20", + sha256 = { + "aarch64-unknown-linux-gnu": "9d8798f9e79e0fc0f36fcb95bfa28a1023407d51a8ea5944b4da711f1f75f1ed", + "x86_64-unknown-linux-gnu": "285e141c36f88b2e9357654c5f77d1f8fb29cc25132698fe35bb30d787f38e87", + }, + urls = ["https://github.com/astral-sh/python-build-standalone/releases/download/20241002/cpython-{python_version}+20241002-{platform}-{build}.tar.gz"], +) python.toolchain( #configure_coverage_tool = True, is_default = True, @@ -89,6 +97,18 @@ bazel_dep(name = "aspect_rules_py", version = "1.6.3", dev_dependency = True) bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2", dev_dependency = True) bazel_dep(name = "aspect_rules_lint", version = "1.5.3", dev_dependency = True) +bazel_dep(name = "score_bazel_tools_cc", version = "0.1.0") +bazel_dep(name = "toolchains_llvm", version = "1.4.0") + +llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") +llvm.toolchain( + llvm_version = "19.1.1", + stdlib = {"linux-x86_64": "stdc++"}, +) +use_repo(llvm, "llvm_toolchain") + +register_toolchains("@llvm_toolchain//:all") + deb = use_repo_rule("@download_utils//download/deb:defs.bzl", "download_deb") deb(