rosica | 8044286 | 2018-05-28 05:59:33 -0700 | [diff] [blame] | 1 | # Copyright 2018 The Bazel Authors. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | """Rule that allows select() to differentiate between compilers.""" |
| 16 | |
John Cater | 86e2db7 | 2022-02-10 23:27:21 -0800 | [diff] [blame] | 17 | load("//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") |
rosica | 8044286 | 2018-05-28 05:59:33 -0700 | [diff] [blame] | 18 | |
| 19 | def _compiler_flag_impl(ctx): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 20 | toolchain = find_cpp_toolchain(ctx) |
| 21 | return [config_common.FeatureFlagInfo(value = toolchain.compiler)] |
rosica | 8044286 | 2018-05-28 05:59:33 -0700 | [diff] [blame] | 22 | |
| 23 | compiler_flag = rule( |
| 24 | implementation = _compiler_flag_impl, |
| 25 | attrs = { |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 26 | "_cc_toolchain": attr.label(default = Label("//tools/cpp:current_cc_toolchain")), |
| 27 | }, |
John Cater | 86e2db7 | 2022-02-10 23:27:21 -0800 | [diff] [blame] | 28 | toolchains = use_cpp_toolchain(), |
jcater | 5672d5d | 2020-10-01 06:27:58 -0700 | [diff] [blame] | 29 | incompatible_use_toolchain_transition = True, |
rosica | 8044286 | 2018-05-28 05:59:33 -0700 | [diff] [blame] | 30 | ) |