From cc4e01f7a59d995d57cba38a84f50c2cdd3d8915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 1 Oct 2025 14:27:00 +0200 Subject: [PATCH 1/3] Add swift_c_test_library --- cc/defs.bzl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cc/defs.bzl b/cc/defs.bzl index 757c4d5..8b39217 100644 --- a/cc/defs.bzl +++ b/cc/defs.bzl @@ -579,6 +579,36 @@ def swift_cc_tool(**kwargs): native.cc_binary(**kwargs) +def swift_c_test_library(**kwargs): + """Wraps cc_library to enforce Swift test library conventions. + + Args: + **kwargs: See https://bazel.build/reference/be/c-cpp#cc_test + + The following additional attributes are supported: + + local_includes: List of local (non-public) include paths. Prefer + this to passing local includes using copts. Paths are expected to + be relative to the package this macro is called from. + """ + + _ = kwargs.pop("nocopts", []) # To handle API compatibility. + + local_includes = _construct_local_includes(kwargs.pop("local_includes", [])) + + extensions = kwargs.pop("extensions", False) + standard = kwargs.pop("standard", 99) + + kwargs["copts"] = local_includes + kwargs.get("copts", []) + _tests_warn_deprecated_declarations() + _c_standard(extensions, standard) + kwargs["data"] = kwargs.get("data", []) + _symbolizer_data() + kwargs["env"] = _symbolizer_env(kwargs.get("env", {})) + kwargs["linkstatic"] = kwargs.get("linkstatic", True) + kwargs["name"] = name + kwargs["tags"] = [TEST_LIBRARY] + kwargs.get("tags", []) + kwargs["target_compatible_with"] = kwargs.get("target_compatible_with", []) + _test_compatible_with() + + native.cc_library(**kwargs) + def swift_cc_test_library(**kwargs): """Wraps cc_library to enforce Swift test library conventions. From b3ad495b35324377a52c89fa6507ae0369ed0c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 1 Oct 2025 14:30:34 +0200 Subject: [PATCH 2/3] Fix --- cc/defs.bzl | 3 --- 1 file changed, 3 deletions(-) diff --git a/cc/defs.bzl b/cc/defs.bzl index 8b39217..0c66275 100644 --- a/cc/defs.bzl +++ b/cc/defs.bzl @@ -600,10 +600,7 @@ def swift_c_test_library(**kwargs): standard = kwargs.pop("standard", 99) kwargs["copts"] = local_includes + kwargs.get("copts", []) + _tests_warn_deprecated_declarations() + _c_standard(extensions, standard) - kwargs["data"] = kwargs.get("data", []) + _symbolizer_data() - kwargs["env"] = _symbolizer_env(kwargs.get("env", {})) kwargs["linkstatic"] = kwargs.get("linkstatic", True) - kwargs["name"] = name kwargs["tags"] = [TEST_LIBRARY] + kwargs.get("tags", []) kwargs["target_compatible_with"] = kwargs.get("target_compatible_with", []) + _test_compatible_with() From f0ed9201149cc403000bc42cbf8c0988f01df790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Thu, 2 Oct 2025 10:36:41 +0200 Subject: [PATCH 3/3] Fix docs --- cc/defs.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cc/defs.bzl b/cc/defs.bzl index 0c66275..3236612 100644 --- a/cc/defs.bzl +++ b/cc/defs.bzl @@ -583,7 +583,7 @@ def swift_c_test_library(**kwargs): """Wraps cc_library to enforce Swift test library conventions. Args: - **kwargs: See https://bazel.build/reference/be/c-cpp#cc_test + **kwargs: See https://bazel.build/reference/be/c-cpp#cc_library The following additional attributes are supported: