diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl index 52b04edc3a7c9c..f1f68c0f563c0d 100644 --- a/tools/cpp/unix_cc_configure.bzl +++ b/tools/cpp/unix_cc_configure.bzl @@ -199,20 +199,21 @@ def _get_no_canonical_prefixes_opt(repository_ctx, cc): # (ie when they're shorter), it confuses Bazel's logic for verifying all # #included header files are listed as inputs to the action. - # The '-fno-canonical-system-headers' should be enough, but clang does not - # support it, so we also try '-no-canonical-prefixes' if first option does - # not work. + # The '-fno-canonical-system-headers' flag is enough in some + # cases, but clang does not support it, and gcc can be configured + # in a way where it is not sufficient to suppress symlink + # resolution, so we also try '-no-canonical-prefixes' if the + # compiler can use it without failing. opt = _add_compiler_option_if_supported( repository_ctx, cc, "-fno-canonical-system-headers", ) - if len(opt) == 0: - return _add_compiler_option_if_supported( + opt.extend(_add_compiler_option_if_supported( repository_ctx, cc, "-no-canonical-prefixes", - ) + )) return opt def get_env(repository_ctx):