1*eed53cd4SHONG Yifan# Copyright 2023 The Bazel Authors. All rights reserved. 2*eed53cd4SHONG Yifan# 3*eed53cd4SHONG Yifan# Licensed under the Apache License, Version 2.0 (the "License"); 4*eed53cd4SHONG Yifan# you may not use this file except in compliance with the License. 5*eed53cd4SHONG Yifan# You may obtain a copy of the License at 6*eed53cd4SHONG Yifan# 7*eed53cd4SHONG Yifan# http://www.apache.org/licenses/LICENSE-2.0 8*eed53cd4SHONG Yifan# 9*eed53cd4SHONG Yifan# Unless required by applicable law or agreed to in writing, software 10*eed53cd4SHONG Yifan# distributed under the License is distributed on an "AS IS" BASIS, 11*eed53cd4SHONG Yifan# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*eed53cd4SHONG Yifan# See the License for the specific language governing permissions and 13*eed53cd4SHONG Yifan# limitations under the License. 14*eed53cd4SHONG Yifan 15*eed53cd4SHONG Yifan"""Config settings for compilers identified by Bazel. 16*eed53cd4SHONG Yifan 17*eed53cd4SHONG YifanTargets that require compiler-specific flags can use the config_settings defined 18*eed53cd4SHONG Yifanin this package in their select() statements. 19*eed53cd4SHONG Yifan 20*eed53cd4SHONG Yifan*Note*: Before Bazel 6, gcc on Linux and clang on macOS would not match their 21*eed53cd4SHONG Yifanspecific config_setting, but only the fallback case of a select expression. 22*eed53cd4SHONG Yifan 23*eed53cd4SHONG YifanToolchains not shipped with Bazel are encouraged to use the same names to 24*eed53cd4SHONG Yifanidentify compilers as used below, but this is not enforced. 25*eed53cd4SHONG Yifan 26*eed53cd4SHONG YifanExample: 27*eed53cd4SHONG Yifan 28*eed53cd4SHONG Yifan cc_binary( 29*eed53cd4SHONG Yifan name = "foo", 30*eed53cd4SHONG Yifan srcs = ["foo.cc"], 31*eed53cd4SHONG Yifan copts = select({ 32*eed53cd4SHONG Yifan "@rules_cc//cc/compiler:gcc": [...], 33*eed53cd4SHONG Yifan "@rules_cc//cc/compiler:clang": [...], 34*eed53cd4SHONG Yifan "@rules_cc//cc/compiler:msvc-cl": [...], 35*eed53cd4SHONG Yifan # Fallback case for an undetected compiler. 36*eed53cd4SHONG Yifan "//conditions:default": [...], 37*eed53cd4SHONG Yifan }), 38*eed53cd4SHONG Yifan ) 39*eed53cd4SHONG Yifan 40*eed53cd4SHONG YifanIf multiple targets use the same set of conditionally enabled flags, this can be 41*eed53cd4SHONG Yifansimplified by extracting the select expression into a Starlark constant. 42*eed53cd4SHONG Yifan""" 43*eed53cd4SHONG Yifan 44*eed53cd4SHONG Yifanpackage(default_visibility = ["//visibility:public"]) 45*eed53cd4SHONG Yifan 46*eed53cd4SHONG Yifanlicenses(["notice"]) 47*eed53cd4SHONG Yifan 48*eed53cd4SHONG Yifanconfig_setting( 49*eed53cd4SHONG Yifan name = "clang", 50*eed53cd4SHONG Yifan flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"}, 51*eed53cd4SHONG Yifan) 52*eed53cd4SHONG Yifan 53*eed53cd4SHONG Yifanconfig_setting( 54*eed53cd4SHONG Yifan name = "clang-cl", 55*eed53cd4SHONG Yifan flag_values = {"@bazel_tools//tools/cpp:compiler": "clang-cl"}, 56*eed53cd4SHONG Yifan) 57*eed53cd4SHONG Yifan 58*eed53cd4SHONG Yifanconfig_setting( 59*eed53cd4SHONG Yifan name = "gcc", 60*eed53cd4SHONG Yifan flag_values = {"@bazel_tools//tools/cpp:compiler": "gcc"}, 61*eed53cd4SHONG Yifan) 62*eed53cd4SHONG Yifan 63*eed53cd4SHONG Yifanconfig_setting( 64*eed53cd4SHONG Yifan name = "mingw-gcc", 65*eed53cd4SHONG Yifan flag_values = {"@bazel_tools//tools/cpp:compiler": "mingw-gcc"}, 66*eed53cd4SHONG Yifan) 67*eed53cd4SHONG Yifan 68*eed53cd4SHONG Yifanconfig_setting( 69*eed53cd4SHONG Yifan name = "msvc-cl", 70*eed53cd4SHONG Yifan flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"}, 71*eed53cd4SHONG Yifan) 72