diff --git a/swift/internal/api.bzl b/swift/internal/api.bzl
index 96d123316..212e02259 100644
--- a/swift/internal/api.bzl
+++ b/swift/internal/api.bzl
@@ -858,7 +858,7 @@ def _compile_as_library(
         providers = providers,
     )
 
-def _configure_features(swift_toolchain, requested_features = [], unsupported_features = []):
+def _configure_features(ctx, swift_toolchain, requested_features = [], unsupported_features = []):
     """Creates a feature configuration that should be passed to other Swift build APIs.
 
     This function calls through to `cc_common.configure_features` to configure underlying C++
@@ -867,6 +867,7 @@ def _configure_features(swift_toolchain, requested_features = [], unsupported_fe
     `swift_common.cc_feature_configuration(feature_configuration)`.
 
     Args:
+        ctx: The rule context.
         swift_toolchain: The `SwiftToolchainInfo` provider of the toolchain being used to build.
             The C++ toolchain associated with the Swift toolchain is used to create the underlying
             C++ feature configuration.
@@ -905,6 +906,7 @@ def _configure_features(swift_toolchain, requested_features = [], unsupported_fe
                  "but it is not supported by the current toolchain or rule.")
 
     cc_feature_configuration = cc_common.configure_features(
+        ctx = ctx,
         cc_toolchain = swift_toolchain.cc_toolchain_info,
         requested_features = all_requested_features,
         unsupported_features = all_unsupported_features,
diff --git a/swift/internal/swift_binary_test.bzl b/swift/internal/swift_binary_test.bzl
index bde257c7e..eb9769ecd 100644
--- a/swift/internal/swift_binary_test.bzl
+++ b/swift/internal/swift_binary_test.bzl
@@ -81,6 +81,7 @@ def _configure_features_for_binary(ctx, requested_features = [], unsupported_fea
         unsupported_features.append("gcc_coverage_map_format")
 
     return swift_common.configure_features(
+        ctx = ctx,
         requested_features = requested_features,
         swift_toolchain = toolchain,
         unsupported_features = unsupported_features,
diff --git a/swift/internal/swift_c_module_aspect.bzl b/swift/internal/swift_c_module_aspect.bzl
index dad12fe73..711d45cda 100644
--- a/swift/internal/swift_c_module_aspect.bzl
+++ b/swift/internal/swift_c_module_aspect.bzl
@@ -123,6 +123,7 @@ def _swift_c_module_aspect_impl(target, aspect_ctx):
     # Determine if the toolchain requires module maps to use workspace-relative paths or not.
     toolchain = aspect_ctx.attr._toolchain_for_aspect[SwiftToolchainInfo]
     feature_configuration = swift_common.configure_features(
+        ctx = aspect_ctx,
         requested_features = aspect_ctx.features,
         swift_toolchain = toolchain,
         unsupported_features = aspect_ctx.disabled_features,
@@ -198,4 +199,5 @@ This aspect is an implementation detail of the Swift build rules and is not mean
 to other rules or run independently.
 """,
     implementation = _swift_c_module_aspect_impl,
+    fragments = ["cpp"],
 )
diff --git a/swift/internal/swift_grpc_library.bzl b/swift/internal/swift_grpc_library.bzl
index 6ff476ea9..9722c9a32 100644
--- a/swift/internal/swift_grpc_library.bzl
+++ b/swift/internal/swift_grpc_library.bzl
@@ -186,6 +186,7 @@ def _swift_grpc_library_impl(ctx):
         unsupported_features.append(SWIFT_FEATURE_ENABLE_TESTING)
 
     feature_configuration = swift_common.configure_features(
+        ctx = ctx,
         requested_features = ctx.features + [SWIFT_FEATURE_NO_GENERATED_HEADER],
         swift_toolchain = toolchain,
         unsupported_features = unsupported_features,
diff --git a/swift/internal/swift_library.bzl b/swift/internal/swift_library.bzl
index 8a3b252b9..dfe786dd0 100644
--- a/swift/internal/swift_library.bzl
+++ b/swift/internal/swift_library.bzl
@@ -35,6 +35,7 @@ def _swift_library_impl(ctx):
     toolchain = ctx.attr._toolchain[SwiftToolchainInfo]
 
     feature_configuration = swift_common.configure_features(
+        ctx = ctx,
         requested_features = ctx.features,
         swift_toolchain = toolchain,
         unsupported_features = ctx.disabled_features,
@@ -93,4 +94,5 @@ Compiles and links Swift code into a static library and Swift module.
 """,
     outputs = swift_library_output_map,
     implementation = _swift_library_impl,
+    fragments = ["cpp"],
 )
diff --git a/swift/internal/swift_module_alias.bzl b/swift/internal/swift_module_alias.bzl
index 61f490941..3caf28a7f 100644
--- a/swift/internal/swift_module_alias.bzl
+++ b/swift/internal/swift_module_alias.bzl
@@ -55,6 +55,7 @@ following dependencies instead:\n\n""".format(
 
     toolchain = ctx.attr._toolchain[SwiftToolchainInfo]
     feature_configuration = swift_common.configure_features(
+        ctx = ctx,
         requested_features = ctx.features,
         swift_toolchain = toolchain,
         unsupported_features = ctx.disabled_features,
diff --git a/swift/internal/swift_protoc_gen_aspect.bzl b/swift/internal/swift_protoc_gen_aspect.bzl
index f9b82bc37..b0bc578f1 100644
--- a/swift/internal/swift_protoc_gen_aspect.bzl
+++ b/swift/internal/swift_protoc_gen_aspect.bzl
@@ -272,6 +272,7 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
         compile_deps = deps + aspect_ctx.attr._proto_support
 
         feature_configuration = swift_common.configure_features(
+            ctx = aspect_ctx,
             requested_features = aspect_ctx.features + [SWIFT_FEATURE_NO_GENERATED_HEADER],
             swift_toolchain = toolchain,
             unsupported_features = aspect_ctx.disabled_features + [SWIFT_FEATURE_ENABLE_TESTING],
@@ -360,5 +361,6 @@ provider.
 Most users should not need to use this aspect directly; it is an implementation
 detail of the `swift_proto_library` rule.
 """,
+    fragments = ["cpp"],
     implementation = _swift_protoc_gen_aspect_impl,
 )