[Build] Dropped Bazel 6.x support (#37979)

This is aligned with [OSS C++ Support Policy](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md) saying that Bazel 6 support will be dropped from Nov 2024.

Also this is required to upgrade rule_cc now.

Closes #37979

PiperOrigin-RevId: 689104858
pull/37978/head
Esun Kim 1 month ago committed by Copybara-Service
parent 36b9ee9524
commit a24c8cc62a
  1. 1
      bazel/supported_versions.txt
  2. 3
      bazel/update_mirror.sh
  3. 1
      doc/bazel_support.md
  4. 2
      third_party/toolchains/generate_linux_rbe_configs.sh
  5. 42
      third_party/toolchains/rbe_ubuntu2004/cc/BUILD
  6. 2
      third_party/toolchains/rbe_ubuntu2004/cc/WORKSPACE
  7. 1
      third_party/toolchains/rbe_ubuntu2004/cc/builtin_include_directory_paths
  8. 253
      third_party/toolchains/rbe_ubuntu2004/cc/cc_toolchain_config.bzl
  9. 29
      third_party/toolchains/rbe_ubuntu2004/cc/cc_wrapper.sh
  10. 1
      tools/bazelify_tests/test/supported_bazel_versions.bzl

@ -57,9 +57,6 @@ function upload {
# upload "github.com/google/boringssl/archive/1c2769383f027befac5b75b6cedd25daf3bf4dcf.tar.gz"
# bazel binaries used by the tools/bazel wrapper script
upload github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-linux-x86_64
upload github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-darwin-x86_64
upload github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-windows-x86_64.exe
upload github.com/bazelbuild/bazel/releases/download/7.3.1/bazel-7.3.1-linux-x86_64
upload github.com/bazelbuild/bazel/releases/download/7.3.1/bazel-7.3.1-darwin-x86_64
upload github.com/bazelbuild/bazel/releases/download/7.3.1/bazel-7.3.1-windows-x86_64.exe

@ -44,6 +44,5 @@ compatibility range. The currently supported versions are captured by the
following list:
- [`7.3.1`](https://github.com/bazelbuild/bazel/releases/tag/7.3.1)
- [`6.5.0`](https://github.com/bazelbuild/bazel/releases/tag/6.5.0)
NOTE: gRPC doesn't support bzlmod yet.

@ -42,7 +42,7 @@ LINUX_RBE_DOCKER_IMAGE=$(cat ${LINUX_RBE_DOCKERFILE_DIR}.current_version)
# Bazel version used for configuring
# Needs to be the oldest of the versions from bazel/supported_versions.txt chosen
# so that the result is compatible with other supported bazel versions.
BAZEL_VERSION=6.5.0
BAZEL_VERSION=7.3.1
# TODO(jtattermusch): experiment with --cpp_env_json to simplify bazel build configuration.

@ -22,6 +22,24 @@ package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0
cc_library(name = "empty_lib")
# Label flag for extra libraries to be linked into every binary.
# TODO(bazel-team): Support passing flag multiple times to build a list.
label_flag(
name = "link_extra_libs",
build_setting_default = ":empty_lib",
)
# The final extra library to be linked into every binary target. This collects
# the above flag, but may also include more libraries depending on config.
cc_library(
name = "link_extra_lib",
deps = [
":link_extra_libs",
],
)
cc_library(
name = "malloc",
)
@ -38,7 +56,8 @@ filegroup(
filegroup(
name = "compiler_deps",
srcs = glob(["extra_tools/**"], allow_empty = True) + [":builtin_include_directory_paths"],
srcs = glob(["extra_tools/**"], allow_empty = True) + [":builtin_include_directory_paths",
":cc_wrapper"],
)
# This is the entry point for --crosstool_top. Toolchains are found
@ -66,6 +85,7 @@ cc_toolchain(
linker_files = ":compiler_deps",
objcopy_files = ":empty",
strip_files = ":empty",
supports_header_parsing = 1,
supports_param_files = 1,
module_map = ":module.modulemap",
)
@ -88,7 +108,8 @@ cc_toolchain_config(
"/usr/include/c++/9",
"/usr/include/x86_64-linux-gnu/c++/9",
"/usr/include/c++/9/backward",
"/usr/local/include/c++/v1"],
"/usr/local/include/c++/v1",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"],
tool_paths = {"ar": "/usr/bin/ar",
"ld": "/usr/bin/ld",
"llvm-cov": "/usr/local/bin/llvm-cov",
@ -100,7 +121,8 @@ cc_toolchain_config(
"nm": "/usr/bin/nm",
"objcopy": "/usr/bin/objcopy",
"objdump": "/usr/bin/objdump",
"strip": "/usr/bin/strip"},
"strip": "/usr/bin/strip",
"parse_headers": "cc_wrapper.sh"},
compile_flags = ["-fstack-protector",
"-Wall",
"-Wthread-safety",
@ -116,13 +138,18 @@ cc_toolchain_config(
"-ffunction-sections",
"-fdata-sections"],
dbg_compile_flags = ["-g"],
conly_flags = [],
cxx_flags = ["-std=c++14"],
link_flags = ["-fuse-ld=/usr/local/bin/ld.lld",
"-B/usr/local/bin",
"-Wl,-no-as-needed",
"-Wl,-z,relro,-z,now",
"-B/usr/local/bin"],
link_libs = ["-lstdc++",
"-lm"],
"-Wl,-z,relro,-z,now"],
link_libs = ["-Wl,--push-state,-as-needed",
"-lstdc++",
"-Wl,--pop-state",
"-Wl,--push-state,-as-needed",
"-lm",
"-Wl,--pop-state"],
opt_link_flags = ["-Wl,--gc-sections"],
unfiltered_compile_flags = ["-no-canonical-prefixes",
"-Wno-builtin-macro-redefined",
@ -132,6 +159,7 @@ cc_toolchain_config(
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
supports_start_end_lib = True,
extra_flags_per_feature = {"use_module_maps": ["-Xclang", "-fno-cxx-modules"]},
)
# Android tooling requires a default toolchain for the armeabi-v7a cpu.

@ -1,2 +0,0 @@
# DO NOT EDIT: automatically generated WORKSPACE file for cc_autoconf rule
workspace(name = "local_config_cc")

@ -13,3 +13,4 @@ declared action inputs or the action commandline changes.
/usr/include/x86_64-linux-gnu/c++/9
/usr/include/c++/9/backward
/usr/local/include/c++/v1
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

@ -14,10 +14,13 @@
"""A Starlark cc_toolchain configuration rule"""
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"action_config",
"artifact_name_pattern",
"env_entry",
"env_set",
"feature",
"feature_set",
"flag_group",
@ -27,9 +30,13 @@ load(
"variable_with_value",
"with_feature_set",
)
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
def layering_check_features(compiler):
def _target_os_version(ctx):
platform_type = ctx.fragments.apple.single_arch_platform.platform_type
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
return xcode_config.minimum_os_for_platform_type(platform_type)
def layering_check_features(compiler, extra_flags_per_feature, is_macos):
if compiler != "clang":
return []
return [
@ -46,10 +53,12 @@ def layering_check_features(compiler):
],
flag_groups = [
flag_group(
flags = [
# macOS requires -Xclang because of a bug in Apple Clang
flags = (["-Xclang"] if is_macos else []) + [
"-fmodule-name=%{module_name}",
] + (["-Xclang"] if is_macos else []) + [
"-fmodule-map-file=%{module_map_file}",
],
] + extra_flags_per_feature.get("use_module_maps", []),
),
],
),
@ -79,7 +88,7 @@ def layering_check_features(compiler):
]),
flag_group(
iterate_over = "dependent_module_map_files",
flags = [
flags = (["-Xclang"] if is_macos else []) + [
"-fmodule-map-file=%{dependent_module_map_files}",
],
),
@ -89,6 +98,47 @@ def layering_check_features(compiler):
),
]
def parse_headers_support(parse_headers_tool_path):
if not parse_headers_tool_path:
return [], []
action_configs = [
action_config(
action_name = ACTION_NAMES.cpp_header_parsing,
tools = [
tool(path = parse_headers_tool_path),
],
flag_sets = [
flag_set(
flag_groups = [
flag_group(
flags = [
# Note: This treats all headers as C++ headers, which may lead to
# parsing failures for C headers that are not valid C++.
# For such headers, use features = ["-parse_headers"] to selectively
# disable parsing.
"-xc++-header",
"-fsyntax-only",
],
),
],
),
],
implies = [
# Copied from the legacy feature definition in CppActionConfigs.java.
"legacy_compile_flags",
"user_compile_flags",
"sysroot",
"unfiltered_compile_flags",
"compiler_input_flags",
"compiler_output_flags",
],
),
]
features = [
feature(name = "parse_headers"),
]
return action_configs, features
all_compile_actions = [
ACTION_NAMES.c_compile,
ACTION_NAMES.cpp_compile,
@ -187,7 +237,17 @@ def _impl(ctx):
],
)
objcopy_action = action_config(
action_name = ACTION_NAMES.objcopy_embed_data,
tools = [
tool(
path = ctx.attr.tool_paths["objcopy"],
),
],
)
action_configs.append(llvm_cov_action)
action_configs.append(objcopy_action)
supports_pic_feature = feature(
name = "supports_pic",
@ -198,6 +258,16 @@ def _impl(ctx):
enabled = True,
)
gcc_quoting_for_param_files_feature = feature(
name = "gcc_quoting_for_param_files",
enabled = True,
)
static_link_cpp_runtimes_feature = feature(
name = "static_link_cpp_runtimes",
enabled = False,
)
default_compile_flags_feature = feature(
name = "default_compile_flags",
enabled = True,
@ -243,6 +313,14 @@ def _impl(ctx):
] if ctx.attr.opt_compile_flags else []),
with_features = [with_feature_set(features = ["opt"])],
),
flag_set(
actions = [ACTION_NAMES.c_compile],
flag_groups = ([
flag_group(
flags = ctx.attr.conly_flags,
),
] if ctx.attr.conly_flags else []),
),
flag_set(
actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
flag_groups = ([
@ -276,6 +354,18 @@ def _impl(ctx):
with_features = [with_feature_set(features = ["opt"])],
),
],
env_sets = [
env_set(
actions = all_link_actions + lto_index_actions + [ACTION_NAMES.cpp_link_static_library],
env_entries = ([
env_entry(
# Required for hermetic links on macOS
key = "ZERO_AR_DATE",
value = "1",
),
]),
),
],
)
dbg_feature = feature(name = "dbg")
@ -749,23 +839,6 @@ def _impl(ctx):
],
)
symbol_counts_feature = feature(
name = "symbol_counts",
flag_sets = [
flag_set(
actions = all_link_actions + lto_index_actions,
flag_groups = [
flag_group(
flags = [
"-Wl,--print-symbol-counts=%{symbol_counts_output}",
],
expand_if_available = "symbol_counts_output",
),
],
),
],
)
strip_debug_symbols_feature = feature(
name = "strip_debug_symbols",
flag_sets = [
@ -811,24 +884,6 @@ def _impl(ctx):
],
)
is_linux = ctx.attr.target_libc != "macosx"
if is_linux:
versioned_library_flag_group = flag_group(
flags = ["-l:%{libraries_to_link.name}"],
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "versioned_dynamic_library",
),
)
else:
versioned_library_flag_group = flag_group(
flags = ["%{libraries_to_link.path}"],
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "versioned_dynamic_library",
),
)
libraries_to_link_feature = feature(
name = "libraries_to_link",
flag_sets = [
@ -849,6 +904,10 @@ def _impl(ctx):
flags = ["-Wl,-whole-archive"],
expand_if_true =
"libraries_to_link.is_whole_archive",
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "static_library",
),
),
flag_group(
flags = ["%{libraries_to_link.object_files}"],
@ -886,10 +945,20 @@ def _impl(ctx):
value = "dynamic_library",
),
),
versioned_library_flag_group,
flag_group(
flags = ["-l:%{libraries_to_link.name}"],
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "versioned_dynamic_library",
),
),
flag_group(
flags = ["-Wl,-no-whole-archive"],
expand_if_true = "libraries_to_link.is_whole_archive",
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "static_library",
),
),
flag_group(
flags = ["-Wl,--end-lib"],
@ -975,15 +1044,23 @@ def _impl(ctx):
],
)
is_linux = ctx.attr.target_libc != "macosx"
libtool_feature = feature(
name = "libtool",
enabled = not is_linux,
)
archiver_flags_feature = feature(
name = "archiver_flags",
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(flags = ["rcsD"]),
flag_group(
flags = ["%{output_execpath}"],
flags = [
"rcsD" if is_linux else "rcs",
"%{output_execpath}",
],
expand_if_available = "output_execpath",
),
],
@ -996,9 +1073,12 @@ def _impl(ctx):
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(flags = ["-static", "-s"]),
flag_group(
flags = ["-o", "%{output_execpath}"],
flags = [
"-static",
"-o",
"%{output_execpath}",
],
expand_if_available = "output_execpath",
),
],
@ -1139,6 +1219,25 @@ def _impl(ctx):
],
)
generate_linkmap_feature = feature(
name = "generate_linkmap",
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.cpp_link_executable,
],
flag_groups = [
flag_group(
flags = [
"-Wl,-Map=%{output_execpath}.map" if is_linux else "-Wl,-map,%{output_execpath}.map",
],
expand_if_available = "output_execpath",
),
],
),
],
)
output_execpath_flags_feature = feature(
name = "output_execpath_flags",
flag_sets = [
@ -1254,7 +1353,9 @@ def _impl(ctx):
),
flag_set(
actions = all_link_actions,
flag_groups = [flag_group(flags = ["-Wl,-fatal-warnings"])],
flag_groups = [flag_group(
flags = ["-Wl,-fatal-warnings"] if is_linux else ["-Wl,-fatal_warnings"],
)],
),
],
)
@ -1295,9 +1396,34 @@ def _impl(ctx):
],
)
libtool_feature = feature(
name = "libtool",
enabled = not is_linux,
# If you have Xcode + the CLT installed the version defaults can be
# too old for some standard C apis such as thread locals
macos_minimum_os_feature = feature(
name = "macos_minimum_os",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions + all_link_actions,
flag_groups = [flag_group(flags = ["-mmacosx-version-min={}".format(_target_os_version(ctx))])],
),
],
)
# Kept for backwards compatibility with the crosstool that moved. Without
# linking the objc runtime binaries don't link CoreFoundation for free,
# which breaks abseil.
macos_default_link_flags_feature = feature(
name = "macos_default_link_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_link_actions,
flag_groups = [flag_group(flags = [
"-no-canonical-prefixes",
"-fobjc-link-runtime",
])],
),
],
)
# TODO(#8303): Mac crosstool should also declare every feature.
@ -1322,7 +1448,7 @@ def _impl(ctx):
autofdo_feature,
build_interface_libraries_feature,
dynamic_library_linker_tool_feature,
symbol_counts_feature,
generate_linkmap_feature,
shared_flag_feature,
linkstamps_feature,
output_execpath_flags_feature,
@ -1338,6 +1464,8 @@ def _impl(ctx):
asan_feature,
tsan_feature,
ubsan_feature,
gcc_quoting_for_param_files_feature,
static_link_cpp_runtimes_feature,
] + (
[
supports_start_end_lib_feature,
@ -1358,7 +1486,7 @@ def _impl(ctx):
unfiltered_compile_flags_feature,
treat_warnings_as_errors_feature,
archive_param_file_feature,
] + layering_check_features(ctx.attr.compiler)
] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = False)
else:
# macOS artifact name patterns differ from the defaults only for dynamic
# libraries.
@ -1370,12 +1498,15 @@ def _impl(ctx):
),
]
features = [
macos_minimum_os_feature,
macos_default_link_flags_feature,
libtool_feature,
archiver_flags_feature,
supports_pic_feature,
asan_feature,
tsan_feature,
ubsan_feature,
gcc_quoting_for_param_files_feature,
static_link_cpp_runtimes_feature,
] + (
[
supports_start_end_lib_feature,
@ -1386,8 +1517,8 @@ def _impl(ctx):
default_link_flags_feature,
user_link_flags_feature,
default_link_libs_feature,
external_include_paths_feature,
fdo_optimize_feature,
supports_dynamic_linker_feature,
dbg_feature,
opt_feature,
user_compile_flags_feature,
@ -1395,7 +1526,14 @@ def _impl(ctx):
unfiltered_compile_flags_feature,
treat_warnings_as_errors_feature,
archive_param_file_feature,
] + layering_check_features(ctx.attr.compiler)
generate_linkmap_feature,
] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = True)
parse_headers_action_configs, parse_headers_features = parse_headers_support(
parse_headers_tool_path = ctx.attr.tool_paths.get("parse_headers"),
)
action_configs += parse_headers_action_configs
features += parse_headers_features
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
@ -1431,6 +1569,7 @@ cc_toolchain_config = rule(
"compile_flags": attr.string_list(),
"dbg_compile_flags": attr.string_list(),
"opt_compile_flags": attr.string_list(),
"conly_flags": attr.string_list(),
"cxx_flags": attr.string_list(),
"link_flags": attr.string_list(),
"archive_flags": attr.string_list(),
@ -1441,6 +1580,12 @@ cc_toolchain_config = rule(
"coverage_link_flags": attr.string_list(),
"supports_start_end_lib": attr.bool(),
"builtin_sysroot": attr.string(),
"extra_flags_per_feature": attr.string_list_dict(),
"_xcode_config": attr.label(default = configuration_field(
fragment = "apple",
name = "xcode_config_label",
)),
},
fragments = ["apple"],
provides = [CcToolchainConfigInfo],
)

@ -18,8 +18,37 @@
#
set -eu
OUTPUT=
function parse_option() {
local -r opt="$1"
if [[ "${OUTPUT}" = "1" ]]; then
OUTPUT=$opt
elif [[ "$opt" = "-o" ]]; then
# output is coming
OUTPUT=1
fi
}
# let parse the option list
for i in "$@"; do
if [[ "$i" = @* && -r "${i:1}" ]]; then
while IFS= read -r opt
do
parse_option "$opt"
done < "${i:1}" || exit 1
else
parse_option "$i"
fi
done
# Set-up the environment
# Call the C++ compiler
/usr/local/bin/clang-19 "$@"
# Generate an empty file if header processing succeeded.
if [[ "${OUTPUT}" == *.h.processed ]]; then
echo -n > "${OUTPUT}"
fi

@ -18,5 +18,4 @@ This file is generated from the supported_bazel_versions.bzl.template
SUPPORTED_BAZEL_VERSIONS = [
"7.3.1",
"6.5.0",
]

Loading…
Cancel
Save