Always validate that required features are enabled before using feature-dependent functionality. Feature flags should be the primary condition for enabling code paths, not the presence of related data or parameters.
When implementing feature-dependent behavior:
Example of proper feature validation:
# Good: Check feature first, regardless of data presence
if feature_configuration.is_enabled("cpp_modules"):
_create_cc_compile_actions_with_cpp20_module(...)
return
# Also good: Validate required features with clear error messages
def _check_cpp20_module(ctx, feature_configuration):
if len(ctx.files.module_interfaces) > 0 and not cc_common.is_enabled(
feature_configuration = feature_configuration,
feature_name = "cpp20_module",
):
fail("to use C++20 Modules, the feature cpp20_module must be enabled")
# Avoid: Making feature enablement dependent on data availability
if module_interfaces_sources and feature_configuration.is_enabled("cpp_modules"):
This approach ensures consistent behavior, prevents silent failures, and makes feature dependencies explicit and debuggable.
Enter the URL of a public GitHub repository