diff --git a/base/cvd/toolchain/BUILD.bazel b/base/cvd/toolchain/BUILD.bazel index 973cc94371a..c6ec9a357d6 100644 --- a/base/cvd/toolchain/BUILD.bazel +++ b/base/cvd/toolchain/BUILD.bazel @@ -1,86 +1,3 @@ -load(":cc_toolchain_macro.bzl", "linux_local_clang") - package(default_visibility = ["//visibility:public"]) filegroup(name = "empty") - -linux_local_clang( - name = "linux_local_clang_19", - exec_compatible_with = [ - "@clang_detector//:clang_19_present", - "@platforms//os:linux", - ], - version = 19, -) - -linux_local_clang( - name = "linux_local_clang_18", - exec_compatible_with = [ - "@clang_detector//:clang_18_present", - "@platforms//os:linux", - ], - version = 18, -) - -linux_local_clang( - name = "linux_local_clang_17", - exec_compatible_with = [ - "@clang_detector//:clang_17_present", - "@platforms//os:linux", - ], - version = 17, -) - -linux_local_clang( - name = "linux_local_clang_16", - exec_compatible_with = [ - "@clang_detector//:clang_16_present", - "@platforms//os:linux", - ], - version = 16, -) - -linux_local_clang( - name = "linux_local_clang_15", - exec_compatible_with = [ - "@clang_detector//:clang_15_present", - "@platforms//os:linux", - ], - version = 15, -) - -linux_local_clang( - name = "linux_local_clang_14", - exec_compatible_with = [ - "@clang_detector//:clang_14_present", - "@platforms//os:linux", - ], - version = 14, -) - -linux_local_clang( - name = "linux_local_clang_13", - exec_compatible_with = [ - "@clang_detector//:clang_13_present", - "@platforms//os:linux", - ], - version = 13, -) - -linux_local_clang( - name = "linux_local_clang_12", - exec_compatible_with = [ - "@clang_detector//:clang_12_present", - "@platforms//os:linux", - ], - version = 12, -) - -linux_local_clang( - name = "linux_local_clang_11", - exec_compatible_with = [ - "@clang_detector//:clang_11_present", - "@platforms//os:linux", - ], - version = 11, -) diff --git a/base/cvd/toolchain/cc_toolchain_config.bzl b/base/cvd/toolchain/cc_toolchain_config.bzl deleted file mode 100644 index ac072ff9747..00000000000 --- a/base/cvd/toolchain/cc_toolchain_config.bzl +++ /dev/null @@ -1,114 +0,0 @@ -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "feature", - "flag_group", - "flag_set", - "tool_path", -) - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -# Relevant documentation: -# - https://bazel.build/rules/lib/providers/CcToolchainInfo -# - https://bazel.build/rules/lib/toplevel/cc_common#create_cc_toolchain_config_info -# - https://bazel.build/tutorials/ccp-toolchain-config -def _impl(ctx): - tool_paths = [ - tool_path( - name = "gcc", - path = "/usr/bin/clang-%d" % ctx.attr.version, - ), - tool_path( - name = "ld", - path = "/usr/bin/ld", - ), - tool_path( - name = "ar", - path = "/usr/bin/ar", - ), - tool_path( - name = "cpp", - path = "/bin/false", - ), - tool_path( - name = "gcov", - path = "/bin/false", - ), - tool_path( - name = "nm", - path = "/bin/false", - ), - tool_path( - name = "objdump", - path = "/bin/false", - ), - tool_path( - name = "strip", - path = "/bin/false", - ), - ] - - features = [ - feature( - name = "default_linker_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_compile, ACTION_NAMES.c_compile], - flag_groups = ([ - flag_group( - flags = [ - "-fPIC", - ], - ), - ]), - ), - flag_set( - actions = all_link_actions, - flag_groups = ([ - flag_group( - flags = [ - "-lm", - "-lstdc++", - ], - ), - ]), - ), - ], - ), - ] - - return cc_common.create_cc_toolchain_config_info( - ctx = ctx, - features = features, - cxx_builtin_include_directories = [ - "/usr/include", - "/usr/lib/clang/%d" % ctx.attr.version, - "/usr/lib/llvm-%d/lib/clang/" % ctx.attr.version, - ], - toolchain_identifier = "local", - host_system_name = "local", - target_system_name = "local", - target_cpu = "k8", - target_libc = "unknown", - compiler = "clang", - abi_version = "unknown", - abi_libc_version = "unknown", - tool_paths = tool_paths, - ) - -# Relevant documentation: -# - https://bazel.build/rules/lib/globals/bzl.html#rule -# - https://bazel.build/rules/lib/toplevel/attr.html#int -linux_local_clang_toolchain_config = rule( - implementation = _impl, - attrs = { - "version": attr.int(mandatory = True), - }, - provides = [CcToolchainConfigInfo], -) diff --git a/base/cvd/toolchain/cc_toolchain_macro.bzl b/base/cvd/toolchain/cc_toolchain_macro.bzl deleted file mode 100644 index 7377bb7202c..00000000000 --- a/base/cvd/toolchain/cc_toolchain_macro.bzl +++ /dev/null @@ -1,49 +0,0 @@ -load(":cc_toolchain_config.bzl", "linux_local_clang_toolchain_config") - -# Relevant documentation: -# - https://bazel.build/extending/macros -# - https://bazel.build/extending/toolchains -# - https://bazel.build/reference/be/platforms-and-toolchains#toolchain -# - https://bazel.build/tutorials/ccp-toolchain-config -def _linux_local_clang_impl(name, visibility, exec_compatible_with, version, **kwargs): - linux_local_clang_toolchain_config( - name = name + "_config", - visibility = ["//visibility:private"], - version = version, - ) - native.cc_toolchain( - name = name + "_cc_toolchain", - visibility = ["//visibility:private"], - toolchain_identifier = name, - toolchain_config = ":" + name + "_config", - all_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - ) - native.toolchain( - name = name, - visibility = visibility, - toolchain = ":" + name + "_cc_toolchain", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", - exec_compatible_with = exec_compatible_with, - target_compatible_with = ["@platforms//os:linux"], - **kwargs, - ) - -# Defines a compiler toolchain that calls /usr/bin/clang-{version} to compile and link c++. -# -# Relevant documentation: -# - https://bazel.build/rules/lib/globals/bzl.html#macro -# - https://bazel.build/rules/lib/toplevel/attr#int -# - https://bazel.build/rules/lib/toplevel/attr#label_list -linux_local_clang = macro( - attrs = { - "exec_compatible_with": attr.label_list(configurable = False), - "version": attr.int(configurable = False, mandatory = True), - }, - implementation = _linux_local_clang_impl, -) diff --git a/base/cvd/toolchain/file_detector.bzl b/base/cvd/toolchain/file_detector.bzl deleted file mode 100644 index 36955c0f1ab..00000000000 --- a/base/cvd/toolchain/file_detector.bzl +++ /dev/null @@ -1,86 +0,0 @@ -# Relevant documentation: -# - https://bazel.build/reference/be/platforms-and-toolchains -# - https://bazel.build/rules/lib/builtins/path.html -# - https://bazel.build/rules/lib/builtins/repository_ctx -# - https://bazel.build/rules/lib/globals/bzl.html#repository_rule -def _file_detector_impl(repository_ctx): - root_build_file = 'package(default_visibility = ["//visibility:public"])\n\n' - for (filename, constraint_setting) in repository_ctx.attr.files.items(): - file_path = repository_ctx.path(filename) - repository_ctx.watch(file_path) - if file_path.exists: - exists_str = "present" - else: - exists_str = "absent" - build_fragment = """ -constraint_setting( - name = "{0}", - default_constraint_value = ":{0}_{1}" -) -constraint_value( - name = "{0}_present", - constraint_setting = ":{0}", -) -constraint_value( - name = "{0}_absent", - constraint_setting = ":{0}", -) - """.strip().format(constraint_setting, exists_str) - root_build_file += "\n" + build_fragment + "\n" - build_file = repository_ctx.path("BUILD.bazel") - repository_ctx.file(build_file, root_build_file, False) - -# Creates a repository that defines `constraint_setting`s and -# `constraint_value`s based on the existence of some files on the host. -# -# Example usage: -# ``` -# file_detector = use_repo_rule("//toolchain:file_detector.bzl", "file_detector") -# -# file_detector( -# name = "clang_detector", -# files = { -# "/usr/bin/clang-11": "clang_11", -# }, -# ), -# ``` -# This expands to a repository `@clang_detector` defining the following -# targets: -# ``` -# constraint_setting( -# name = "clang_11", -# default_constraint_value = ":clang_11_present", -# ) -# constraint_value( -# name = "clang_11_present", -# constraint_setting = ":clang_11", -# ) -# constraint_value( -# name = "clang_11_absent", -# constraint_setting = ":clang_11", -# ) -# ``` -# The default constraint value of the "@clang_detector//:clang_11" setting is -# set to either "@clang_detector//:clang_11_present" or -# "@clang_detector//:clang_11_absent" depending on whether the file -# /usr/bin/clang-11 is present on the host. -# -# This is helpful for toolchain resolution. A toolchain relying on host -# executables can reference these constraints in its `exec_compatible_with` -# list, which is used to report availability. -# -# Relevant documentation: -# - https://bazel.build/extending/toolchains -# - https://bazel.build/reference/be/platforms-and-toolchains -# - https://bazel.build/rules/lib/globals/bzl.html#repository_rule -# - https://bazel.build/rules/lib/toplevel/attr#string_dict -file_detector = repository_rule( - implementation = _file_detector_impl, - attrs = { - "files": attr.string_dict( - allow_empty = False, - configurable = False, - mandatory = True, - ), - }, -)