Make toolchains use directory markers instead of strings.

BEGIN_PUBLIC
Make toolchains use directory markers instead of strings.

You now refer to this instead of a string containing the repo mapped path.
END_PUBLIC

PiperOrigin-RevId: 639946886
Change-Id: I409be7b7002252b06562a2982a2568e79811877d
This commit is contained in:
Googler 2024-06-03 16:19:58 -07:00 committed by Copybara-Service
parent 1acf5213b6
commit 2351aa42b1
4 changed files with 32 additions and 12 deletions

View File

@ -4,7 +4,7 @@ module(
compatibility_level = 1, compatibility_level = 1,
) )
bazel_dep(name = "bazel_skylib", version = "1.3.0") bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.7") bazel_dep(name = "platforms", version = "0.0.7")
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension")

View File

@ -14,6 +14,7 @@
"""Implementation of the cc_toolchain rule.""" """Implementation of the cc_toolchain rule."""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@bazel_skylib//rules/directory:providers.bzl", "DirectoryInfo")
load( load(
"//cc/toolchains:cc_toolchain_info.bzl", "//cc/toolchains:cc_toolchain_info.bzl",
"ActionTypeConfigSetInfo", "ActionTypeConfigSetInfo",
@ -64,13 +65,22 @@ def _cc_toolchain_config_impl(ctx):
legacy = convert_toolchain(toolchain_config) legacy = convert_toolchain(toolchain_config)
sysroot = None
if ctx.attr.sysroot:
sysroot = ctx.attr.sysroot[DirectoryInfo].path
cxx_builtin_include_directories = [
d[DirectoryInfo].path
for d in ctx.attr.cxx_builtin_include_directories
]
return [ return [
toolchain_config, toolchain_config,
cc_common.create_cc_toolchain_config_info( cc_common.create_cc_toolchain_config_info(
ctx = ctx, ctx = ctx,
action_configs = legacy.action_configs, action_configs = legacy.action_configs,
features = legacy.features, features = legacy.features,
cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, cxx_builtin_include_directories = cxx_builtin_include_directories,
# toolchain_identifier is deprecated, but setting it to None results # toolchain_identifier is deprecated, but setting it to None results
# in an error that it expected a string, and for safety's sake, I'd # in an error that it expected a string, and for safety's sake, I'd
# prefer to provide something unique. # prefer to provide something unique.
@ -81,7 +91,7 @@ def _cc_toolchain_config_impl(ctx):
compiler = ctx.attr.compiler, compiler = ctx.attr.compiler,
abi_version = ctx.attr.abi_version, abi_version = ctx.attr.abi_version,
abi_libc_version = ctx.attr.abi_libc_version, abi_libc_version = ctx.attr.abi_libc_version,
builtin_sysroot = ctx.attr.sysroot or None, builtin_sysroot = sysroot,
), ),
# This allows us to support all_files. # This allows us to support all_files.
# If all_files was simply an alias to # If all_files was simply an alias to
@ -103,21 +113,18 @@ cc_toolchain_config = rule(
"_builtin_features": attr.label(default = "//cc/toolchains/features:all_builtin_features"), "_builtin_features": attr.label(default = "//cc/toolchains/features:all_builtin_features"),
"_enabled": attr.label(default = "//cc/toolchains:experimental_enable_rule_based_toolchains"), "_enabled": attr.label(default = "//cc/toolchains:experimental_enable_rule_based_toolchains"),
# Attributes from create_cc_toolchain_config_info. # Attributes translated from legacy cc toolchains.
# artifact_name_patterns is currently unused. Consider adding it later. "sysroot": attr.label(providers = [DirectoryInfo]),
# TODO: Consider making this into a label_list that takes a "cxx_builtin_include_directories": attr.label_list(providers = [DirectoryInfo]),
# cc_directory_marker rule as input.
"cxx_builtin_include_directories": attr.string_list(), # TODO: remove these fields. I'm pretty sure they're unnecessary with
# --incompatible_enable_cc_toolchain_resolution.
"target_system_name": attr.string(), "target_system_name": attr.string(),
"target_cpu": attr.string(), "target_cpu": attr.string(),
"target_libc": attr.string(), "target_libc": attr.string(),
"compiler": attr.string(mandatory = True), "compiler": attr.string(mandatory = True),
"abi_version": attr.string(), "abi_version": attr.string(),
"abi_libc_version": attr.string(), "abi_libc_version": attr.string(),
# tool_paths currently unused.
# TODO: Consider making this into a label that takes a
# cc_directory_marker rule as an input.
"sysroot": attr.string(),
}, },
provides = [ToolchainConfigInfo], provides = [ToolchainConfigInfo],
) )

View File

@ -1,7 +1,16 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary") load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@bazel_skylib//rules/directory:directory.bzl", "directory")
package(default_visibility = ["//tests/rule_based_toolchain:__subpackages__"]) package(default_visibility = ["//tests/rule_based_toolchain:__subpackages__"])
directory(
name = "directory",
srcs = glob(
["*"],
exclude = ["BUILD"],
),
)
exports_files( exports_files(
glob( glob(
["*"], ["*"],

View File

@ -47,7 +47,11 @@ util.helper_target(
action_type_configs = [":compile_config"], action_type_configs = [":compile_config"],
args = [":c_compile_args"], args = [":c_compile_args"],
compiler = "gcc-4.1.1", compiler = "gcc-4.1.1",
cxx_builtin_include_directories = [
"//tests/rule_based_toolchain/testdata:directory",
],
skip_experimental_flag_validation_for_test = True, skip_experimental_flag_validation_for_test = True,
sysroot = "//tests/rule_based_toolchain/testdata:directory",
target_cpu = "k8", target_cpu = "k8",
target_libc = "glibc-2.2.2", target_libc = "glibc-2.2.2",
target_system_name = "local", target_system_name = "local",