From 22ec99c51d9223712065ac35f31888db0bd8e0b0 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 15 Apr 2019 03:41:38 -0700 Subject: [PATCH] Add ctx argument to cc_common.configure_features 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 https://github.com/bazelbuild/bazel/issues/7793, and is part of the effort for https://github.com/bazelbuild/bazel/issues/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: 243587078 --- swift/internal/api.bzl | 4 +++- swift/internal/swift_binary_test.bzl | 3 +++ swift/internal/swift_c_module_aspect.bzl | 2 ++ swift/internal/swift_grpc_library.bzl | 1 + swift/internal/swift_library.bzl | 2 ++ swift/internal/swift_module_alias.bzl | 1 + swift/internal/swift_protoc_gen_aspect.bzl | 2 ++ 7 files changed, 14 insertions(+), 1 deletion(-) 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..58ab84425 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, @@ -352,6 +353,7 @@ instead of `swift_binary`. executable = True, fragments = ["cpp"], implementation = _swift_binary_impl, + fragments = ["cpp"], ) swift_test = rule( @@ -404,4 +406,5 @@ You can also disable this feature for all the tests in a package by applying it fragments = ["cpp"], test = True, implementation = _swift_test_impl, + fragments = ["cpp"], ) 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, )