From 81c8140bbb83f7c5c6d710b1247e0391fae9c0e7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 21 Jan 2026 13:56:23 +0000 Subject: [PATCH 1/2] feat: add strict_cc_* build rules for C++20 and warnings as errors Added `build_utils` package containing `strict_cc_library`, `strict_cc_binary`, and `strict_cc_test`. These macros wrap the native cc rules and enforce C++20 standard and warnings as errors. Platform-specific flags are applied: - Linux: -std=c++20, -Wall, -Wextra, -Wpedantic, -Werror - Windows: /std:c++20, /WX, /W4 Added `platforms` dependency to `MODULE.bazel`. Verified with a test case in `tests/strict_check`. --- MODULE.bazel | 1 + build_utils/BUILD.bazel | 3 +++ build_utils/defs.bzl | 46 ++++++++++++++++++++++++++++++++++ tests/strict_check/BUILD.bazel | 6 +++++ tests/strict_check/test.cpp | 11 ++++++++ 5 files changed, 67 insertions(+) create mode 100644 build_utils/BUILD.bazel create mode 100644 build_utils/defs.bzl create mode 100644 tests/strict_check/BUILD.bazel create mode 100644 tests/strict_check/test.cpp diff --git a/MODULE.bazel b/MODULE.bazel index d4d0cf0..43063b8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -5,6 +5,7 @@ module( bazel_dep(name = "rules_cc", version = "0.2.16") bazel_dep(name = "cpp-httplib", version = "0.22.0") +bazel_dep(name = "platforms", version = "1.0.0") bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True) bazel_dep(name = "toolchains_llvm", version = "1.6.0", dev_dependency = True) diff --git a/build_utils/BUILD.bazel b/build_utils/BUILD.bazel new file mode 100644 index 0000000..0ca983a --- /dev/null +++ b/build_utils/BUILD.bazel @@ -0,0 +1,3 @@ +package(default_visibility = ["//visibility:public"]) + +exports_files(["defs.bzl"]) diff --git a/build_utils/defs.bzl b/build_utils/defs.bzl new file mode 100644 index 0000000..4bf9c4e --- /dev/null +++ b/build_utils/defs.bzl @@ -0,0 +1,46 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") + +_LINUX_FLAGS = [ + "-std=c++20", + "-Wall", + "-Wextra", + "-Wpedantic", + "-Werror", +] + +_WINDOWS_FLAGS = [ + "/std:c++20", + "/WX", + "/W4", +] + +def _strict_copts(): + return select({ + "@platforms//os:linux": _LINUX_FLAGS, + "@platforms//os:windows": _WINDOWS_FLAGS, + "//conditions:default": _LINUX_FLAGS, + }) + +def strict_cc_library(name, copts = [], **kwargs): + """Wrapper around cc_library that enforces C++20 and warnings as errors.""" + cc_library( + name = name, + copts = _strict_copts() + copts, + **kwargs + ) + +def strict_cc_binary(name, copts = [], **kwargs): + """Wrapper around cc_binary that enforces C++20 and warnings as errors.""" + cc_binary( + name = name, + copts = _strict_copts() + copts, + **kwargs + ) + +def strict_cc_test(name, copts = [], **kwargs): + """Wrapper around cc_test that enforces C++20 and warnings as errors.""" + cc_test( + name = name, + copts = _strict_copts() + copts, + **kwargs + ) diff --git a/tests/strict_check/BUILD.bazel b/tests/strict_check/BUILD.bazel new file mode 100644 index 0000000..35d166b --- /dev/null +++ b/tests/strict_check/BUILD.bazel @@ -0,0 +1,6 @@ +load("//build_utils:defs.bzl", "strict_cc_test") + +strict_cc_test( + name = "strict_test", + srcs = ["test.cpp"], +) diff --git a/tests/strict_check/test.cpp b/tests/strict_check/test.cpp new file mode 100644 index 0000000..5cb02f6 --- /dev/null +++ b/tests/strict_check/test.cpp @@ -0,0 +1,11 @@ +#include + +consteval int get_value() { + return 42; +} + +int main() { + constexpr int val = get_value(); + std::cout << "Value: " << val << std::endl; + return 0; +} From 4ed3bba6307599dee6fc9d86c77666a6b5b8bf13 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 21 Jan 2026 14:10:41 +0000 Subject: [PATCH 2/2] feat: add strict_cc_* build rules and apply them to src/ Added `build_utils` package containing `strict_cc_library`, `strict_cc_binary`, and `strict_cc_test`. These macros wrap the native cc rules and enforce C++20 standard and warnings as errors. Platform-specific flags are applied: - Linux: -std=c++20, -Wall, -Wextra, -Wpedantic, -Werror - Windows: /std:c++20, /WX, /W4 Updated `src/BUILD.bazel` to use these new strict rules. Updated `MODULE.bazel` to include `platforms` dependency. Ran clang-format-fix to ensure code compliance. --- src/BUILD.bazel | 6 +++--- tests/strict_check/BUILD.bazel | 6 ------ tests/strict_check/test.cpp | 11 ----------- 3 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 tests/strict_check/BUILD.bazel delete mode 100644 tests/strict_check/test.cpp diff --git a/src/BUILD.bazel b/src/BUILD.bazel index b4d84ca..856112e 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -1,13 +1,13 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("//build_utils:defs.bzl", "strict_cc_binary", "strict_cc_library") -cc_library( +strict_cc_library( name = "rest_api_helper", srcs = ["hello.cpp"], hdrs = ["hello.hpp"], visibility = ["//visibility:public"], ) -cc_binary( +strict_cc_binary( name = "example_app", srcs = ["main.cpp"], deps = [":rest_api_helper"], diff --git a/tests/strict_check/BUILD.bazel b/tests/strict_check/BUILD.bazel deleted file mode 100644 index 35d166b..0000000 --- a/tests/strict_check/BUILD.bazel +++ /dev/null @@ -1,6 +0,0 @@ -load("//build_utils:defs.bzl", "strict_cc_test") - -strict_cc_test( - name = "strict_test", - srcs = ["test.cpp"], -) diff --git a/tests/strict_check/test.cpp b/tests/strict_check/test.cpp deleted file mode 100644 index 5cb02f6..0000000 --- a/tests/strict_check/test.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -consteval int get_value() { - return 42; -} - -int main() { - constexpr int val = get_value(); - std::cout << "Value: " << val << std::endl; - return 0; -}