chore(bazel): add MODULE.bazel files for bzlmod

bzlmod
Alex Eagle 2023-10-31 12:21:11 -07:00
parent 3667102d91
commit a7b87e5ec9
7 changed files with 2074 additions and 2 deletions

View File

@ -1,2 +1,63 @@
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/protocolbuffers/protobuf/issues/14313
"""Bazel dependencies
Currently only used by external users via the Bazel Central Registry.
TODO(alexeagle): empty the WORKSPACE file and enable bzlmod for this repo.
"""
module(
name = "protobuf",
compatibility_level = 1,
# Replaced automatically by the publish-to-bcr GitHub app, see files in .bcr
version = "0.0",
)
# Lower-bound versions of dependencies.
# Only bump these when required, otherwise a new protobuf release will affect
# bzlmod's MVS constraint solver solution for users and may change their dependencies.
bazel_dep(name = "bazel_skylib", version = "1.0.3")
bazel_dep(name = "rules_python", version = "0.10.2")
bazel_dep(name = "rules_cc", version = "0.0.1")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_java", version = "4.0.0")
bazel_dep(name = "rules_pkg", version = "0.7.0")
bazel_dep(name = "abseil-cpp", repo_name = "com_google_absl", version = "20230802.0")
bazel_dep(name = "zlib", version = "1.2.11")
bazel_dep(name = "upb", version = "0.0.0-20220923-a547704")
bazel_dep(name = "platforms", version = "0.0.7")
protobuf_deps = use_extension(":extensions.bzl", "deps")
use_repo(protobuf_deps, "utf8_range")
# Use this instead, once bzlmod users are required to be on Bazel 7+
# http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# http_archive(
# name = "utf8_range",
# urls = ["https://github.com/protocolbuffers/utf8_range/archive/d863bc33e15cba6d873c878dcca9e6fe52b2f8cb.tar.gz"],
# sha256 = "568988b5f7261ca181468dba38849fabf59dd9200fb2ed4b2823da187ef84d8c",
# )
# TODO(alexeagle): Add missing rules_kotlin
# Maven dependencies
bazel_dep(name = "rules_jvm_external", version = "4.4.2")
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "maven",
artifacts = [
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.8.9",
"com.google.errorprone:error_prone_annotations:2.3.2",
"com.google.j2objc:j2objc-annotations:1.3",
"com.google.guava:guava:31.1-jre",
"com.google.guava:guava-testlib:31.1-jre",
"com.google.truth:truth:1.1.2",
"junit:junit:4.13.2",
"org.mockito:mockito-core:4.3.1",
],
)
use_repo(maven, "maven")
# Dependencies needed in tests
bazel_dep(name = "googletest", repo_name = "com_google_googletest", version = "1.11.0")

1
examples/.bazelversion Normal file
View File

@ -0,0 +1 @@
7.0.0rc2

14
examples/MODULE.bazel Normal file
View File

@ -0,0 +1,14 @@
"""Bazel dependencies
TODO(alexeagle): empty the WORKSPACE file and enable bzlmod for this module
"""
bazel_dep(name = "rules_cc", version = "0.0.1")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_java", version = "4.0.0")
bazel_dep(name = "rules_pkg", version = "0.7.0")
bazel_dep(name = "protobuf", repo_name = "com_google_protobuf")
local_path_override(
module_name = "protobuf",
path = "..",
)

1981
examples/MODULE.bazel.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
"Note, with bzlmod enabled, this file is shadowed by WORKSPACE.bzlmod and not referenced."
workspace(name = "com_google_protobuf_examples")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

View File

@ -0,0 +1,2 @@
# Marker that this folder is the root of a Bazel workspace.
# This file is used instead of WORKSPACE when bzlmod is enabled.

12
extensions.bzl Normal file
View File

@ -0,0 +1,12 @@
"bzlmod extensions, needed to support Bazel 6 users as there was no use_repo_rule in MODULE.bazel."
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def _one_off_ext_impl(ctx):
http_archive(
name = "utf8_range",
urls = ["https://github.com/protocolbuffers/utf8_range/archive/d863bc33e15cba6d873c878dcca9e6fe52b2f8cb.zip"],
sha256 = "568988b5f7261ca181468dba38849fabf59dd9200fb2ed4b2823da187ef84d8c",
strip_prefix = "utf8_range-d863bc33e15cba6d873c878dcca9e6fe52b2f8cb",
)
deps = module_extension(_one_off_ext_impl)