From 1edd65f80bd8ded5cb2c0ebeec818784ebd76bfb Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 26 Apr 2022 21:16:18 -0700 Subject: [PATCH] bazel: remove rules_cc (#19760) The plans for bazel to move to rules_cc have been postponed without any communication. There's no value to us in using this right now, but it will be trivial to re-adopt in the future if needed. But it has the downside of using a fork of bazel's crosstool, that has to be updated independently of bazel, which doesn't always happen as improvements are made. More details: https://github.com/bazelbuild/rules_cc/issues/86 https://github.com/bazelbuild/bazel/issues/14150 This also required a `--host_action_env` addition to mirror the variables we pass through to actions in general. This is required because C++ toolchain setup which discovers linkers in the cc configuration which uses PATH directly, but then host actions didn't use PATH because of --incompatible_strict_action_env, so gcc couldn't discover the path of lld even though `-fuse-ld=lld` was passed. Fixes https://github.com/envoyproxy/envoy/issues/16608 Signed-off-by: Keith Smiley --- .bazelrc | 8 ++++---- api/bazel/api_build_system.bzl | 3 +-- bazel/BUILD | 1 - bazel/dependency_imports.bzl | 3 --- bazel/envoy_binary.bzl | 4 +--- bazel/envoy_library.bzl | 10 ++++------ bazel/envoy_pch.bzl | 4 +--- bazel/envoy_test.bzl | 7 +++---- bazel/external/BUILD | 2 -- bazel/external/boringssl_fips.BUILD | 1 - bazel/external/compiler_rt.BUILD | 2 -- bazel/external/fmtlib.BUILD | 2 -- bazel/external/http_parser/BUILD | 2 -- bazel/external/json.BUILD | 2 -- bazel/external/libcircllhist.BUILD | 2 -- bazel/external/libprotobuf_mutator.BUILD | 2 -- bazel/external/quiche.BUILD | 1 - bazel/external/rapidjson.BUILD | 2 -- bazel/external/spdlog.BUILD | 2 -- bazel/external/sqlparser.BUILD | 2 -- bazel/external/su-exec.BUILD | 2 -- bazel/external/tclap.BUILD | 2 -- bazel/external/wasm-c-api.BUILD | 2 -- bazel/external/wasmtime.BUILD | 1 - bazel/external/xxhash.BUILD | 2 -- bazel/foreign_cc/BUILD | 1 - bazel/repositories.bzl | 1 - bazel/repository_locations.bzl | 10 ---------- contrib/vcl/source/BUILD | 1 - source/common/protobuf/BUILD | 1 - source/extensions/common/wasm/ext/BUILD | 1 - test/extensions/filters/http/wasm/test_data/BUILD | 1 - tools/clang_tools/support/clang_tools.bzl | 8 +++----- tools/testdata/check_format/skip_envoy_package.BUILD | 2 -- .../check_format/skip_envoy_package.BUILD.gold | 2 -- 35 files changed, 17 insertions(+), 82 deletions(-) diff --git a/.bazelrc b/.bazelrc index ff53ce5cb4d7..cc2e86a7aa40 100644 --- a/.bazelrc +++ b/.bazelrc @@ -21,10 +21,10 @@ build --tool_java_runtime_version=remotejdk_11 build --platform_mappings=bazel/platform_mappings # Pass PATH, CC, CXX and LLVM_CONFIG variables from the environment. -build --action_env=CC -build --action_env=CXX -build --action_env=LLVM_CONFIG -build --action_env=PATH +build --action_env=CC --host_action_env=CC +build --action_env=CXX --host_action_env=CXX +build --action_env=LLVM_CONFIG --host_action_env=LLVM_CONFIG +build --action_env=PATH --host_action_env=PATH build --enable_platform_specific_config diff --git a/api/bazel/api_build_system.bzl b/api/bazel/api_build_system.bzl index 8a0e0bf71021..a2f8d84eaea3 100644 --- a/api/bazel/api_build_system.bzl +++ b/api/bazel/api_build_system.bzl @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_test") load("@com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library") load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") load("@com_google_protobuf//:protobuf.bzl", _py_proto_library = "py_proto_library") @@ -143,7 +142,7 @@ def api_cc_py_proto_library( _api_cc_grpc_library(name = cc_grpc_name, proto = relative_name, deps = cc_proto_deps) def api_cc_test(name, **kwargs): - cc_test( + native.cc_test( name = name, **kwargs ) diff --git a/bazel/BUILD b/bazel/BUILD index c338ead03ac4..905d3fa6ad61 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library") load("//bazel:envoy_build_system.bzl", "envoy_package") load("//bazel:envoy_internal.bzl", "envoy_select_force_libcpp") load("//bazel:utils.bzl", "json_data") diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index e45339435cd0..5796dfa00a00 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -7,7 +7,6 @@ load("@upb//bazel:workspace_deps.bzl", "upb_deps") load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") load("@rules_antlr//antlr:deps.bzl", "antlr_dependencies") load("@proxy_wasm_rust_sdk//bazel:dependencies.bzl", "proxy_wasm_rust_sdk_dependencies") -load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains") load("@base_pip3//:requirements.bzl", pip_dependencies = "install_deps") load("@emsdk//:emscripten_deps.bzl", "emscripten_deps") @@ -43,8 +42,6 @@ def envoy_dependency_imports(go_version = GO_VERSION): oss_fuzz = True, honggfuzz = False, ) - rules_cc_dependencies() - rules_cc_toolchains() emscripten_deps() # These dependencies, like most of the Go in this repository, exist only for the API. diff --git a/bazel/envoy_binary.bzl b/bazel/envoy_binary.bzl index f744e60c82f0..b9a339cdf951 100644 --- a/bazel/envoy_binary.bzl +++ b/bazel/envoy_binary.bzl @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") - # DO NOT LOAD THIS FILE. Load envoy_build_system.bzl instead. # Envoy binary targets load( @@ -30,7 +28,7 @@ def envoy_cc_binary( linkopts = linkopts + _envoy_stamped_linkopts() deps = deps + _envoy_stamped_deps() deps = deps + [envoy_external_dep_path(dep) for dep in external_deps] + envoy_stdlib_deps() - cc_binary( + native.cc_binary( name = name, srcs = srcs, data = data, diff --git a/bazel/envoy_library.bzl b/bazel/envoy_library.bzl index 5b1d674483c8..e48943ff9dc0 100644 --- a/bazel/envoy_library.bzl +++ b/bazel/envoy_library.bzl @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - # DO NOT LOAD THIS FILE. Load envoy_build_system.bzl instead. # Envoy library targets load( @@ -40,7 +38,7 @@ def tcmalloc_external_deps(repository): # all envoy targets pass through an envoy-declared Starlark function where they can be modified # before being passed to a native bazel function. def envoy_basic_cc_library(name, deps = [], external_deps = [], **kargs): - cc_library( + native.cc_library( name = name, deps = deps + [envoy_external_dep_path(dep) for dep in external_deps], **kargs @@ -62,7 +60,7 @@ def envoy_cc_extension( visibility = visibility, **kwargs ) - cc_library( + native.cc_library( name = ext_name, tags = tags, deps = select({ @@ -99,7 +97,7 @@ def envoy_cc_library( if tcmalloc_dep: deps += tcmalloc_external_deps(repository) - cc_library( + native.cc_library( name = name, srcs = srcs, hdrs = hdrs, @@ -125,7 +123,7 @@ def envoy_cc_library( # Intended for usage by external consumers. This allows them to disambiguate # include paths via `external/envoy...` - cc_library( + native.cc_library( name = name + "_with_external_headers", hdrs = hdrs, copts = envoy_copts(repository) + copts, diff --git a/bazel/envoy_pch.bzl b/bazel/envoy_pch.bzl index 8d1418596dd2..bb8d4d29c7c5 100644 --- a/bazel/envoy_pch.bzl +++ b/bazel/envoy_pch.bzl @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - # DO NOT LOAD THIS FILE. Load envoy_build_system.bzl instead. # Envoy library targets load( @@ -27,7 +25,7 @@ def envoy_pch_library( visibility, testonly = False, repository = ""): - cc_library( + native.cc_library( name = name + "_libs", visibility = ["//visibility:private"], copts = envoy_copts(repository), diff --git a/bazel/envoy_test.bzl b/bazel/envoy_test.bzl index de13aa09c975..185ff626decb 100644 --- a/bazel/envoy_test.bzl +++ b/bazel/envoy_test.bzl @@ -1,7 +1,6 @@ # DO NOT LOAD THIS FILE. Load envoy_build_system.bzl instead. # Envoy test targets. This includes both test library and test binary targets. load("@rules_python//python:defs.bzl", "py_binary", "py_test") -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("@rules_fuzzing//fuzzing:cc_defs.bzl", "fuzzing_decoration") load(":envoy_binary.bzl", "envoy_cc_binary") load(":envoy_library.bzl", "tcmalloc_external_deps") @@ -42,7 +41,7 @@ def _envoy_cc_test_infrastructure_library( extra_deps = [repository + "//test:test_pch"] pch_copts = envoy_pch_copts(repository, "//test:test_pch") - cc_library( + native.cc_library( name = name, srcs = srcs, hdrs = hdrs, @@ -103,7 +102,7 @@ def envoy_cc_fuzz_test( **kwargs ) - cc_test( + native.cc_test( name = name, copts = envoy_copts("@envoy", test = True), linkopts = _envoy_test_linkopts() + select({ @@ -161,7 +160,7 @@ def envoy_cc_test( exec_properties = {}): coverage_tags = tags + ([] if coverage else ["nocoverage"]) - cc_test( + native.cc_test( name = name, srcs = srcs, data = data, diff --git a/bazel/external/BUILD b/bazel/external/BUILD index 719adb21855a..11dabbc90cee 100644 --- a/bazel/external/BUILD +++ b/bazel/external/BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 # Use a wrapper cc_library with an empty source source file to force diff --git a/bazel/external/boringssl_fips.BUILD b/bazel/external/boringssl_fips.BUILD index 7b913e413614..94fca2ac4c89 100644 --- a/bazel/external/boringssl_fips.BUILD +++ b/bazel/external/boringssl_fips.BUILD @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") load(":genrule_cmd.bzl", "genrule_cmd") licenses(["notice"]) # Apache 2 diff --git a/bazel/external/compiler_rt.BUILD b/bazel/external/compiler_rt.BUILD index 666c4eca06a0..268e04c09c12 100644 --- a/bazel/external/compiler_rt.BUILD +++ b/bazel/external/compiler_rt.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/fmtlib.BUILD b/bazel/external/fmtlib.BUILD index da85ce22ad8f..3000f503fd7f 100644 --- a/bazel/external/fmtlib.BUILD +++ b/bazel/external/fmtlib.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/http_parser/BUILD b/bazel/external/http_parser/BUILD index 5fefacde47dc..303950d7c00b 100644 --- a/bazel/external/http_parser/BUILD +++ b/bazel/external/http_parser/BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/json.BUILD b/bazel/external/json.BUILD index 8a0b359d0fc8..cc19af32bf49 100644 --- a/bazel/external/json.BUILD +++ b/bazel/external/json.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/libcircllhist.BUILD b/bazel/external/libcircllhist.BUILD index 4dff51012671..a77269ef60b0 100644 --- a/bazel/external/libcircllhist.BUILD +++ b/bazel/external/libcircllhist.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/libprotobuf_mutator.BUILD b/bazel/external/libprotobuf_mutator.BUILD index 697a3c6334a4..12fd8b49b51f 100644 --- a/bazel/external/libprotobuf_mutator.BUILD +++ b/bazel/external/libprotobuf_mutator.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/quiche.BUILD b/bazel/external/quiche.BUILD index 70887a8ab5c0..539609c9d4ee 100644 --- a/bazel/external/quiche.BUILD +++ b/bazel/external/quiche.BUILD @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") load( "@envoy//bazel:envoy_build_system.bzl", diff --git a/bazel/external/rapidjson.BUILD b/bazel/external/rapidjson.BUILD index ef3db0ef55ac..6138f5fa351f 100644 --- a/bazel/external/rapidjson.BUILD +++ b/bazel/external/rapidjson.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/spdlog.BUILD b/bazel/external/spdlog.BUILD index 41080ccda63f..cda0f9519c1d 100644 --- a/bazel/external/spdlog.BUILD +++ b/bazel/external/spdlog.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/sqlparser.BUILD b/bazel/external/sqlparser.BUILD index 5a12383074f5..8e14f45e5360 100644 --- a/bazel/external/sqlparser.BUILD +++ b/bazel/external/sqlparser.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/su-exec.BUILD b/bazel/external/su-exec.BUILD index 6f993793cddc..8d0418538f02 100644 --- a/bazel/external/su-exec.BUILD +++ b/bazel/external/su-exec.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") - licenses(["notice"]) # Apache 2 cc_binary( diff --git a/bazel/external/tclap.BUILD b/bazel/external/tclap.BUILD index 39bd270fd749..fabf6c4c3f99 100644 --- a/bazel/external/tclap.BUILD +++ b/bazel/external/tclap.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/external/wasm-c-api.BUILD b/bazel/external/wasm-c-api.BUILD index 8296cdb23e00..8fd92e4ac7c1 100644 --- a/bazel/external/wasm-c-api.BUILD +++ b/bazel/external/wasm-c-api.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 package(default_visibility = ["//visibility:public"]) diff --git a/bazel/external/wasmtime.BUILD b/bazel/external/wasmtime.BUILD index 6eb689c0d27f..16ba412ef268 100644 --- a/bazel/external/wasmtime.BUILD +++ b/bazel/external/wasmtime.BUILD @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:defs.bzl", "rust_static_library") licenses(["notice"]) # Apache 2 diff --git a/bazel/external/xxhash.BUILD b/bazel/external/xxhash.BUILD index 33f9bbe69705..5f8120dfee0f 100644 --- a/bazel/external/xxhash.BUILD +++ b/bazel/external/xxhash.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - licenses(["notice"]) # Apache 2 cc_library( diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD index 6c59c4266db1..d421ff908872 100644 --- a/bazel/foreign_cc/BUILD +++ b/bazel/foreign_cc/BUILD @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") load("//bazel:envoy_build_system.bzl", "envoy_cmake", "envoy_package") load("@rules_foreign_cc//foreign_cc:configure.bzl", "configure_make") diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index cab3cac8d69b..4387c328e4be 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -222,7 +222,6 @@ def envoy_dependencies(skip_targets = []): external_http_archive("bazel_toolchains") external_http_archive("bazel_compdb") external_http_archive("envoy_build_tools") - external_http_archive("rules_cc") external_http_archive("rules_pkg") _com_github_fdio_vpp_vcl() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 250653423ad7..4e924f52e7e8 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -707,16 +707,6 @@ REPOSITORY_LOCATIONS_SPEC = dict( "org_golang_x_tools", ], ), - rules_cc = dict( - project_name = "C++ rules for Bazel", - project_desc = "Bazel rules for the C++ language", - project_url = "https://github.com/bazelbuild/rules_cc", - version = "0.0.1", - sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241", - urls = ["https://github.com/bazelbuild/rules_cc/releases/download/{version}/rules_cc-{version}.tar.gz"], - release_date = "2021-10-07", - use_category = ["build"], - ), rules_foreign_cc = dict( project_name = "Rules for using foreign build systems in Bazel", project_desc = "Rules for using foreign build systems in Bazel", diff --git a/contrib/vcl/source/BUILD b/contrib/vcl/source/BUILD index a75f027b068c..1a3b37b1f796 100644 --- a/contrib/vcl/source/BUILD +++ b/contrib/vcl/source/BUILD @@ -4,7 +4,6 @@ load( "envoy_cc_library", "envoy_contrib_package", ) -load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_python//python:defs.bzl", "py_binary") load("@base_pip3//:requirements.bzl", "requirement") diff --git a/source/common/protobuf/BUILD b/source/common/protobuf/BUILD index f5e52af8a1ad..77aecdfc4d19 100644 --- a/source/common/protobuf/BUILD +++ b/source/common/protobuf/BUILD @@ -1,4 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") load( "//bazel:envoy_build_system.bzl", diff --git a/source/extensions/common/wasm/ext/BUILD b/source/extensions/common/wasm/ext/BUILD index 0d29ec27788a..6363ae9404ca 100644 --- a/source/extensions/common/wasm/ext/BUILD +++ b/source/extensions/common/wasm/ext/BUILD @@ -1,5 +1,4 @@ load("@rules_proto//proto:defs.bzl", "proto_library") -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library") load( "//bazel:envoy_build_system.bzl", "envoy_cc_library", diff --git a/test/extensions/filters/http/wasm/test_data/BUILD b/test/extensions/filters/http/wasm/test_data/BUILD index 8876b3f02b72..c6d1f956a59e 100644 --- a/test/extensions/filters/http/wasm/test_data/BUILD +++ b/test/extensions/filters/http/wasm/test_data/BUILD @@ -1,5 +1,4 @@ load("@rules_proto//proto:defs.bzl", "proto_library") -load("@rules_cc//cc:defs.bzl", "cc_proto_library") load( "//bazel:envoy_build_system.bzl", "envoy_cc_library", diff --git a/tools/clang_tools/support/clang_tools.bzl b/tools/clang_tools/support/clang_tools.bzl index 398b80330b66..f47598f63e9a 100644 --- a/tools/clang_tools/support/clang_tools.bzl +++ b/tools/clang_tools/support/clang_tools.bzl @@ -1,12 +1,10 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") - _clang_tools_copts = [ "-fno-exceptions", "-fno-rtti", ] def clang_tools_cc_binary(name, copts = [], tags = [], deps = [], **kwargs): - cc_binary( + native.cc_binary( name = name, copts = copts + _clang_tools_copts, tags = tags + ["manual"], @@ -15,14 +13,14 @@ def clang_tools_cc_binary(name, copts = [], tags = [], deps = [], **kwargs): ) def clang_tools_cc_library(name, copts = [], **kwargs): - cc_library( + native.cc_library( name = name, copts = copts + _clang_tools_copts, **kwargs ) def clang_tools_cc_test(name, copts = [], deps = [], **kwargs): - cc_test( + native.cc_test( name = name, copts = copts + _clang_tools_copts, deps = deps + ["@com_google_googletest//:gtest_main"], diff --git a/tools/testdata/check_format/skip_envoy_package.BUILD b/tools/testdata/check_format/skip_envoy_package.BUILD index 11d7a8c872b1..51736f94d67d 100644 --- a/tools/testdata/check_format/skip_envoy_package.BUILD +++ b/tools/testdata/check_format/skip_envoy_package.BUILD @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") - licenses(["notice"]) # Apache 2 cc_binary( diff --git a/tools/testdata/check_format/skip_envoy_package.BUILD.gold b/tools/testdata/check_format/skip_envoy_package.BUILD.gold index 11d7a8c872b1..51736f94d67d 100644 --- a/tools/testdata/check_format/skip_envoy_package.BUILD.gold +++ b/tools/testdata/check_format/skip_envoy_package.BUILD.gold @@ -1,5 +1,3 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") - licenses(["notice"]) # Apache 2 cc_binary(