diff --git a/swift_cc_defs.bzl b/swift_cc_defs.bzl new file mode 100644 index 00000000..154532f5 --- /dev/null +++ b/swift_cc_defs.bzl @@ -0,0 +1,48 @@ +# Name for a unit test +UNIT = "unit" + +# Name for a integration test +INTEGRATION = "integration" + +def swift_cc_library(**kwargs): + """Wraps cc_library to enforce standards for a production library. + """ + native.cc_library(**kwargs) + +def swift_cc_tool_library(**kwargs): + """Wraps cc_library to enforce standards for a non-production library. + """ + native.cc_library(**kwargs) + +def swift_cc_binary(**kwargs): + """Wraps cc_binary to enforce standards for a production library. + """ + native.cc_binary(**kwargs) + +def swift_cc_tool(**kwargs): + """Wraps cc_binary to enforce standards for a non-production library. + """ + native.cc_binary(**kwargs) + +def swift_cc_test_library(**kwargs): + """Wraps cc_library to enforce Swift test library conventions. + """ + native.cc_library(**kwargs) + +def swift_cc_test(name, type, **kwargs): + """Wraps cc_test to enforce Swift testing conventions. + + Args: + name: A unique name for this rule. + type: Specifies whether the test is a unit or integration test. + + These are passed to cc_test as tags which enables running + these test types seperately: `bazel test --test_tag_filters=unit //...` + """ + + if not (type == UNIT or type == INTEGRATION): + fail("The 'type' attribute must be either UNIT or INTEGRATION") + + kwargs["name"] = name + kwargs["tags"] = [type] + native.cc_test(**kwargs)