Philipp Schrader | 33b5e80 | 2022-02-06 22:17:41 -0800 | [diff] [blame] | 1 | load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") |
| 2 | |
| 3 | def _cc_toolchain_make_variables_impl(ctx): |
| 4 | """Supports make variables for toolchains in a platforms setup. |
| 5 | |
| 6 | The upstream @bazel_tools//tools/cpp:current_cc_toolchain target on its own |
| 7 | doesn't appear to work with platforms. It only works when using --cpu. |
| 8 | """ |
| 9 | toolchain = find_cpp_toolchain(ctx) |
| 10 | |
| 11 | feature_configuration = cc_common.configure_features( |
| 12 | ctx = ctx, |
| 13 | cc_toolchain = toolchain, |
| 14 | requested_features = ctx.features, |
| 15 | unsupported_features = ctx.disabled_features, |
| 16 | ) |
| 17 | objcopy = cc_common.get_tool_for_action( |
| 18 | feature_configuration = feature_configuration, |
| 19 | action_name = "objcopy_embed_data", |
| 20 | ) |
| 21 | |
| 22 | return [ |
| 23 | platform_common.TemplateVariableInfo({ |
| 24 | "OBJCOPY": objcopy, |
| 25 | }), |
| 26 | DefaultInfo(files = toolchain.all_files), |
| 27 | ] |
| 28 | |
| 29 | cc_toolchain_make_variables = rule( |
| 30 | implementation = _cc_toolchain_make_variables_impl, |
| 31 | attrs = { |
| 32 | # This is a dependency of find_cpp_toolchain(). |
| 33 | "_toolchain": attr.label( |
| 34 | default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), |
| 35 | ), |
| 36 | }, |
| 37 | fragments = ["cpp"], |
| 38 | toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], |
| 39 | ) |