Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions build_utils/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package(default_visibility = ["//visibility:public"])

exports_files(["defs.bzl"])
46 changes: 46 additions & 0 deletions build_utils/defs.bzl
Original file line number Diff line number Diff line change
@@ -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
)
6 changes: 3 additions & 3 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down