diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index daa7b8e474ee..25e218f3a7a7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,7 +57,8 @@ repos: - id: buildifier name: Bazel buildifier entry: scripts/run_buildifier.py - args: ['-r', '.'] + # Beyond just formatting, explicitly fix lint warnings. + args: ['--lint=fix', '--warnings=all', '-r', '.'] language: python files: | (?x)^( diff --git a/bazel/cc_toolchains/clang_cc_toolchain_config.bzl b/bazel/cc_toolchains/clang_cc_toolchain_config.bzl index 2f2fadf0a01b..26ff416aaf09 100644 --- a/bazel/cc_toolchains/clang_cc_toolchain_config.bzl +++ b/bazel/cc_toolchains/clang_cc_toolchain_config.bzl @@ -4,6 +4,7 @@ """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", @@ -16,7 +17,6 @@ load( "variable_with_value", "with_feature_set", ) -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load( ":clang_detected_variables.bzl", "clang_bindir", @@ -856,7 +856,7 @@ def _impl(ctx): # Next, add the features based on the target platform. Here too the # features are order sensitive. We also setup the sysroot here. if ctx.attr.target_cpu == "k8": - features += [linux_flags_feature] + features.append(linux_flags_feature) sysroot = None elif ctx.attr.target_cpu == "x64_windows": # TODO: Need to figure out if we need to add windows specific features @@ -864,19 +864,19 @@ def _impl(ctx): # so that might be an example where a feature must be added. sysroot = None elif ctx.attr.target_cpu in ["darwin", "darwin_arm64"]: - features += [macos_flags_feature] + features.append(macos_flags_feature) sysroot = sysroot_dir elif ctx.attr.target_cpu == "freebsd": - features += [freebsd_flags_feature] + features.append(freebsd_flags_feature) sysroot = sysroot_dir else: fail("Unsupported target platform!") # TODO: Need to support non-macOS ARM platforms here. if ctx.attr.target_cpu == "darwin_arm64": - features += [aarch64_cpu_flags] + features.append(aarch64_cpu_flags) else: - features += [x86_64_cpu_flags] + features.append(x86_64_cpu_flags) # Finally append the libraries to link and any final flags. features += [ diff --git a/bazel/cc_toolchains/clang_configuration.bzl b/bazel/cc_toolchains/clang_configuration.bzl index ab0e7aadb996..d1fadc2ed002 100644 --- a/bazel/cc_toolchains/clang_configuration.bzl +++ b/bazel/cc_toolchains/clang_configuration.bzl @@ -212,15 +212,15 @@ def _configure_clang_toolchain_impl(repository_ctx): "clang_detected_variables.bzl", repository_ctx.attr._clang_detected_variables_template, substitutions = { - "{LLVM_BINDIR}": str(ar_path.dirname), - "{LLVM_SYMBOLIZER}": str(ar_path.dirname.get_child("llvm-symbolizer")), "{CLANG_BINDIR}": str(clang.dirname), - "{CLANG_VERSION}": str(clang_version), - "{CLANG_VERSION_FOR_CACHE}": clang_version_for_cache.replace('"', "_").replace("\\", "_"), - "{CLANG_RESOURCE_DIR}": resource_dir, "{CLANG_INCLUDE_DIRS_LIST}": str( [str(path) for path in include_dirs], ), + "{CLANG_RESOURCE_DIR}": resource_dir, + "{CLANG_VERSION_FOR_CACHE}": clang_version_for_cache.replace('"', "_").replace("\\", "_"), + "{CLANG_VERSION}": str(clang_version), + "{LLVM_BINDIR}": str(ar_path.dirname), + "{LLVM_SYMBOLIZER}": str(ar_path.dirname.get_child("llvm-symbolizer")), "{SYSROOT}": str(sysroot_dir), }, executable = False, @@ -231,10 +231,6 @@ configure_clang_toolchain = repository_rule( configure = True, local = True, attrs = { - "_clang_toolchain_build": attr.label( - default = Label("//bazel/cc_toolchains:clang_toolchain.BUILD"), - allow_single_file = True, - ), "_clang_cc_toolchain_config": attr.label( default = Label( "//bazel/cc_toolchains:clang_cc_toolchain_config.bzl", @@ -247,6 +243,10 @@ configure_clang_toolchain = repository_rule( ), allow_single_file = True, ), + "_clang_toolchain_build": attr.label( + default = Label("//bazel/cc_toolchains:clang_toolchain.BUILD"), + allow_single_file = True, + ), }, environ = ["CC"], ) diff --git a/bazel/check_deps/BUILD b/bazel/check_deps/BUILD index 7092fd492389..54280aa07cd7 100644 --- a/bazel/check_deps/BUILD +++ b/bazel/check_deps/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_python//python:defs.bzl", "py_test") + # The filegroups establishing root rules for `genquery` invocations can be # updated by running: # diff --git a/common/BUILD b/common/BUILD index 8187cc7e74f4..81fcf9eb1895 100644 --- a/common/BUILD +++ b/common/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = ["//visibility:public"]) cc_library( diff --git a/explorer/BUILD b/explorer/BUILD index a3dae7c826d8..f0c3f46e441e 100644 --- a/explorer/BUILD +++ b/explorer/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") load("//bazel/cc_toolchains:defs.bzl", "cc_env") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test") diff --git a/explorer/ast/BUILD b/explorer/ast/BUILD index ef76b2e2f1a7..27f19b867c23 100644 --- a/explorer/ast/BUILD +++ b/explorer/ast/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = ["//explorer:__subpackages__"]) cc_library( diff --git a/explorer/base/BUILD b/explorer/base/BUILD index dfb7f07cadfe..31e0878296bb 100644 --- a/explorer/base/BUILD +++ b/explorer/base/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = ["//explorer:__subpackages__"]) cc_library( diff --git a/explorer/fuzzing/BUILD b/explorer/fuzzing/BUILD index 454ab8ea0678..86b17606e060 100644 --- a/explorer/fuzzing/BUILD +++ b/explorer/fuzzing/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") cc_library( diff --git a/explorer/interpreter/BUILD b/explorer/interpreter/BUILD index 58448fde4ebd..7383217d2106 100644 --- a/explorer/interpreter/BUILD +++ b/explorer/interpreter/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library") + package(default_visibility = ["//explorer/parse_and_execute:__pkg__"]) cc_library( diff --git a/explorer/parse_and_execute/BUILD b/explorer/parse_and_execute/BUILD index 7ce7d6f18be2..f2a7a294ea8b 100644 --- a/explorer/parse_and_execute/BUILD +++ b/explorer/parse_and_execute/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = [ "//explorer:__pkg__", "//explorer/fuzzing:__pkg__", diff --git a/explorer/syntax/BUILD b/explorer/syntax/BUILD index c95d36b93b45..32a01bdf0f1c 100644 --- a/explorer/syntax/BUILD +++ b/explorer/syntax/BUILD @@ -2,6 +2,9 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@rules_python//python:defs.bzl", "py_library", "py_test") + package(default_visibility = ["//explorer/parse_and_execute:__pkg__"]) cc_library( diff --git a/github_tools/BUILD b/github_tools/BUILD index 56627780b2a0..144fab958282 100644 --- a/github_tools/BUILD +++ b/github_tools/BUILD @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception load("@py_deps//:requirements.bzl", "requirement") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") py_library( name = "github_helpers", diff --git a/installers/local/BUILD b/installers/local/BUILD index 664d13142ff8..8be4a986e84d 100644 --- a/installers/local/BUILD +++ b/installers/local/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_binary") load("install.bzl", "install_path_rule") # Turns `--//installers/local:install_path=arg` into `$(INSTALL_PATH)`. diff --git a/language_server/BUILD b/language_server/BUILD index f552b9abcc0c..f9c3ca7ab742 100644 --- a/language_server/BUILD +++ b/language_server/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_binary") + package(default_visibility = [ "//language_server:__subpackages__", ]) diff --git a/migrate_cpp/BUILD b/migrate_cpp/BUILD index 8cc0fd5d08b0..0d237c6eebaf 100644 --- a/migrate_cpp/BUILD +++ b/migrate_cpp/BUILD @@ -2,6 +2,9 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@rules_python//python:defs.bzl", "py_binary") + py_binary( name = "migrate_cpp", srcs = ["migrate_cpp.py"], diff --git a/migrate_cpp/cpp_refactoring/BUILD b/migrate_cpp/cpp_refactoring/BUILD index f1809a3ec79a..d566e1caad7e 100644 --- a/migrate_cpp/cpp_refactoring/BUILD +++ b/migrate_cpp/cpp_refactoring/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") + package(default_visibility = ["//visibility:public"]) cc_binary( diff --git a/proposals/scripts/BUILD b/proposals/scripts/BUILD index a9349ab4fbd3..8eac0680c72e 100644 --- a/proposals/scripts/BUILD +++ b/proposals/scripts/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_python//python:defs.bzl", "py_binary", "py_test") + py_binary( name = "new_proposal", srcs = ["new_proposal.py"], diff --git a/testing/base/BUILD b/testing/base/BUILD index 631cf2062ec8..f70426ff71a1 100644 --- a/testing/base/BUILD +++ b/testing/base/BUILD @@ -5,6 +5,8 @@ # Trivial, single-file testing libraries. More complex libraries should get # their own directory. +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = ["//visibility:public"]) # This does extra initialization on top of googletest's gtest_main in order to diff --git a/testing/file_test/BUILD b/testing/file_test/BUILD index 066a693e012a..1343b6888b8f 100644 --- a/testing/file_test/BUILD +++ b/testing/file_test/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library") load("rules.bzl", "file_test") package(default_visibility = ["//visibility:public"]) diff --git a/testing/file_test/rules.bzl b/testing/file_test/rules.bzl index 030ffe65f26e..008ff9d63516 100644 --- a/testing/file_test/rules.bzl +++ b/testing/file_test/rules.bzl @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_test") + """Rules for building fuzz tests.""" def file_test(name, tests, data = [], args = [], **kwargs): @@ -18,7 +20,7 @@ def file_test(name, tests, data = [], args = [], **kwargs): args: Passed to cc_test. **kwargs: Passed to cc_test. """ - native.cc_test( + cc_test( name = name, data = tests + data, args = ["--file_tests=" + ",".join([ diff --git a/testing/fuzzing/BUILD b/testing/fuzzing/BUILD index 229ef75d4738..574ba8fa2620 100644 --- a/testing/fuzzing/BUILD +++ b/testing/fuzzing/BUILD @@ -2,7 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "cc_test") load("@rules_proto//proto:defs.bzl", "proto_library") package(default_visibility = ["//visibility:public"]) diff --git a/third_party/examples/woff2/BUILD.original b/third_party/examples/woff2/BUILD.original index d695462a8c30..13aa377d1153 100644 --- a/third_party/examples/woff2/BUILD.original +++ b/third_party/examples/woff2/BUILD.original @@ -4,6 +4,8 @@ # Rules are adapted from CMakeLists.txt. +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + package( default_visibility = ["//visibility:public"], ) diff --git a/third_party/examples/woff2/carbon/BUILD b/third_party/examples/woff2/carbon/BUILD index d695462a8c30..13aa377d1153 100644 --- a/third_party/examples/woff2/carbon/BUILD +++ b/third_party/examples/woff2/carbon/BUILD @@ -4,6 +4,8 @@ # Rules are adapted from CMakeLists.txt. +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + package( default_visibility = ["//visibility:public"], ) diff --git a/third_party/libprotobuf_mutator/BUILD.txt b/third_party/libprotobuf_mutator/BUILD.txt index c8bcadfd84d4..cb10edc1b019 100644 --- a/third_party/libprotobuf_mutator/BUILD.txt +++ b/third_party/libprotobuf_mutator/BUILD.txt @@ -5,6 +5,8 @@ # libprotobuf_mutator uses cmake and doesn't provide a bazel BUILD file. # See https://github.com/google/libprotobuf-mutator/issues/91. +load("@rules_cc//cc:defs.bzl", "cc_library") + exports_files(["LICENSE"]) cc_library( diff --git a/toolchain/base/BUILD b/toolchain/base/BUILD index d5f43c698c83..7d0df7c41095 100644 --- a/toolchain/base/BUILD +++ b/toolchain/base/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library") + package(default_visibility = ["//visibility:public"]) cc_library( diff --git a/toolchain/codegen/BUILD b/toolchain/codegen/BUILD index 37472ee6c823..7a681318ae4d 100644 --- a/toolchain/codegen/BUILD +++ b/toolchain/codegen/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library") load("//testing/file_test:rules.bzl", "file_test") package(default_visibility = ["//visibility:public"]) diff --git a/toolchain/diagnostics/BUILD b/toolchain/diagnostics/BUILD index 7050ce1318d6..151ffa69ceac 100644 --- a/toolchain/diagnostics/BUILD +++ b/toolchain/diagnostics/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = ["//visibility:public"]) cc_library( diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index d28566bfcbb6..c14de157fdae 100644 --- a/toolchain/driver/BUILD +++ b/toolchain/driver/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("//bazel/cc_toolchains:defs.bzl", "cc_env") load("//testing/file_test:rules.bzl", "file_test") load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") diff --git a/toolchain/lexer/BUILD b/toolchain/lexer/BUILD index 5db349dd874e..ec26606d1b96 100644 --- a/toolchain/lexer/BUILD +++ b/toolchain/lexer/BUILD @@ -2,9 +2,10 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") package(default_visibility = ["//visibility:public"]) diff --git a/toolchain/lowering/BUILD b/toolchain/lowering/BUILD index 5a0412b1b266..bb6908d4bc59 100644 --- a/toolchain/lowering/BUILD +++ b/toolchain/lowering/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test") diff --git a/toolchain/parser/BUILD b/toolchain/parser/BUILD index da333ba401fe..19eaed04c4af 100644 --- a/toolchain/parser/BUILD +++ b/toolchain/parser/BUILD @@ -2,9 +2,10 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") package(default_visibility = ["//visibility:public"]) diff --git a/toolchain/semantics/BUILD b/toolchain/semantics/BUILD index ae95bcb2e472..c993ad4cfd7c 100644 --- a/toolchain/semantics/BUILD +++ b/toolchain/semantics/BUILD @@ -2,9 +2,10 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") package(default_visibility = ["//visibility:public"]) diff --git a/toolchain/source/BUILD b/toolchain/source/BUILD index 50b18e829caf..2c2fce67073a 100644 --- a/toolchain/source/BUILD +++ b/toolchain/source/BUILD @@ -2,6 +2,8 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = ["//visibility:public"]) cc_library( diff --git a/utils/treesitter/BUILD b/utils/treesitter/BUILD index 58e449a07657..61d540f192e0 100644 --- a/utils/treesitter/BUILD +++ b/utils/treesitter/BUILD @@ -2,6 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test") load("@rules_tree_sitter//tree_sitter:tree_sitter.bzl", "tree_sitter_cc_library") tree_sitter_cc_library(