From b308aae57fe187c670e465591081177dbfb95960 Mon Sep 17 00:00:00 2001 From: hlopko Date: Wed, 8 May 2019 01:46:03 -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: 247171967 --- examples/my_c_archive/my_c_archive.bzl | 2 ++ examples/my_c_compile/my_c_compile.bzl | 1 + 2 files changed, 3 insertions(+) diff --git a/examples/my_c_archive/my_c_archive.bzl b/examples/my_c_archive/my_c_archive.bzl index bdb1c0e..30b313e 100644 --- a/examples/my_c_archive/my_c_archive.bzl +++ b/examples/my_c_archive/my_c_archive.bzl @@ -24,6 +24,7 @@ def _my_c_archive_impl(ctx): output_file = ctx.actions.declare_file(ctx.label.name + ".a") feature_configuration = cc_common.configure_features( + ctx = ctx, cc_toolchain = cc_toolchain, requested_features = ctx.features, unsupported_features = ctx.disabled_features, @@ -90,4 +91,5 @@ my_c_archive = rule( "deps": attr.label_list(providers = [CcInfo]), "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), }, + fragments = ["cpp"], ) diff --git a/examples/my_c_compile/my_c_compile.bzl b/examples/my_c_compile/my_c_compile.bzl index 9892dc6..6e35b39 100644 --- a/examples/my_c_compile/my_c_compile.bzl +++ b/examples/my_c_compile/my_c_compile.bzl @@ -28,6 +28,7 @@ def _my_c_compile_impl(ctx): source_file = ctx.file.src output_file = ctx.actions.declare_file(ctx.label.name + ".o") feature_configuration = cc_common.configure_features( + ctx = ctx, cc_toolchain = cc_toolchain, requested_features = ctx.features, unsupported_features = DISABLED_FEATURES + ctx.disabled_features,