bazel: Enable the layering check for Sense
Fix all violations in the same CL.
Bug: 219091175
Change-Id: I824b4f9e356124e787288c0592b814861944c78a
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/showcase/sense/+/261652
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Ted Pudlik <tpudlik@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
diff --git a/.bazelrc b/.bazelrc
index 83be71c..fd91da2 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -59,6 +59,10 @@
# workaround.
common --legacy_external_runfiles=True
+# Enable layering check support. See
+# https://pigweed.dev/pw_toolchain/bazel.html#layering-check.
+common --@pigweed//pw_toolchain/host_clang:layering_check
+
# C++ toolchain configuration
# ===========================
diff --git a/REPO.bazel b/REPO.bazel
new file mode 100644
index 0000000..3b8c73e
--- /dev/null
+++ b/REPO.bazel
@@ -0,0 +1,27 @@
+# Copyright 2025 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+"""Repository-wide configuration.
+
+See https://bazel.build/external/overview#repo.bazel. This file is used in
+particular to enable toolchain features that we want to enable for all Pigweed
+targets, but not for any external dependencies also compiled with Bazel.
+"""
+
+repo(
+ # Any C++ toolchain features enabled here will be enabled when compiling
+ # Sense, but not when compiling any dependencies hosted in external
+ # repositories.
+ features = ["layering_check"],
+)
+
diff --git a/apps/blinky/BUILD.bazel b/apps/blinky/BUILD.bazel
index 53ff154..79d928a 100644
--- a/apps/blinky/BUILD.bazel
+++ b/apps/blinky/BUILD.bazel
@@ -25,8 +25,9 @@
deps = [
"//modules/blinky:service",
"//modules/board:service",
- "//system:worker",
"//system",
+ "//system:headers",
+ "//system:worker",
"@pigweed//pw_async2:system_time_provider",
"@pigweed//pw_log",
"@pigweed//pw_system:async",
diff --git a/apps/factory/BUILD.bazel b/apps/factory/BUILD.bazel
index 933e51d..b5f54c3 100644
--- a/apps/factory/BUILD.bazel
+++ b/apps/factory/BUILD.bazel
@@ -33,6 +33,7 @@
"//modules/board:service",
"//modules/pubsub:service",
"//modules/proximity:manager",
+ "//system:headers",
"//system:pubsub",
"//system:worker",
"//system",
@@ -106,6 +107,7 @@
"//modules/buttons:manager",
"//modules/light:sensor",
"//modules/proximity:sensor",
+ "@pigweed//pw_status",
],
)
diff --git a/apps/production/BUILD.bazel b/apps/production/BUILD.bazel
index b267b51..fdcde5c 100644
--- a/apps/production/BUILD.bazel
+++ b/apps/production/BUILD.bazel
@@ -32,10 +32,12 @@
"//modules/pubsub:service",
"//modules/state_manager",
"//modules/state_manager:service",
+ "//system:headers",
"//system:pubsub",
"//system:worker",
"//system",
":threads",
+ ":threads_headers",
"@pigweed//pw_assert:check",
"@pigweed//pw_async2:system_time_provider",
"@pigweed//pw_log",
diff --git a/device/BUILD.bazel b/device/BUILD.bazel
index 45943e3..1a14677 100644
--- a/device/BUILD.bazel
+++ b/device/BUILD.bazel
@@ -50,6 +50,7 @@
"//modules/light:sensor",
"//modules/proximity:sensor",
"@pigweed//pw_chrono:system_clock",
+ "@pigweed//pw_i2c:address",
"@pigweed//pw_i2c:initiator",
"@pigweed//pw_i2c:register_device",
"@pigweed//pw_result",
diff --git a/modules/air_sensor/BUILD.bazel b/modules/air_sensor/BUILD.bazel
index 5f23327..1c950fe 100644
--- a/modules/air_sensor/BUILD.bazel
+++ b/modules/air_sensor/BUILD.bazel
@@ -31,6 +31,7 @@
],
deps = [
"//modules/pubsub:events",
+ "@pigweed//pw_assert:check",
"@pigweed//pw_metric:metric",
"@pigweed//pw_result",
"@pigweed//pw_status",
@@ -102,6 +103,8 @@
"@pigweed//pw_assert:check",
"@pigweed//pw_chrono:system_clock",
"@pigweed//pw_chrono:system_timer",
+ "@pigweed//pw_function",
+ "@pigweed//pw_status",
"@pigweed//pw_sync:thread_notification",
],
)
diff --git a/modules/blinky/BUILD.bazel b/modules/blinky/BUILD.bazel
index d5ac90b..91d3443 100644
--- a/modules/blinky/BUILD.bazel
+++ b/modules/blinky/BUILD.bazel
@@ -32,14 +32,17 @@
],
deps = [
"//modules/led:monochrome_led",
+ "//modules/led:polychrome_led",
"//modules/worker",
"//system",
+ "@pigweed//pw_allocator:allocator",
"@pigweed//pw_async2:coro",
"@pigweed//pw_async2:coro_or_else_task",
"@pigweed//pw_async2:dispatcher",
"@pigweed//pw_async2:time_provider",
"@pigweed//pw_chrono:system_clock",
"@pigweed//pw_function",
+ "@pigweed//pw_status",
"@pigweed//pw_sync:interrupt_spin_lock",
"@pigweed//pw_sync:lock_annotations",
"@pigweed//pw_system:async",
diff --git a/modules/board/BUILD.bazel b/modules/board/BUILD.bazel
index 09b5631..a713d03 100644
--- a/modules/board/BUILD.bazel
+++ b/modules/board/BUILD.bazel
@@ -75,9 +75,11 @@
":board",
":nanopb_rpc",
"//modules/worker",
+ "//system:headers",
"@pigweed//pw_chrono:system_clock",
"@pigweed//pw_chrono:system_timer",
"@pigweed//pw_log",
+ "@pigweed//pw_status",
"@pigweed//pw_work_queue",
],
)
diff --git a/modules/buttons/BUILD.bazel b/modules/buttons/BUILD.bazel
index 1eff6a5..d4a3a9c 100644
--- a/modules/buttons/BUILD.bazel
+++ b/modules/buttons/BUILD.bazel
@@ -22,6 +22,7 @@
hdrs = ["manager.h"],
deps = [
"//modules/pubsub:events",
+ "//modules/worker",
"@pigweed//pw_assert",
"@pigweed//pw_chrono:system_clock",
"@pigweed//pw_chrono:system_timer",
@@ -29,6 +30,7 @@
"@pigweed//pw_function",
"@pigweed//pw_log",
"@pigweed//pw_preprocessor",
+ "@pigweed//pw_status",
"@pigweed//pw_sync:interrupt_spin_lock",
"@pigweed//pw_sync:lock_annotations",
"@pigweed//pw_work_queue",
@@ -45,6 +47,7 @@
"//modules/worker:test_worker",
"@pigweed//pw_digital_io",
"@pigweed//pw_status",
+ "@pigweed//pw_sync:interrupt_spin_lock",
"@pigweed//pw_sync:timed_thread_notification",
"@pigweed//pw_unit_test",
],
diff --git a/modules/morse_code/BUILD.bazel b/modules/morse_code/BUILD.bazel
index f7bdd81..1f6ead7 100644
--- a/modules/morse_code/BUILD.bazel
+++ b/modules/morse_code/BUILD.bazel
@@ -40,7 +40,8 @@
"@pigweed//pw_chrono:system_clock",
"@pigweed//pw_containers:flat_map",
"@pigweed//pw_function",
- "@pigweed//pw_string",
+ "@pigweed//pw_status",
+ "@pigweed//pw_string:string",
],
)
@@ -69,6 +70,7 @@
":encoder",
":nanopb_rpc",
"@pigweed//pw_rpc",
+ "@pigweed//pw_status",
],
)
diff --git a/modules/pubsub/BUILD.bazel b/modules/pubsub/BUILD.bazel
index cc6d0d6..82e0a63 100644
--- a/modules/pubsub/BUILD.bazel
+++ b/modules/pubsub/BUILD.bazel
@@ -61,6 +61,7 @@
srcs = ["pubsub_events_test.cc"],
deps = [
":events",
+ ":pubsub",
"//modules/worker:test_worker",
"@pigweed//pw_sync:thread_notification",
],
@@ -73,7 +74,7 @@
implementation_deps = [
"@pigweed//pw_assert:check",
"@pigweed//pw_log",
- "@pigweed//pw_string",
+ "@pigweed//pw_string:util",
],
deps = [
":events",
@@ -91,6 +92,7 @@
"//modules/worker:test_worker",
"@pigweed//pw_rpc:test_helpers",
"@pigweed//pw_rpc/nanopb:client_server_testing",
+ "@pigweed//pw_rpc/nanopb:test_method_context",
],
)
diff --git a/modules/sampling_thread/BUILD.bazel b/modules/sampling_thread/BUILD.bazel
index ac9e72b..61dafd3 100644
--- a/modules/sampling_thread/BUILD.bazel
+++ b/modules/sampling_thread/BUILD.bazel
@@ -20,7 +20,11 @@
hdrs = ["sampling_thread.h"],
implementation_deps = [
"//system",
+ "//system:headers",
"//system:pubsub",
+ "@pigweed//pw_assert:check",
"@pigweed//pw_chrono:system_clock",
+ "@pigweed//pw_log",
+ "@pigweed//pw_thread:sleep",
],
)
diff --git a/modules/state_manager/BUILD.bazel b/modules/state_manager/BUILD.bazel
index c60ec4b..ed9f4b9 100644
--- a/modules/state_manager/BUILD.bazel
+++ b/modules/state_manager/BUILD.bazel
@@ -59,7 +59,8 @@
deps = [
":nanopb_rpc",
"//modules/pubsub:events",
- "@pigweed//pw_string",
+ "@pigweed//pw_assert:check",
+ "@pigweed//pw_string:util",
"@pigweed//pw_sync:interrupt_spin_lock",
"@pigweed//pw_sync:lock_annotations",
],
diff --git a/modules/worker/BUILD.bazel b/modules/worker/BUILD.bazel
index aa23525..851f906 100644
--- a/modules/worker/BUILD.bazel
+++ b/modules/worker/BUILD.bazel
@@ -29,6 +29,9 @@
hdrs = ["test_worker.h"],
deps = [
":worker",
+ "@pigweed//pw_assert:check",
+ "@pigweed//pw_function",
+ "@pigweed//pw_log",
"@pigweed//pw_thread:test_thread_context",
"@pigweed//pw_thread:thread",
"@pigweed//pw_unit_test",
diff --git a/targets/host/BUILD.bazel b/targets/host/BUILD.bazel
index 01edf9e..91a78d5 100644
--- a/targets/host/BUILD.bazel
+++ b/targets/host/BUILD.bazel
@@ -29,12 +29,14 @@
"//modules/led:polychrome_led_fake",
"//modules/light:fake_sensor",
"//modules/proximity:fake_sensor",
+ "@pigweed//pw_assert:check",
"@pigweed//pw_channel",
"@pigweed//pw_channel:stream_channel",
"@pigweed//pw_digital_io",
"@pigweed//pw_multibuf:simple_allocator",
"@pigweed//pw_system:async",
"@pigweed//pw_system:io",
+ "@pigweed//pw_thread_stl:thread",
],
target_compatible_with = incompatible_with_mcu(),
deps = ["//system:headers"],
diff --git a/targets/rp2/BUILD.bazel b/targets/rp2/BUILD.bazel
index 38578c1..4bf7f8b 100644
--- a/targets/rp2/BUILD.bazel
+++ b/targets/rp2/BUILD.bazel
@@ -150,6 +150,7 @@
testonly = True,
srcs = ["unit_test_rpc_main.cc"],
deps = [
+ "//system:headers",
"//system:worker",
"//system",
"@pigweed//pw_log",