Skip to content

Commit

Permalink
Merge pull request #18820 from comius/prepare-for-bazel-8
Browse files Browse the repository at this point in the history
Cherry-picks for Bazel 8
  • Loading branch information
zhangskz authored Oct 16, 2024
2 parents 72d2975 + 111584f commit 3a78fcc
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ jobs:
cache_key: Bazel7
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:7.1.2-cf84e92285ca133b9c8104ad7b14d70e953cbb8e"
targets: "//src/... //third_party/utf8_range/..."
- config: { name: "Bazel7 with Bzlmod", flags: --enable_bzlmod --enable_workspace }
# TODO: remove -Wno-unreachable-code" when dropping C++14
- config: { name: "Bazel7 with Bzlmod", flags: --enable_bzlmod --enable_workspace --per_file_copt=.*/absl/strings/string_view.h@-Wno-unreachable-code --cxxopt="-Wno-self-assign-overloaded" }
cache_key: Bazel7bzlmod
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:7.1.2-cf84e92285ca133b9c8104ad7b14d70e953cbb8e"
targets: "//src/... //third_party/utf8_range/..."
Expand Down
7 changes: 6 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bazel_dep(

bazel_dep(
name = "rules_cc",
version = "0.0.9",
version = "0.0.13",
)

bazel_dep(
Expand Down Expand Up @@ -84,6 +84,11 @@ bazel_dep(
repo_name = "proto_bazel_features",
)

bazel_dep(
name = "rules_shell",
version = "0.2.0"
)

# Proto toolchains
register_toolchains("//bazel/private/toolchains:all")

Expand Down
23 changes: 23 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,31 @@ bzl_library(
name = "proto_library_bzl",
srcs = ["proto_library.bzl"],
visibility = ["//visibility:public"],
deps = [
"//bazel/private:bazel_proto_library_rule_bzl",
"@proto_bazel_features//:features",
],
)

bzl_library(
name = "cc_proto_library_bzl",
srcs = ["cc_proto_library.bzl"],
visibility = ["//visibility:public"],
deps = ["//bazel/private:bazel_cc_proto_library_bzl"],
)

bzl_library(
name = "java_proto_library_bzl",
srcs = ["java_proto_library.bzl"],
visibility = ["//visibility:public"],
deps = ["//bazel/private:bazel_java_proto_library_rule_bzl"],
)

bzl_library(
name = "java_lite_proto_library_bzl",
srcs = ["java_lite_proto_library.bzl"],
visibility = ["//visibility:public"],
deps = ["//bazel/private:java_lite_proto_library_bzl"],
)

bzl_library(
Expand All @@ -56,3 +63,19 @@ bzl_library(
visibility = ["//visibility:public"],
deps = ["//bazel/private:upb_proto_library_internal_bzl"],
)

# The data in this target is exposed in //bazel/private:for_bazel_tests
filegroup(
name = "for_bazel_tests",
testonly = True,
srcs = [
"BUILD.bazel",
":cc_proto_library_bzl",
":java_lite_proto_library_bzl",
":proto_library_bzl",
":py_proto_library_bzl",
"//bazel/common:for_bazel_tests",
"//bazel/toolchains:for_bazel_tests",
],
visibility = ["//bazel/private:__pkg__"],
)
13 changes: 9 additions & 4 deletions bazel/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
":proto_lang_toolchain_info_bzl",
"//bazel/private:native_bzl",
"//bazel/private:toolchain_helpers_bzl",
"@proto_bazel_features//:features",
],
Expand Down Expand Up @@ -38,9 +39,13 @@ bzl_library(
)

filegroup(
name = "bazel_osx_p4deps",
srcs = glob(["**"]) + ["@proto_bazel_features//:features"],
visibility = [
"//bazel:__pkg__",
name = "for_bazel_tests",
testonly = True,
srcs = [
"BUILD",
"proto_common_bzl",
"proto_info_bzl",
"proto_lang_toolchain_info_bzl",
],
visibility = ["//bazel:__pkg__"],
)
77 changes: 70 additions & 7 deletions bazel/private/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//bazel/private:native_bool_flag.bzl", "native_bool_flag")
load(":native_bool_flag.bzl", "native_bool_flag")

package(default_applicable_licenses = ["//:license"])

Expand Down Expand Up @@ -52,32 +52,84 @@ bzl_library(
visibility = ["//bazel:__subpackages__"],
)

bzl_library(
name = "proto_info_bzl",
srcs = ["proto_info.bzl"],
visibility = ["//bazel:__subpackages__"],
)

bzl_library(
name = "bazel_proto_library_rule_bzl",
srcs = [
"bazel_proto_library_rule.bzl",
],
visibility = ["//bazel:__subpackages__"],
deps = [
":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_info_bzl",
"//bazel/private:toolchain_helpers_bzl",
"@bazel_skylib//lib:paths",
"@bazel_skylib//rules:common_settings",
"@proto_bazel_features//:features",
],
)

bzl_library(
name = "bazel_java_proto_library_rule_bzl",
srcs = [
"bazel_java_proto_library_rule.bzl",
"java_proto_support.bzl",
],
visibility = ["//bazel:__subpackages__"],
deps = [
":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_info_bzl",
"@rules_java//java/common",
],
)

bzl_library(
name = "java_lite_proto_library_bzl",
srcs = [
"java_lite_proto_library.bzl",
"java_proto_support.bzl",
],
visibility = ["//bazel:__subpackages__"],
deps = [
":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_info_bzl",
"@rules_java//java/common",
],
)

bzl_library(
name = "bazel_cc_proto_library_bzl",
srcs = [
"bazel_cc_proto_library.bzl",
"cc_proto_support.bzl",
],
visibility = ["//bazel:__subpackages__"],
deps = [
":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_info_bzl",
"@proto_bazel_features//:features",
"@rules_cc//cc:find_cc_toolchain_bzl",
],
)

bzl_library(
name = "proto_toolchain_rule_bzl",
srcs = [
"proto_toolchain_rule.bzl",
],
visibility = ["//bazel:__subpackages__"],
deps = [
":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_lang_toolchain_info_bzl",
"//bazel/private:toolchain_helpers_bzl",
],
)

Expand Down Expand Up @@ -131,10 +183,21 @@ native_bool_flag(
visibility = ["//bazel:__subpackages__"],
)

bzl_library(
name = "native_bool_flag_bzl",
srcs = ["native_bool_flag.bzl"],
visibility = ["//visibility:private"],
deps = ["@bazel_skylib//rules:common_settings"],
)

filegroup(
name = "bazel_osx_p4deps",
srcs = glob(["**"]),
visibility = [
"//bazel:__pkg__",
name = "for_bazel_tests",
testonly = True,
srcs = [
"BUILD",
":native_bool_flag_bzl",
"//bazel:for_bazel_tests",
"//bazel/private/toolchains:for_bazel_tests",
],
visibility = ["//visibility:public"],
)
3 changes: 2 additions & 1 deletion bazel/private/bazel_cc_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"""Bazel's implementation of cc_proto_library"""

load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//bazel/common:proto_common.bzl", "proto_common")
load("//bazel/common:proto_info.bzl", "ProtoInfo")
load("//bazel/private:cc_proto_support.bzl", "cc_proto_compile_and_link")
load("//bazel/private:toolchain_helpers.bzl", "toolchains")

_CC_PROTO_TOOLCHAIN = "//bazel/private:cc_toolchain_type"
_CC_PROTO_TOOLCHAIN = Label("//bazel/private:cc_toolchain_type")

_ProtoCcFilesInfo = provider(fields = ["files"], doc = "Provide cc proto files.")
_ProtoCcHeaderInfo = provider(fields = ["headers"], doc = "Provide cc proto headers.")
Expand Down
2 changes: 1 addition & 1 deletion bazel/private/bazel_java_proto_library_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ load("//bazel/common:proto_info.bzl", "ProtoInfo")
load("//bazel/private:java_proto_support.bzl", "JavaProtoAspectInfo", "java_compile_for_protos", "java_info_merge_for_protos")
load("//bazel/private:toolchain_helpers.bzl", "toolchains")

_JAVA_PROTO_TOOLCHAIN = "//bazel/private:java_toolchain_type"
_JAVA_PROTO_TOOLCHAIN = Label("//bazel/private:java_toolchain_type")

def _filter_provider(provider, *attrs):
return [dep[provider] for attr in attrs for dep in attr if provider in dep]
Expand Down
2 changes: 2 additions & 0 deletions bazel/private/cc_proto_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

load("@proto_bazel_features//:features.bzl", "bazel_features")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")

def get_feature_configuration(ctx, has_sources, extra_requested_features = []):
"""Returns C++ feature configuration for compiling and linking generated C++ files.
Expand Down
2 changes: 1 addition & 1 deletion bazel/private/java_lite_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load("//bazel/private:toolchain_helpers.bzl", "toolchains")

_PROTO_TOOLCHAIN_ATTR = "_aspect_proto_toolchain_for_javalite"

_JAVA_LITE_PROTO_TOOLCHAIN = "//bazel/private:javalite_toolchain_type"
_JAVA_LITE_PROTO_TOOLCHAIN = Label("//bazel/private:javalite_toolchain_type")

def _aspect_impl(target, ctx):
"""Generates and compiles Java code for a proto_library dependency graph.
Expand Down
2 changes: 1 addition & 1 deletion bazel/private/toolchain_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ toolchains = struct(
find_toolchain = _find_toolchain,
if_legacy_toolchain = _if_legacy_toolchain,
INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = _incompatible_toolchain_resolution,
PROTO_TOOLCHAIN = "//bazel/private:proto_toolchain_type",
PROTO_TOOLCHAIN = Label("//bazel/private:proto_toolchain_type"),
)
11 changes: 11 additions & 0 deletions bazel/private/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ toolchain(
toolchain = "//java/lite:toolchain",
toolchain_type = "@rules_java//java/proto:lite_toolchain_type",
)

filegroup(
name = "for_bazel_tests",
testonly = True,
srcs = [
"BUILD.bazel",
],
visibility = [
"//bazel/private:__pkg__",
],
)
9 changes: 7 additions & 2 deletions bazel/toolchains/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ bzl_library(
)

filegroup(
name = "bazel_osx_p4deps",
srcs = glob(["**"]),
name = "for_bazel_tests",
testonly = True,
srcs = [
"BUILD",
"proto_lang_toolchain_bzl",
"proto_toolchain_bzl",
],
visibility = [
"//bazel:__pkg__",
],
Expand Down
7 changes: 5 additions & 2 deletions build_defs/internal_shell.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Internal tools to migrate shell commands to Bazel as an intermediate step
to wider Bazelification.
"""

load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

def inline_sh_binary(
name,
srcs = [],
Expand Down Expand Up @@ -41,7 +44,7 @@ def inline_sh_binary(
testonly = kwargs["testonly"] if "testonly" in kwargs else None,
)

native.sh_binary(
sh_binary(
name = name,
srcs = [name + "_genrule"],
data = srcs + tools + deps,
Expand Down Expand Up @@ -86,7 +89,7 @@ def inline_sh_test(
testonly = kwargs["testonly"] if "testonly" in kwargs else None,
)

native.sh_test(
sh_test(
name = name,
srcs = [name + "_genrule"],
data = srcs + tools + deps,
Expand Down
4 changes: 3 additions & 1 deletion conformance/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE.
"""

load("@rules_shell//shell:sh_test.bzl", "sh_test")

def conformance_test(
name,
testee,
Expand Down Expand Up @@ -31,7 +33,7 @@ def conformance_test(
if maximum_edition:
args = args + ["--maximum_edition %s" % maximum_edition]

native.sh_test(
sh_test(
name = name,
srcs = ["//conformance:bazel_conformance_test_runner.sh"],
data = [testee] + failure_lists + [
Expand Down
16 changes: 12 additions & 4 deletions protobuf_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def protobuf_deps():
)

if not native.existing_rule("rules_cc"):
_github_archive(
http_archive(
name = "rules_cc",
repo = "https://github.com/bazelbuild/rules_cc",
commit = "c8c38f8c710cbbf834283e4777916b68261b359c", # 0.0.9
sha256 = "5f862a44bbd032e1b48ed53c9c211ba2a1da60e10c5baa01c97369c249299ecb",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.13/rules_cc-0.0.13.tar.gz"],
sha256 = "d9bdd3ec66b6871456ec9c965809f43a0901e692d754885e89293807762d3d80",
strip_prefix = "rules_cc-0.0.13",
)

if not native.existing_rule("rules_java"):
Expand All @@ -104,6 +104,14 @@ def protobuf_deps():
sha256 = "6f3ce0e9fba979a844faba2d60467843fbf5191d8ca61fa3d2ea17655b56bb8c",
)

if not native.existing_rule("rules_shell"):
http_archive(
name = "rules_shell",
sha256 = "410e8ff32e018b9efd2743507e7595c26e2628567c42224411ff533b57d27c28",
strip_prefix = "rules_shell-0.2.0",
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.2.0/rules_shell-v0.2.0.tar.gz",
)

if not native.existing_rule("proto_bazel_features"):
proto_bazel_features(name = "proto_bazel_features")

Expand Down
Loading

0 comments on commit 3a78fcc

Please sign in to comment.