xref: /aosp_15_r20/external/bazelbuild-rules_rust/proto/protobuf/repositories.bzl (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifan# Copyright 2018 The Bazel Authors. All rights reserved.
2*d4726bddSHONG Yifan#
3*d4726bddSHONG Yifan# Licensed under the Apache License, Version 2.0 (the "License");
4*d4726bddSHONG Yifan# you may not use this file except in compliance with the License.
5*d4726bddSHONG Yifan# You may obtain a copy of the License at
6*d4726bddSHONG Yifan#
7*d4726bddSHONG Yifan#    http://www.apache.org/licenses/LICENSE-2.0
8*d4726bddSHONG Yifan#
9*d4726bddSHONG Yifan# Unless required by applicable law or agreed to in writing, software
10*d4726bddSHONG Yifan# distributed under the License is distributed on an "AS IS" BASIS,
11*d4726bddSHONG Yifan# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*d4726bddSHONG Yifan# See the License for the specific language governing permissions and
13*d4726bddSHONG Yifan# limitations under the License.
14*d4726bddSHONG Yifan
15*d4726bddSHONG Yifan"""Dependencies for Rust proto rules"""
16*d4726bddSHONG Yifan
17*d4726bddSHONG Yifanload("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18*d4726bddSHONG Yifanload("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
19*d4726bddSHONG Yifanload("//proto/protobuf/3rdparty/crates:defs.bzl", "crate_repositories")
20*d4726bddSHONG Yifan
21*d4726bddSHONG Yifandef rust_proto_protobuf_dependencies(bzlmod = False):
22*d4726bddSHONG Yifan    """Sets up dependencies for rules_rust's proto support.
23*d4726bddSHONG Yifan
24*d4726bddSHONG Yifan    Args:
25*d4726bddSHONG Yifan        bzlmod (bool): Whether this function is being called from a bzlmod context rather than a workspace context.
26*d4726bddSHONG Yifan
27*d4726bddSHONG Yifan    Returns:
28*d4726bddSHONG Yifan        A list of structs containing information about root module deps to report to bzlmod's extension_metadata.
29*d4726bddSHONG Yifan
30*d4726bddSHONG Yifan    """
31*d4726bddSHONG Yifan    if not bzlmod:
32*d4726bddSHONG Yifan        maybe(
33*d4726bddSHONG Yifan            http_archive,
34*d4726bddSHONG Yifan            name = "rules_proto",
35*d4726bddSHONG Yifan            sha256 = "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295",
36*d4726bddSHONG Yifan            strip_prefix = "rules_proto-6.0.2",
37*d4726bddSHONG Yifan            url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
38*d4726bddSHONG Yifan        )
39*d4726bddSHONG Yifan
40*d4726bddSHONG Yifan        maybe(
41*d4726bddSHONG Yifan            http_archive,
42*d4726bddSHONG Yifan            name = "com_google_protobuf",
43*d4726bddSHONG Yifan            sha256 = "758249b537abba2f21ebc2d02555bf080917f0f2f88f4cbe2903e0e28c4187ed",
44*d4726bddSHONG Yifan            strip_prefix = "protobuf-3.10.0",
45*d4726bddSHONG Yifan            urls = [
46*d4726bddSHONG Yifan                "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
47*d4726bddSHONG Yifan                "https://github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
48*d4726bddSHONG Yifan            ],
49*d4726bddSHONG Yifan            patch_args = ["-p1"],
50*d4726bddSHONG Yifan            patches = [
51*d4726bddSHONG Yifan                Label("//proto/protobuf/3rdparty/patches:com_google_protobuf-v3.10.0-bzl_visibility.patch"),
52*d4726bddSHONG Yifan            ],
53*d4726bddSHONG Yifan        )
54*d4726bddSHONG Yifan
55*d4726bddSHONG Yifan        maybe(
56*d4726bddSHONG Yifan            http_archive,
57*d4726bddSHONG Yifan            name = "bazel_features",
58*d4726bddSHONG Yifan            sha256 = "5d7e4eb0bb17aee392143cd667b67d9044c270a9345776a5e5a3cccbc44aa4b3",
59*d4726bddSHONG Yifan            strip_prefix = "bazel_features-1.13.0",
60*d4726bddSHONG Yifan            url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.13.0/bazel_features-v1.13.0.tar.gz",
61*d4726bddSHONG Yifan        )
62*d4726bddSHONG Yifan
63*d4726bddSHONG Yifan    return crate_repositories()
64*d4726bddSHONG Yifan
65*d4726bddSHONG Yifan# buildifier: disable=unnamed-macro
66*d4726bddSHONG Yifandef rust_proto_protobuf_register_toolchains(register_toolchains = True):
67*d4726bddSHONG Yifan    """Register toolchains for proto compilation."""
68*d4726bddSHONG Yifan
69*d4726bddSHONG Yifan    if register_toolchains:
70*d4726bddSHONG Yifan        native.register_toolchains(str(Label("//proto/protobuf:default-proto-toolchain")))
71