diff --git a/.bazelrc b/.bazelrc index 2be5855993..b389854378 100644 --- a/.bazelrc +++ b/.bazelrc @@ -15,6 +15,11 @@ common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry common --registry=https://bcr.bazel.build +# Clippy linting (enabled by default) +build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect +build --output_groups=+clippy_checks +build --@rules_rust//rust/settings:clippy.toml=@score_rust_policies//clippy/strict:clippy.toml + # Flags needed by score_baselibs and communication modules. # Do not add more! build --@score_baselibs//score/mw/log/flags:KRemote_Logging=False diff --git a/.github/workflows/bazel_clippy.yml b/.github/workflows/bazel_clippy.yml new file mode 100644 index 0000000000..fcd1595ee5 --- /dev/null +++ b/.github/workflows/bazel_clippy.yml @@ -0,0 +1,28 @@ +# ******************************************************************************* +# Copyright (c) 2025 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: Bazel Clippy + +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: + - main + merge_group: + types: [checks_requested] + +jobs: + bazel-clippy: + uses: eclipse-score/cicd-workflows/.github/workflows/static-analysis.yml@main + with: + bazel-target: "build //:clippy" diff --git a/BUILD b/BUILD index 2d6570fe8e..7dd8ee6768 100644 --- a/BUILD +++ b/BUILD @@ -12,6 +12,7 @@ # ******************************************************************************* load("@score_docs_as_code//:docs.bzl", "docs") +load("@rules_rust//rust:defs.bzl", "rust_clippy") docs( data = [ @@ -32,3 +33,15 @@ filegroup( srcs = ["README.md"], visibility = ["//visibility:public"], ) + +rust_clippy( + name = "clippy", + testonly = True, + tags = ["manual"], + visibility = ["//visibility:public"], + deps = [ + "//feature_integration_tests/rust_test_scenarios:rust_test_scenarios", +# "//feature_showcase/rust:kyron_example", + "//feature_showcase/rust:orch_per_example", + ], +) diff --git a/MODULE.bazel b/MODULE.bazel index 3db57550c8..c6505e672f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -63,5 +63,6 @@ git_override( # imports for the feature showcase module bazel_dep(name = "rules_rust", version = "0.61.0") +bazel_dep(name = "score_rust_policies", version = "0.0.2", dev_dependency = True) bazel_dep(name = "score_itf", version = "0.1.0") bazel_dep(name = "score_crates", version = "0.0.4") diff --git a/README.md b/README.md index 2946b1237e..0845825620 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,12 @@ bazel build --config bl-x86_64-linux \ bazel build --config bl-x86_64-linux @score_orchestrator//src/... ``` +## Clippy + +- Clippy runs by default via `.bazelrc` on all Rust targets (Rust tests may be tagged `no-clippy`). +- Use `bazel build //:clippy` if you want an explicit lint-only target, or build the Rust targets normally to see Clippy diagnostics. +- The Clippy config comes from `@score_rust_policies//clippy/strict:clippy.toml`. + ## Feature showcase examples The examples that are aiming to showcase features provided by S-CORE are located in `feature_showcase` folder. You can run them currently for host platform using `--config bl-x86_64-linux`. diff --git a/feature_integration_tests/rust_test_scenarios/BUILD b/feature_integration_tests/rust_test_scenarios/BUILD index 41f582aed7..4af52b7b07 100644 --- a/feature_integration_tests/rust_test_scenarios/BUILD +++ b/feature_integration_tests/rust_test_scenarios/BUILD @@ -16,7 +16,10 @@ load("@rules_rust//rust:defs.bzl", "rust_binary") rust_binary( name = "rust_test_scenarios", srcs = glob(["src/**/*.rs"]), - visibility = ["//feature_integration_tests/python_test_cases:__pkg__"], + visibility = [ + "//feature_integration_tests/python_test_cases:__pkg__", + "//visibility:public", + ], tags = [ "manual", ], @@ -31,4 +34,4 @@ rust_binary( "@score_crates//:serde", "@score_crates//:serde_json", ], -) \ No newline at end of file +) diff --git a/feature_integration_tests/rust_test_scenarios/src/scenarios/basic/orchestration_with_persistency.rs b/feature_integration_tests/rust_test_scenarios/src/scenarios/basic/orchestration_with_persistency.rs index a9a7641a77..17a0e86576 100644 --- a/feature_integration_tests/rust_test_scenarios/src/scenarios/basic/orchestration_with_persistency.rs +++ b/feature_integration_tests/rust_test_scenarios/src/scenarios/basic/orchestration_with_persistency.rs @@ -87,7 +87,7 @@ async fn kvs_save_cycle_number(path: String) -> Result<(), UserErrValue> { // Simple set/get. let key = "run_cycle_number"; - let last_cycle_number: u32 = kvs.get_value_as::(key).unwrap_or_else(|_| 0_u32); + let last_cycle_number: u32 = kvs.get_value_as::(key).unwrap_or(0_u32); kvs.set_value(key, last_cycle_number + 1) .expect("Failed to set value");