Skip to content

Commit

Permalink
Add ctx argument to cc_common.configure_features
Browse files Browse the repository at this point in the history
In order to migrate C++ rules to platforms, we need the access to the C++
configuration fragment in Starlark APIs. All existing APIs have already access
to it, but cc_common.configure_features doesn't. This change adds a
ctx argument to configure_features.

This is the migration needed for
bazelbuild/bazel#7793, and is part of the effort for
bazelbuild/bazel#6516.

If the rule doesn't depend on cpp fragment yet, you will have to add `fragments
=['cpp']` argument to the rule() call.

Note that this behavior is only available in Bazel 0.25 (to be released this month).

RELNOTES: None.
PiperOrigin-RevId: 247206987
  • Loading branch information
Googler authored and swiple-rules-gardener committed May 8, 2019
1 parent cc802a0 commit 7cf1ce4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion swift/internal/api.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def _compile(
swiftmodule = swiftmodule,
)

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++
Expand All @@ -664,6 +664,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.
Expand Down Expand Up @@ -702,6 +703,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,
Expand Down
1 change: 1 addition & 0 deletions swift/internal/swift_binary_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = swift_toolchain,
unsupported_features = unsupported_features,
Expand Down
2 changes: 2 additions & 0 deletions swift/internal/swift_c_module_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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,
Expand Down Expand Up @@ -199,4 +200,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"],
)
2 changes: 2 additions & 0 deletions swift/internal/swift_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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 = swift_toolchain,
unsupported_features = unsupported_features,
Expand Down Expand Up @@ -378,5 +379,6 @@ swift_grpc_library(
)
```
""",
fragments = ["cpp"],
implementation = _swift_grpc_library_impl,
)
2 changes: 2 additions & 0 deletions swift/internal/swift_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _swift_library_impl(ctx):
deps = ctx.attr.deps + swift_toolchain.implicit_deps

feature_configuration = swift_common.configure_features(
ctx = ctx,
requested_features = ctx.features,
swift_toolchain = swift_toolchain,
unsupported_features = ctx.disabled_features,
Expand Down Expand Up @@ -182,4 +183,5 @@ Compiles and links Swift code into a static library and Swift module.
""",
outputs = swift_library_output_map,
implementation = _swift_library_impl,
fragments = ["cpp"],
)
1 change: 1 addition & 0 deletions swift/internal/swift_module_alias.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ following dependencies instead:\n\n""".format(

swift_toolchain = ctx.attr._toolchain[SwiftToolchainInfo]
feature_configuration = swift_common.configure_features(
ctx = ctx,
requested_features = ctx.features,
swift_toolchain = swift_toolchain,
unsupported_features = ctx.disabled_features,
Expand Down
2 changes: 2 additions & 0 deletions swift/internal/swift_protoc_gen_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def _swift_protoc_gen_aspect_impl(target, aspect_ctx):
# support libraries like the SwiftProtobuf runtime as deps to the compile
# action.
feature_configuration = swift_common.configure_features(
ctx = aspect_ctx,
requested_features = aspect_ctx.features + [SWIFT_FEATURE_NO_GENERATED_HEADER],
swift_toolchain = swift_toolchain,
unsupported_features = aspect_ctx.disabled_features + [SWIFT_FEATURE_ENABLE_TESTING],
Expand Down Expand Up @@ -463,5 +464,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,
)

0 comments on commit 7cf1ce4

Please sign in to comment.