diff --git a/.github/workflows/ci-rbe.yml b/.github/workflows/ci-rbe.yml index 1a53330d5be06..00bc0c4d9b077 100644 --- a/.github/workflows/ci-rbe.yml +++ b/.github/workflows/ci-rbe.yml @@ -31,5 +31,4 @@ jobs: name: All RBE tests cache-save: ${{ github.ref_name == 'trunk' }} rerun-with-debug: true - ruby-version: jruby-10.1.0.0 run: ./scripts/github-actions/ci-build.sh ${{ github.event.inputs.disable_test_cache }} diff --git a/MODULE.bazel b/MODULE.bazel index 713723d0c4957..ae73a80d149f2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -38,8 +38,8 @@ bazel_dep(name = "rules_oci", version = "2.3.0") bazel_dep(name = "rules_pkg", version = "1.2.0") bazel_dep(name = "rules_python", version = "1.9.0") bazel_dep(name = "rules_proto", version = "7.1.0") -bazel_dep(name = "rules_ruby", version = "0.26.0") bazel_dep(name = "rules_rs", version = "0.0.90") +bazel_dep(name = "rules_ruby", version = "0.27.0") single_version_override( module_name = "rules_jvm_external", diff --git a/common/remote-build/BUILD.bazel b/common/remote-build/BUILD.bazel index 4ab4ce176d838..6f8306baaad01 100755 --- a/common/remote-build/BUILD.bazel +++ b/common/remote-build/BUILD.bazel @@ -41,7 +41,7 @@ platform( "@llvm//constraints/libc:gnu.2.28", ], exec_properties = { - "container-image": "docker://docker.io/selenium/selenium-remote-build@sha256:ca164352826812f02eaa1b4dab89adcf5b3e57deb6798dd9f15d004099db59fe", + "container-image": "docker://docker.io/selenium/selenium-remote-build@sha256:7f917a409785aceff81e72358222c6d1bdc24d0b7df2d02f0f46e7392d5c8871", "OSFamily": "Linux", "dockerNetwork": "standard", # Allow internet access for the Rust tests "dockerReuse": "True", diff --git a/common/remote-build/cc/BUILD b/common/remote-build/cc/BUILD index 425b4acd189ff..e4e90492517dc 100755 --- a/common/remote-build/cc/BUILD +++ b/common/remote-build/cc/BUILD @@ -15,7 +15,8 @@ # This becomes the BUILD file for @local_config_cc// under non-BSD unixes. load("@rules_cc//cc:cc_library.bzl", "cc_library") -load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite") +load("@rules_cc//cc/toolchains:cc_toolchain.bzl", "cc_toolchain") +load("@rules_cc//cc/toolchains:cc_toolchain_suite.bzl", "cc_toolchain_suite") load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config") load(":cc_toolchain_config.bzl", "cc_toolchain_config") @@ -23,6 +24,23 @@ 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. +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", ) @@ -37,12 +55,27 @@ filegroup( srcs = ["cc_wrapper.sh"], ) +filegroup( + name = "validate_static_library", + srcs = ["validate_static_library.sh"], +) + +filegroup( + name = "deps_scanner_wrapper", + srcs = ["deps_scanner_wrapper.sh"], +) + filegroup( name = "compiler_deps", srcs = glob( ["extra_tools/**"], allow_empty = True, - ) + [":builtin_include_directory_paths"], + ) + [ + ":builtin_include_directory_paths", + ":cc_wrapper", + ":deps_scanner_wrapper", + ":validate_static_library", + ], ) # This is the entry point for --crosstool_top. Toolchains are found @@ -69,6 +102,7 @@ cc_toolchain( module_map = None, objcopy_files = ":empty", strip_files = ":empty", + supports_header_parsing = 1, supports_param_files = 1, toolchain_config = ":local", toolchain_identifier = "local", @@ -78,6 +112,7 @@ cc_toolchain_config( name = "local", abi_libc_version = "local", abi_version = "local", + all_compile_flags = [], compile_flags = [ "-fstack-protector", "-Wall", @@ -86,31 +121,38 @@ cc_toolchain_config( "-fno-omit-frame-pointer", ], compiler = "gcc", + conly_flags = [], coverage_compile_flags = ["--coverage"], coverage_link_flags = ["--coverage"], cpu = "k8", cxx_builtin_include_directories = [ - "/usr/lib/gcc/x86_64-linux-gnu/9/include", + "/usr/lib/gcc/x86_64-linux-gnu/11/include", "/usr/local/include", "/usr/include/x86_64-linux-gnu", "/usr/include", - "/usr/include/c++/9", - "/usr/include/x86_64-linux-gnu/c++/9", - "/usr/include/c++/9/backward", + "/usr/include/c++/11", + "/usr/include/x86_64-linux-gnu/c++/11", + "/usr/include/c++/11/backward", ], - cxx_flags = ["-std=c++0x"], + cxx_flags = ["-std=c++17"], dbg_compile_flags = ["-g"], + extra_flags_per_feature = {}, + fastbuild_compile_flags = [], host_system_name = "local", link_flags = [ "-fuse-ld=gold", + "-B/usr/bin", "-Wl,-no-as-needed", "-Wl,-z,relro,-z,now", - "-B/usr/bin", "-pass-exit-codes", ], link_libs = [ + "-Wl,--push-state,-as-needed", "-lstdc++", + "-Wl,--pop-state", + "-Wl,--push-state,-as-needed", "-lm", + "-Wl,--pop-state", ], opt_compile_flags = [ "-g0", @@ -127,8 +169,6 @@ cc_toolchain_config( tool_paths = { "ar": "/usr/bin/ar", "ld": "/usr/bin/ld", - "llvm-cov": "None", - "llvm-profdata": "None", "cpp": "/usr/bin/cpp", "gcc": "/usr/bin/gcc", "dwp": "/usr/bin/dwp", @@ -137,6 +177,10 @@ cc_toolchain_config( "objcopy": "/usr/bin/objcopy", "objdump": "/usr/bin/objdump", "strip": "/usr/bin/strip", + "c++filt": "/usr/bin/c++filt", + "cpp-module-deps-scanner": "deps_scanner_wrapper.sh", + "parse_headers": "cc_wrapper.sh", + "validate_static_library": "validate_static_library.sh", }, toolchain_identifier = "local", unfiltered_compile_flags = [ diff --git a/common/remote-build/cc/REPO.bazel b/common/remote-build/cc/REPO.bazel new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/common/remote-build/cc/WORKSPACE b/common/remote-build/cc/WORKSPACE deleted file mode 100644 index bc05b4c36ff49..0000000000000 --- a/common/remote-build/cc/WORKSPACE +++ /dev/null @@ -1,2 +0,0 @@ -# DO NOT EDIT: automatically generated WORKSPACE file for cc_autoconf rule -workspace(name = "local_config_cc") diff --git a/common/remote-build/cc/armeabi_cc_toolchain_config.bzl b/common/remote-build/cc/armeabi_cc_toolchain_config.bzl old mode 100755 new mode 100644 index 2d16c5c9cfa77..ea7ce6b0acc06 --- a/common/remote-build/cc/armeabi_cc_toolchain_config.bzl +++ b/common/remote-build/cc/armeabi_cc_toolchain_config.bzl @@ -15,12 +15,12 @@ """A Starlark cc_toolchain configuration rule""" load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "@rules_cc//cc:cc_toolchain_config_lib.bzl", "feature", "tool_path", ) load("@rules_cc//cc/common:cc_common.bzl", "cc_common") -load("@rules_cc//cc/private/toolchain_config:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo") +load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo") def _impl(ctx): toolchain_identifier = "stub_armeabi-v7a" @@ -45,6 +45,7 @@ def _impl(ctx): tool_paths = [ tool_path(name = "ar", path = "/bin/false"), + tool_path(name = "compat-ld", path = "/bin/false"), tool_path(name = "cpp", path = "/bin/false"), tool_path(name = "dwp", path = "/bin/false"), tool_path(name = "gcc", path = "/bin/false"), diff --git a/common/remote-build/cc/builtin_include_directory_paths b/common/remote-build/cc/builtin_include_directory_paths index 4bb4d8ff01522..b2ba3ed40bb7f 100755 --- a/common/remote-build/cc/builtin_include_directory_paths +++ b/common/remote-build/cc/builtin_include_directory_paths @@ -4,10 +4,10 @@ changes to it will be reflected in the action cache key. When some of these paths change, Bazel will make sure to rerun the action, even though none of declared action inputs or the action commandline changes. -/usr/lib/gcc/x86_64-linux-gnu/9/include +/usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include /usr/include/x86_64-linux-gnu /usr/include -/usr/include/c++/9 -/usr/include/x86_64-linux-gnu/c++/9 -/usr/include/c++/9/backward +/usr/include/c++/11 +/usr/include/x86_64-linux-gnu/c++/11 +/usr/include/c++/11/backward diff --git a/common/remote-build/cc/cc_toolchain_config.bzl b/common/remote-build/cc/cc_toolchain_config.bzl old mode 100755 new mode 100644 index cdaee4296b374..049b13f919226 --- a/common/remote-build/cc/cc_toolchain_config.bzl +++ b/common/remote-build/cc/cc_toolchain_config.bzl @@ -14,24 +14,33 @@ """A Starlark cc_toolchain configuration rule""" -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") +load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "@rules_cc//cc:cc_toolchain_config_lib.bzl", "action_config", "artifact_name_pattern", + "env_entry", + "env_set", "feature", "feature_set", "flag_group", "flag_set", + "get_profile_correction_flags", "tool", "tool_path", "variable_with_value", "with_feature_set", ) load("@rules_cc//cc/common:cc_common.bzl", "cc_common") -load("@rules_cc//cc/private/toolchain_config:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo") +load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo") +load("@rules_cc//cc/toolchains:feature_injection.bzl", "FeatureInfo", "convert_feature") -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 [ @@ -48,10 +57,11 @@ def layering_check_features(compiler): ], flag_groups = [ flag_group( - flags = [ + 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", []), ), ], ), @@ -81,7 +91,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}", ], ), @@ -91,6 +101,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, @@ -100,6 +151,9 @@ all_compile_actions = [ ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, ACTION_NAMES.clif_match, ACTION_NAMES.lto_backend, ] @@ -110,6 +164,9 @@ all_cpp_compile_actions = [ ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, ACTION_NAMES.clif_match, ] @@ -120,6 +177,8 @@ preprocessor_compile_actions = [ ACTION_NAMES.preprocess_assemble, ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, ACTION_NAMES.clif_match, ] @@ -130,6 +189,7 @@ codegen_compile_actions = [ ACTION_NAMES.assemble, ACTION_NAMES.preprocess_assemble, ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp20_module_codegen, ACTION_NAMES.lto_backend, ] @@ -145,33 +205,162 @@ lto_index_actions = [ ACTION_NAMES.lto_index_for_nodeps_dynamic_library, ] +def _sanitizer_feature(name = "", specific_compile_flags = [], specific_link_flags = []): + return feature( + name = name, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group(flags = [ + "-fno-omit-frame-pointer", + "-fno-sanitize-recover=all", + ] + specific_compile_flags), + ], + ), + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group(flags = specific_link_flags), + ], + ), + ], + ) + def _impl(ctx): + is_linux = ctx.attr.target_libc != "macosx" + profile_correction_flags = get_profile_correction_flags(ctx) + tool_paths = [ tool_path(name = name, path = path) for name, path in ctx.attr.tool_paths.items() ] action_configs = [] - llvm_cov_action = action_config( - action_name = ACTION_NAMES.llvm_cov, + llvm_cov = ctx.attr.tool_paths.get("llvm-cov") + if llvm_cov: + llvm_cov_action = action_config( + action_name = ACTION_NAMES.llvm_cov, + tools = [ + tool( + path = llvm_cov, + ), + ], + ) + action_configs.append(llvm_cov_action) + + objcopy = ctx.attr.tool_paths.get("objcopy") + if objcopy: + objcopy_action = action_config( + action_name = ACTION_NAMES.objcopy_embed_data, + tools = [ + tool( + path = objcopy, + ), + ], + ) + action_configs.append(objcopy_action) + + validate_static_library = ctx.attr.tool_paths.get("validate_static_library") + if validate_static_library: + validate_static_library_action = action_config( + action_name = ACTION_NAMES.validate_static_library, + tools = [ + tool( + path = validate_static_library, + ), + ], + ) + action_configs.append(validate_static_library_action) + + symbol_check = feature( + name = "symbol_check", + implies = [ACTION_NAMES.validate_static_library], + ) + else: + symbol_check = None + + deps_scanner = "cpp-module-deps-scanner_not_found" + if "cpp-module-deps-scanner" in ctx.attr.tool_paths: + deps_scanner = ctx.attr.tool_paths["cpp-module-deps-scanner"] + cc = ctx.attr.tool_paths.get("gcc") + compile_implies = [ + # keep same with c++-compile + "legacy_compile_flags", + "user_compile_flags", + "sysroot", + "unfiltered_compile_flags", + "compiler_input_flags", + "compiler_output_flags", + ] + cpp_module_scan_deps = action_config( + action_name = ACTION_NAMES.cpp_module_deps_scanning, tools = [ tool( - path = ctx.attr.tool_paths["llvm-cov"], + path = deps_scanner, ), ], + implies = compile_implies, ) + action_configs.append(cpp_module_scan_deps) - action_configs.append(llvm_cov_action) + cpp20_module_compile = action_config( + action_name = ACTION_NAMES.cpp20_module_compile, + tools = [ + tool( + path = cc, + ), + ], + flag_sets = [ + flag_set( + flag_groups = [ + flag_group( + flags = [ + "-x", + "c++-module" if ctx.attr.compiler == "clang" else "c++", + ], + ), + ], + ), + ], + implies = compile_implies, + ) + action_configs.append(cpp20_module_compile) + + cpp20_module_codegen = action_config( + action_name = ACTION_NAMES.cpp20_module_codegen, + tools = [ + tool( + path = cc, + ), + ], + implies = compile_implies, + ) + action_configs.append(cpp20_module_codegen) supports_pic_feature = feature( name = "supports_pic", enabled = True, ) + prefer_pic_for_opt_binaries_feature = feature( + name = "prefer_pic_for_opt_binaries", + enabled = False, + ) supports_start_end_lib_feature = feature( name = "supports_start_end_lib", 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, @@ -199,6 +388,15 @@ def _impl(ctx): ), ] if ctx.attr.compile_flags else []), ), + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.fastbuild_compile_flags, + ), + ] if ctx.attr.fastbuild_compile_flags else []), + with_features = [with_feature_set(features = ["fastbuild"])], + ), flag_set( actions = all_compile_actions, flag_groups = ([ @@ -217,6 +415,22 @@ def _impl(ctx): ] if ctx.attr.opt_compile_flags else []), with_features = [with_feature_set(features = ["opt"])], ), + flag_set( + actions = all_compile_actions, + flag_groups = ([ + flag_group( + flags = ctx.attr.all_compile_flags, + ), + ] if ctx.attr.all_compile_flags else []), + ), + 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 = ([ @@ -250,8 +464,22 @@ 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", + ), + ]), + ), + ], ) + fastbuild_feature = feature(name = "fastbuild") + dbg_feature = feature(name = "dbg") opt_feature = feature(name = "opt") @@ -269,6 +497,9 @@ def _impl(ctx): ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, ACTION_NAMES.lto_backend, ACTION_NAMES.clif_match, ] + all_link_actions + lto_index_actions, @@ -282,6 +513,100 @@ def _impl(ctx): ], ) + compiler_input_flags_feature = feature( + name = "compiler_input_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ACTION_NAMES.lto_backend, + ], + flag_groups = [ + flag_group( + flags = ["-c", "%{source_file}"], + expand_if_available = "source_file", + ), + ], + ), + flag_set( + actions = [ + ACTION_NAMES.cpp_header_parsing, + ], + flag_groups = [ + flag_group( + flags = ["%{source_file}"], + expand_if_available = "source_file", + ), + ], + ), + ], + ) + + compiler_output_flags_feature = feature( + name = "compiler_output_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, + ACTION_NAMES.objc_compile, + ACTION_NAMES.objcpp_compile, + ACTION_NAMES.lto_backend, + ], + flag_groups = [ + flag_group( + flags = ["-S"], + expand_if_available = "output_assembly_file", + ), + flag_group( + flags = ["-E"], + expand_if_available = "output_preprocess_file", + ), + flag_group( + flags = ["-o", "%{output_file}"], + expand_if_available = "output_file", + ), + ], + ), + ], + env_sets = [ + env_set( + actions = [ + ACTION_NAMES.cpp_module_deps_scanning, + ], + env_entries = [ + env_entry( + key = "DEPS_SCANNER_OUTPUT_FILE", + value = "%{output_file}", + expand_if_available = "output_file", + ), + ], + ), + ], + ) + fdo_optimize_feature = feature( name = "fdo_optimize", flag_sets = [ @@ -291,8 +616,7 @@ def _impl(ctx): flag_group( flags = [ "-fprofile-use=%{fdo_profile_path}", - "-fprofile-correction", - ], + ] + profile_correction_flags, expand_if_available = "fdo_profile_path", ), ], @@ -383,6 +707,8 @@ def _impl(ctx): ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_module_codegen, ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, ], flag_groups = [ flag_group(flags = ["-fPIC"], expand_if_available = "pic"), @@ -402,6 +728,7 @@ def _impl(ctx): ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.cpp20_module_codegen, ], flag_groups = [ flag_group( @@ -425,6 +752,9 @@ def _impl(ctx): ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, ACTION_NAMES.clif_match, ], flag_groups = [ @@ -448,8 +778,7 @@ def _impl(ctx): "-fprofile-use=%{fdo_profile_path}", "-Wno-profile-instr-unprofiled", "-Wno-profile-instr-out-of-date", - "-fprofile-correction", - ], + ] + profile_correction_flags, expand_if_available = "fdo_profile_path", ), ], @@ -467,8 +796,7 @@ def _impl(ctx): flag_group( flags = [ "-fauto-profile=%{fdo_profile_path}", - "-fprofile-correction", - ], + ] + profile_correction_flags, expand_if_available = "fdo_profile_path", ), ], @@ -477,69 +805,134 @@ def _impl(ctx): provides = ["profile"], ) - runtime_library_search_directories_feature = feature( - name = "runtime_library_search_directories", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = [ - "-Xlinker", - "-rpath", - "-Xlinker", - "$EXEC_ORIGIN/%{runtime_library_search_directories}", - ], - expand_if_true = "is_cc_test", - ), - flag_group( - flags = [ - "-Xlinker", - "-rpath", - "-Xlinker", - "$ORIGIN/%{runtime_library_search_directories}", - ], - expand_if_false = "is_cc_test", - ), - ], - expand_if_available = - "runtime_library_search_directories", - ), - ], - with_features = [ - with_feature_set(features = ["static_link_cpp_runtimes"]), - ], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = [ - "-Xlinker", - "-rpath", - "-Xlinker", - "$ORIGIN/%{runtime_library_search_directories}", - ], - ), - ], - expand_if_available = - "runtime_library_search_directories", - ), - ], - with_features = [ - with_feature_set( - not_features = ["static_link_cpp_runtimes"], - ), - ], - ), - ], - ) + if is_linux: + runtime_library_search_directories_feature = feature( + name = "runtime_library_search_directories", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "runtime_library_search_directories", + flag_groups = [ + flag_group( + flags = [ + "-Xlinker", + "-rpath", + "-Xlinker", + "$EXEC_ORIGIN/%{runtime_library_search_directories}", + ], + expand_if_true = "is_cc_test", + ), + flag_group( + flags = [ + "-Xlinker", + "-rpath", + "-Xlinker", + "$ORIGIN/%{runtime_library_search_directories}", + ], + expand_if_false = "is_cc_test", + ), + ], + expand_if_available = + "runtime_library_search_directories", + ), + ], + with_features = [ + with_feature_set(features = ["static_link_cpp_runtimes"]), + ], + ), + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "runtime_library_search_directories", + flag_groups = [ + flag_group( + flags = [ + "-Xlinker", + "-rpath", + "-Xlinker", + "$ORIGIN/%{runtime_library_search_directories}", + ], + ), + ], + expand_if_available = + "runtime_library_search_directories", + ), + ], + with_features = [ + with_feature_set( + not_features = ["static_link_cpp_runtimes"], + ), + ], + ), + ], + ) + set_install_name_feature = feature( + name = "set_soname", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ], + flag_groups = [ + flag_group( + flags = [ + "-Wl,-soname,%{runtime_solib_name}", + ], + expand_if_available = "runtime_solib_name", + ), + ], + ), + ], + ) + else: + runtime_library_search_directories_feature = feature( + name = "runtime_library_search_directories", + flag_sets = [ + flag_set( + actions = all_link_actions + lto_index_actions, + flag_groups = [ + flag_group( + iterate_over = "runtime_library_search_directories", + flag_groups = [ + flag_group( + flags = [ + "-Xlinker", + "-rpath", + "-Xlinker", + "@loader_path/%{runtime_library_search_directories}", + ], + ), + ], + expand_if_available = "runtime_library_search_directories", + ), + ], + ), + ], + ) + set_install_name_feature = feature( + name = "set_install_name", + enabled = getattr(ctx.fragments.cpp, "do_not_use_macos_set_install_name", True), + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ], + flag_groups = [ + flag_group( + flags = [ + "-Wl,-install_name,@rpath/%{runtime_solib_name}", + ], + expand_if_available = "runtime_solib_name", + ), + ], + ), + ], + ) fission_support_feature = feature( name = "fission_support", @@ -581,6 +974,9 @@ def _impl(ctx): ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_module_codegen, ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, ], flag_groups = [ flag_group( @@ -604,6 +1000,8 @@ def _impl(ctx): ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, ACTION_NAMES.clif_match, ACTION_NAMES.objc_compile, ACTION_NAMES.objcpp_compile, @@ -675,6 +1073,8 @@ def _impl(ctx): ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, ACTION_NAMES.clif_match, ACTION_NAMES.objc_compile, ACTION_NAMES.objcpp_compile, @@ -708,6 +1108,9 @@ def _impl(ctx): ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, ACTION_NAMES.clif_match, ACTION_NAMES.objc_compile, ACTION_NAMES.objcpp_compile, @@ -723,23 +1126,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 = [ @@ -785,11 +1171,77 @@ def _impl(ctx): ], ) + libraries_to_link_common_flag_groups = [ + flag_group( + 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}"], + iterate_over = "libraries_to_link.object_files", + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file_group", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "object_file", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "interface_library", + ), + ), + flag_group( + flags = ["%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "static_library", + ), + ), + flag_group( + flags = ["-l%{libraries_to_link.name}"], + expand_if_equal = variable_with_value( + name = "libraries_to_link.type", + value = "dynamic_library", + ), + ), + 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", + ), + ), + ] + libraries_to_link_feature = feature( name = "libraries_to_link", flag_sets = [ flag_set( - actions = all_link_actions + lto_index_actions, + actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ] + lto_index_actions, flag_groups = [ flag_group( iterate_over = "libraries_to_link", @@ -801,58 +1253,7 @@ def _impl(ctx): value = "object_file_group", ), ), - flag_group( - flags = ["-Wl,-whole-archive"], - expand_if_true = - "libraries_to_link.is_whole_archive", - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "interface_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["-l%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "dynamic_library", - ), - ), - 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", - ), + ] + libraries_to_link_common_flag_groups + [ flag_group( flags = ["-Wl,--end-lib"], expand_if_equal = variable_with_value( @@ -869,6 +1270,22 @@ def _impl(ctx): ), ], ), + # Object file groups may contain symbols that aren't referenced in the same target that + # produces the object files and must thus not be wrapped in --start-lib/--end-lib when + # linking a nodeps dynamic library. + flag_set( + actions = [ACTION_NAMES.cpp_link_nodeps_dynamic_library], + flag_groups = [ + flag_group( + iterate_over = "libraries_to_link", + flag_groups = libraries_to_link_common_flag_groups, + ), + flag_group( + flags = ["-Wl,@%{thinlto_param_file}"], + expand_if_true = "thinlto_param_file", + ), + ], + ), ], ) @@ -937,15 +1354,22 @@ def _impl(ctx): ], ) + 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", ), ], @@ -958,9 +1382,14 @@ 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 = [ + "-D", + "-no_warning_for_no_symbols", + "-static", + "-o", + "%{output_execpath}", + ], expand_if_available = "output_execpath", ), ], @@ -1004,6 +1433,16 @@ def _impl(ctx): ), ] if ctx.attr.archive_flags else []), ), + flag_set( + actions = [ACTION_NAMES.cpp_link_static_library], + flag_groups = [ + flag_group( + flags = ["%{user_archiver_flags}"], + iterate_over = "user_archiver_flags", + expand_if_available = "user_archiver_flags", + ), + ], + ), ], ) @@ -1039,6 +1478,8 @@ def _impl(ctx): ACTION_NAMES.objc_compile, ACTION_NAMES.objcpp_compile, ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_deps_scanning, + ACTION_NAMES.cpp20_module_compile, ACTION_NAMES.clif_match, ], flag_groups = [ @@ -1064,6 +1505,7 @@ def _impl(ctx): ACTION_NAMES.objc_compile, ACTION_NAMES.objcpp_compile, ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_deps_scanning, ACTION_NAMES.clif_match, ], flag_groups = [ @@ -1101,6 +1543,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 = [ @@ -1144,6 +1605,14 @@ def _impl(ctx): ], ) + no_use_lto_indexing_bitcode_file_feature = feature( + name = "no_use_lto_indexing_bitcode_file", + ) + + use_lto_native_object_directory_feature = feature( + name = "use_lto_native_object_directory", + ) + thinlto_feature = feature( name = "thin_lto", flag_sets = [ @@ -1163,6 +1632,7 @@ def _impl(ctx): ), ], ), + # TODO: b/503100490 - We should centralize the stamp injection and remove this. flag_set( actions = [ACTION_NAMES.linkstamp_compile], flag_groups = [flag_group(flags = ["-DBUILD_LTO_TYPE=thin"])], @@ -1216,7 +1686,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"], + )], ), ], ) @@ -1226,17 +1698,134 @@ def _impl(ctx): enabled = True, ) - is_linux = ctx.attr.target_libc != "macosx" - libtool_feature = feature( - name = "libtool", - enabled = not is_linux, + asan_feature = _sanitizer_feature( + name = "asan", + specific_compile_flags = [ + "-fsanitize=address", + "-fno-common", + ], + specific_link_flags = [ + "-fsanitize=address", + ], + ) + + tsan_feature = _sanitizer_feature( + name = "tsan", + specific_compile_flags = [ + "-fsanitize=thread", + ], + specific_link_flags = [ + "-fsanitize=thread", + ], + ) + + ubsan_feature = _sanitizer_feature( + name = "ubsan", + specific_compile_flags = [ + "-fsanitize=undefined", + ], + specific_link_flags = [ + "-fsanitize=undefined", + ], + ) + + # 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", + ])], + ), + ], + ) + + # Tell bazel we support C++ modules now + cpp_modules_feature = feature( + name = "cpp_modules", + # set default value to False + # to enable the feature + # use --features=cpp_modules + # or add cpp_modules to features attr + enabled = False, + ) + + cpp_module_modmap_file_feature = feature( + name = "cpp_module_modmap_file", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp20_module_compile, + ACTION_NAMES.cpp20_module_codegen, + ], + flag_groups = [ + flag_group( + flags = ["@%{cpp_module_modmap_file}" if ctx.attr.compiler == "clang" else "-fmodule-mapper=%{cpp_module_modmap_file}"], + expand_if_available = "cpp_module_modmap_file", + ), + ], + ), + ], + enabled = True, ) + if ctx.attr.compiler == "clang": + flag_groups = [ + flag_group( + flags = ["-fmodule-output=%{cpp_module_output_file}"], + expand_if_available = "cpp_module_output_file", + ), + ] + else: + flag_groups = [] + cpp20_module_compile_flags_feature = feature( + name = "cpp20_module_compile_flags", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.cpp20_module_compile, + ], + flag_groups = flag_groups, + ), + ], + enabled = True, + ) + + no_dotd_file_feature = feature(name = "no_dotd_file") # TODO(#8303): Mac crosstool should also declare every feature. if is_linux: # Linux artifact name patterns are the default. - artifact_name_patterns = [] + artifact_name_patterns = [ + artifact_name_pattern( + category_name = "cpp_module", + prefix = "", + extension = ".pcm", + ), + ] features = [ + cpp_modules_feature, + cpp_module_modmap_file_feature, + cpp20_module_compile_flags_feature, dependency_file_feature, serialized_diagnostics_file_feature, random_seed_feature, @@ -1249,12 +1838,14 @@ def _impl(ctx): fdo_instrument_feature, cs_fdo_instrument_feature, cs_fdo_optimize_feature, + no_use_lto_indexing_bitcode_file_feature, + use_lto_native_object_directory_feature, thinlto_feature, fdo_prefetch_hints_feature, 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, @@ -1267,6 +1858,12 @@ def _impl(ctx): strip_debug_symbols_feature, coverage_feature, supports_pic_feature, + prefer_pic_for_opt_binaries_feature, + asan_feature, + tsan_feature, + ubsan_feature, + gcc_quoting_for_param_files_feature, + static_link_cpp_runtimes_feature, ] + ( [ supports_start_end_lib_feature, @@ -1280,14 +1877,19 @@ def _impl(ctx): static_libgcc_feature, fdo_optimize_feature, supports_dynamic_linker_feature, + fastbuild_feature, dbg_feature, opt_feature, user_compile_flags_feature, sysroot_feature, + compiler_input_flags_feature, + compiler_output_flags_feature, unfiltered_compile_flags_feature, treat_warnings_as_errors_feature, archive_param_file_feature, - ] + layering_check_features(ctx.attr.compiler) + set_install_name_feature, + no_dotd_file_feature, + ] + 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. @@ -1299,9 +1901,21 @@ def _impl(ctx): ), ] features = [ + cpp_modules_feature, + cpp_module_modmap_file_feature, + cpp20_module_compile_flags_feature, + macos_minimum_os_feature, + macos_default_link_flags_feature, + dependency_file_feature, + runtime_library_search_directories_feature, + set_install_name_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, @@ -1312,16 +1926,34 @@ def _impl(ctx): default_link_flags_feature, user_link_flags_feature, default_link_libs_feature, + includes_feature, + include_paths_feature, + external_include_paths_feature, fdo_optimize_feature, - supports_dynamic_linker_feature, dbg_feature, opt_feature, user_compile_flags_feature, sysroot_feature, + compiler_input_flags_feature, + compiler_output_flags_feature, unfiltered_compile_flags_feature, treat_warnings_as_errors_feature, archive_param_file_feature, - ] + layering_check_features(ctx.attr.compiler) + generate_linkmap_feature, + no_dotd_file_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 + + if symbol_check: + features.append(symbol_check) + + extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) + features.extend([convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) for extra_feature in extra_rules_based_features.to_list()]) return cc_common.create_cc_toolchain_config_info( ctx = ctx, @@ -1344,29 +1976,56 @@ def _impl(ctx): cc_toolchain_config = rule( implementation = _impl, attrs = { - "cpu": attr.string(mandatory = True), - "compiler": attr.string(mandatory = True), - "toolchain_identifier": attr.string(mandatory = True), - "host_system_name": attr.string(mandatory = True), - "target_system_name": attr.string(mandatory = True), - "target_libc": attr.string(mandatory = True), - "abi_version": attr.string(mandatory = True), "abi_libc_version": attr.string(mandatory = True), - "cxx_builtin_include_directories": attr.string_list(), - "tool_paths": attr.string_dict(), + "abi_version": attr.string(mandatory = True), + "archive_flags": attr.string_list(), + "builtin_sysroot": attr.string(), + "all_compile_flags": attr.string_list(), "compile_flags": attr.string_list(), - "dbg_compile_flags": attr.string_list(), - "opt_compile_flags": attr.string_list(), + "compiler": attr.string(mandatory = True), + "conly_flags": attr.string_list(), + "coverage_compile_flags": attr.string_list(), + "coverage_link_flags": attr.string_list(), + "cpu": attr.string(mandatory = True), + "cxx_builtin_include_directories": attr.string_list(), "cxx_flags": attr.string_list(), + "dbg_compile_flags": attr.string_list(), + "extra_enabled_features": attr.label_list( + providers = [FeatureInfo], + default = [], + doc = """ +Extra `cc_feature` features to add to this toolchain in an initially enabled state. +This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. +This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. +""", + ), + "extra_known_features": attr.label_list( + providers = [FeatureInfo], + default = [], + doc = """ +Extra `cc_feature` features to add to this toolchain in an initially disabled state. +This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. +This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. +""", + ), + "extra_flags_per_feature": attr.string_list_dict(), + "fastbuild_compile_flags": attr.string_list(), + "host_system_name": attr.string(mandatory = True), "link_flags": attr.string_list(), - "archive_flags": attr.string_list(), "link_libs": attr.string_list(), + "opt_compile_flags": attr.string_list(), "opt_link_flags": attr.string_list(), - "unfiltered_compile_flags": attr.string_list(), - "coverage_compile_flags": attr.string_list(), - "coverage_link_flags": attr.string_list(), "supports_start_end_lib": attr.bool(), - "builtin_sysroot": attr.string(), + "target_libc": attr.string(mandatory = True), + "target_system_name": attr.string(mandatory = True), + "tool_paths": attr.string_dict(), + "toolchain_identifier": attr.string(mandatory = True), + "unfiltered_compile_flags": attr.string_list(), + "_xcode_config": attr.label(default = configuration_field( + fragment = "apple", + name = "xcode_config_label", + )), }, + fragments = ["apple", "cpp"], provides = [CcToolchainConfigInfo], ) diff --git a/common/remote-build/cc/cc_wrapper.sh b/common/remote-build/cc/cc_wrapper.sh index f246528abf2e6..949b3cd9703ef 100755 --- a/common/remote-build/cc/cc_wrapper.sh +++ b/common/remote-build/cc/cc_wrapper.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # Copyright 2015 The Bazel Authors. All rights reserved. # @@ -18,8 +18,44 @@ # set -eu +OUTPUT= + +parse_option() { + opt=$1 + if [ "$OUTPUT" = "1" ]; then + OUTPUT=$opt + elif [ "$opt" = "-o" ]; then + # output is coming + OUTPUT=1 + fi +} + +# parse the option list +for i in "$@"; do + case $i in + @*) + file=${i#@} + if [ -r "$file" ]; then + while IFS= read -r opt; do + parse_option "$opt" + done < "$file" || exit 1 + fi + ;; + *) + parse_option "$i" + ;; + esac +done + # Set-up the environment # Call the C++ compiler /usr/bin/gcc "$@" + +# Generate an empty file if header processing succeeded. +case $OUTPUT in + *.h.processed) + : > "$OUTPUT" + ;; +esac diff --git a/common/remote-build/cc/deps_scanner_wrapper.sh b/common/remote-build/cc/deps_scanner_wrapper.sh new file mode 100755 index 0000000000000..9a773ca7c3fd9 --- /dev/null +++ b/common/remote-build/cc/deps_scanner_wrapper.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# +# Ship the environment to the C++ action +# +set -eu + +# Set-up the environment + + +# Call the C++ compiler + +/usr/bin/gcc -E -x c++ -fmodules-ts -fdeps-file=out.tmp -fdeps-format=p1689r5 "$@" >"$DEPS_SCANNER_OUTPUT_FILE" diff --git a/common/remote-build/cc/validate_static_library.sh b/common/remote-build/cc/validate_static_library.sh new file mode 100755 index 0000000000000..6c959e4a57f47 --- /dev/null +++ b/common/remote-build/cc/validate_static_library.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -euo pipefail + +# Find all duplicate symbols in the given static library: +# 1. Use nm to list all global symbols in the library in POSIX format: +# libstatic.a[my_object.o]: my_function T 1234 abcd +# 2. Use sed to transform the output to a format that can be sorted by symbol +# name and is readable by humans: +# my_object.o: T my_function +# By using the `t` and `d` commands, lines for symbols of type U (undefined) +# as well as V and W (weak) and their local lowercase variants are removed. +# 3. Use sort to sort the lines by symbol name. +# 4. Use uniq to only keep the lines corresponding to duplicate symbols. +# 5. Use c++filt to demangle the symbol names. +# c++filt is applied to the duplicated symbols instead of using the -C flag +# of nm because it is not in POSIX and demangled names may not be unique +# (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35201). +DUPLICATE_SYMBOLS=$( + "/usr/bin/nm" -A -g -P "$1" | + sed -E -e 's/.*\[([^][]+)\]: (.+) ([A-TX-Z]) [a-f0-9]+ [a-f0-9]+/\1: \3 \2/g' -e t -e d | + LC_ALL=C sort -k 3 | + LC_ALL=C uniq -D -f 2 | + "/usr/bin/c++filt") +if [[ -n "$DUPLICATE_SYMBOLS" ]]; then + >&2 echo "Duplicate symbols found in $1:" + >&2 echo "$DUPLICATE_SYMBOLS" + exit 1 +else + touch "$2" +fi diff --git a/scripts/remote-image/Dockerfile b/scripts/remote-image/Dockerfile index d216cd1a7ac54..67a357f3ff5de 100644 --- a/scripts/remote-image/Dockerfile +++ b/scripts/remote-image/Dockerfile @@ -1,5 +1,5 @@ # Our images must be for Linux x86_64 -FROM --platform=linux/amd64 ubuntu:focal@sha256:8e5c4f0285ecbb4ead070431d29b576a530d3166df73ec44affc1cd27555141b +FROM --platform=linux/amd64 ubuntu:jammy@sha256:4f838adc7181d9039ac795a7d0aba05a9bd9ecd480d294483169c5def983b64d ENV DEBIAN_FRONTEND=noninteractive @@ -9,6 +9,7 @@ RUN apt-get -qqy update && \ build-essential \ libcrypt-dev \ libnet1 \ + libyaml-dev \ libzip-dev \ linux-libc-dev \ python3.10 \ @@ -48,7 +49,7 @@ RUN apt-get update -qqy && \ fonts-tlwg-loma-otf \ fonts-noto-color-emoji \ pulseaudio \ - ttf-ubuntu-font-family \ + fonts-ubuntu \ xfonts-cyrillic \ xfonts-scalable \ xvfb && \ diff --git a/scripts/remote-image/create-cc-toolchain-within-image.sh b/scripts/remote-image/create-cc-toolchain-within-image.sh index ee4826d8a13f4..631d859060e18 100755 --- a/scripts/remote-image/create-cc-toolchain-within-image.sh +++ b/scripts/remote-image/create-cc-toolchain-within-image.sh @@ -11,8 +11,17 @@ chmod +x /usr/bin/bazel temp="$(mktemp -d)" cd "$temp" -touch WORKSPACE BUILD.bazel +cat > MODULE.bazel <<'EOF' +module(name = "ccregen") +bazel_dep(name = "rules_cc", version = "0.2.18") +cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") +use_repo(cc_configure, "local_config_cc") +EOF +touch BUILD.bazel + bazel build @local_config_cc//... + +src="$(bazel info output_base)/external/rules_cc++cc_configure_extension+local_config_cc" rm -rf /code/common/remote-build/cc mkdir /code/common/remote-build/cc -cp -Lr $(bazel info output_base)/external/local_config_cc/* /code/common/remote-build/cc +cp -Lr "$src"/* /code/common/remote-build/cc diff --git a/scripts/remote-image/create-cc-toolchain.sh b/scripts/remote-image/create-cc-toolchain.sh index 0b744d2460ee3..a042a1f60b071 100755 --- a/scripts/remote-image/create-cc-toolchain.sh +++ b/scripts/remote-image/create-cc-toolchain.sh @@ -8,6 +8,7 @@ docker run \ -v $(pwd):/code \ --rm \ --platform linux/amd64 \ + --user 0 \ -w /code \ --entrypoint /code/scripts/remote-image/create-cc-toolchain-within-image.sh \ selenium-remote-build