1# Copyright 2023 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"""Config settings for compilers identified by Bazel. 16 17Targets that require compiler-specific flags can use the config_settings defined 18in this package in their select() statements. 19 20*Note*: Before Bazel 6, gcc on Linux and clang on macOS would not match their 21specific config_setting, but only the fallback case of a select expression. 22 23Toolchains not shipped with Bazel are encouraged to use the same names to 24identify compilers as used below, but this is not enforced. 25 26Example: 27 28 cc_binary( 29 name = "foo", 30 srcs = ["foo.cc"], 31 copts = select({ 32 "@rules_cc//cc/compiler:gcc": [...], 33 "@rules_cc//cc/compiler:clang": [...], 34 "@rules_cc//cc/compiler:msvc-cl": [...], 35 # Fallback case for an undetected compiler. 36 "//conditions:default": [...], 37 }), 38 ) 39 40If multiple targets use the same set of conditionally enabled flags, this can be 41simplified by extracting the select expression into a Starlark constant. 42""" 43 44package(default_visibility = ["//visibility:public"]) 45 46licenses(["notice"]) 47 48config_setting( 49 name = "clang", 50 flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"}, 51) 52 53config_setting( 54 name = "clang-cl", 55 flag_values = {"@bazel_tools//tools/cpp:compiler": "clang-cl"}, 56) 57 58config_setting( 59 name = "gcc", 60 flag_values = {"@bazel_tools//tools/cpp:compiler": "gcc"}, 61) 62 63config_setting( 64 name = "mingw-gcc", 65 flag_values = {"@bazel_tools//tools/cpp:compiler": "mingw-gcc"}, 66) 67 68config_setting( 69 name = "msvc-cl", 70 flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"}, 71) 72