I would like to specify linkopts on a cc_library target, but only if the target is built with clang (because gcc doesn't support the flag). How do I go about this?
The specific example in which this need arose is https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/136287 (see also comments on this change). A library produces a warning when linked with clang with the --warn_backrefs flag. This warning can be silenced using --warn-backrefs-exclude, but only clang recognizes this flag: adding it unconditionally will lead gcc to report an error.
Apparently, CMake allows handling such compiler-specific flags via CMAKE_CXX_COMPILER_ID and CMAKE_<LANG>_COMPILER_VERSION. Is there an analogous mechanism in Bazel?