diff --git a/MODULE.bazel b/MODULE.bazel index ee4789b..e7e5603 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module( 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") cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") diff --git a/cc/toolchains/impl/toolchain_config.bzl b/cc/toolchains/impl/toolchain_config.bzl index bd1b89e..82e6695 100644 --- a/cc/toolchains/impl/toolchain_config.bzl +++ b/cc/toolchains/impl/toolchain_config.bzl @@ -14,6 +14,7 @@ """Implementation of the cc_toolchain rule.""" load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") +load("@bazel_skylib//rules/directory:providers.bzl", "DirectoryInfo") load( "//cc/toolchains:cc_toolchain_info.bzl", "ActionTypeConfigSetInfo", @@ -64,13 +65,22 @@ def _cc_toolchain_config_impl(ctx): 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 [ toolchain_config, cc_common.create_cc_toolchain_config_info( ctx = ctx, action_configs = legacy.action_configs, 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 # in an error that it expected a string, and for safety's sake, I'd # prefer to provide something unique. @@ -81,7 +91,7 @@ def _cc_toolchain_config_impl(ctx): compiler = ctx.attr.compiler, abi_version = ctx.attr.abi_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. # 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"), "_enabled": attr.label(default = "//cc/toolchains:experimental_enable_rule_based_toolchains"), - # Attributes from create_cc_toolchain_config_info. - # artifact_name_patterns is currently unused. Consider adding it later. - # TODO: Consider making this into a label_list that takes a - # cc_directory_marker rule as input. - "cxx_builtin_include_directories": attr.string_list(), + # Attributes translated from legacy cc toolchains. + "sysroot": attr.label(providers = [DirectoryInfo]), + "cxx_builtin_include_directories": attr.label_list(providers = [DirectoryInfo]), + + # TODO: remove these fields. I'm pretty sure they're unnecessary with + # --incompatible_enable_cc_toolchain_resolution. "target_system_name": attr.string(), "target_cpu": attr.string(), "target_libc": attr.string(), "compiler": attr.string(mandatory = True), "abi_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], ) diff --git a/tests/rule_based_toolchain/testdata/BUILD b/tests/rule_based_toolchain/testdata/BUILD index 4bfb3e6..fa2cdd8 100644 --- a/tests/rule_based_toolchain/testdata/BUILD +++ b/tests/rule_based_toolchain/testdata/BUILD @@ -1,7 +1,16 @@ 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__"]) +directory( + name = "directory", + srcs = glob( + ["*"], + exclude = ["BUILD"], + ), +) + exports_files( glob( ["*"], diff --git a/tests/rule_based_toolchain/toolchain_config/BUILD b/tests/rule_based_toolchain/toolchain_config/BUILD index 0068963..3fac686 100644 --- a/tests/rule_based_toolchain/toolchain_config/BUILD +++ b/tests/rule_based_toolchain/toolchain_config/BUILD @@ -47,7 +47,11 @@ util.helper_target( action_type_configs = [":compile_config"], args = [":c_compile_args"], compiler = "gcc-4.1.1", + cxx_builtin_include_directories = [ + "//tests/rule_based_toolchain/testdata:directory", + ], skip_experimental_flag_validation_for_test = True, + sysroot = "//tests/rule_based_toolchain/testdata:directory", target_cpu = "k8", target_libc = "glibc-2.2.2", target_system_name = "local",