xref: /aosp_15_r20/external/bazelbuild-rules_go/go/private/repositories.bzl (revision 9bb1b549b6a84214c53be0924760be030e66b93a)
1# Copyright 2014 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Once nested repositories work, this file should cease to exist.
16
17load("//go/private:common.bzl", "MINIMUM_BAZEL_VERSION")
18load("//go/private/skylib/lib:versions.bzl", "versions")
19load("//go/private:nogo.bzl", "DEFAULT_NOGO", "go_register_nogo")
20load("//proto:gogo.bzl", "gogo_special_proto")
21load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22
23def go_rules_dependencies(force = False):
24    """Declares workspaces the Go rules depend on. Workspaces that use
25    rules_go should call this.
26
27    See https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#overriding-dependencies
28    for information on each dependency.
29
30    Instructions for updating this file are in
31    https://github.com/bazelbuild/rules_go/wiki/Updating-dependencies.
32
33    PRs updating dependencies are NOT ACCEPTED. See
34    https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#overriding-dependencies
35    for information on choosing different versions of these repositories
36    in your own project.
37    """
38    if getattr(native, "bazel_version", None):
39        versions.check(MINIMUM_BAZEL_VERSION, bazel_version = native.bazel_version)
40
41    if force:
42        wrapper = _always
43    else:
44        wrapper = _maybe
45
46    # Needed by rules_go implementation and tests.
47    # We can't call bazel_skylib_workspace from here. At the moment, it's only
48    # used to register unittest toolchains, which rules_go does not need.
49    # releaser:upgrade-dep bazelbuild bazel-skylib
50    wrapper(
51        http_archive,
52        name = "bazel_skylib",
53        # 1.4.1, latest as of 2023-03-27
54        urls = [
55            "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
56            "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
57        ],
58        sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
59        strip_prefix = "",
60    )
61
62    # Needed for nogo vet checks and go/packages.
63    # releaser:upgrade-dep golang tools
64    wrapper(
65        http_archive,
66        name = "org_golang_x_tools",
67        # v0.7.0, latest as of 2023-03-27
68        urls = [
69            "https://mirror.bazel.build/github.com/golang/tools/archive/refs/tags/v0.7.0.zip",
70            "https://github.com/golang/tools/archive/refs/tags/v0.7.0.zip",
71        ],
72        sha256 = "9f20a20f29f4008d797a8be882ef82b69cf8f7f2b96dbdfe3814c57d8280fa4b",
73        strip_prefix = "tools-0.7.0",
74        patches = [
75            # deletegopls removes the gopls subdirectory. It contains a nested
76            # module with additional dependencies. It's not needed by rules_go.
77            # releaser:patch-cmd rm -rf gopls
78            Label("//third_party:org_golang_x_tools-deletegopls.patch"),
79            # releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias
80            Label("//third_party:org_golang_x_tools-gazelle.patch"),
81        ],
82        patch_args = ["-p1"],
83    )
84
85    # releaser:upgrade-dep golang sys
86    wrapper(
87        http_archive,
88        name = "org_golang_x_sys",
89        # v0.6.0, latest as of 2023-03-27
90        urls = [
91            "https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.6.0.zip",
92            "https://github.com/golang/sys/archive/refs/tags/v0.6.0.zip",
93        ],
94        sha256 = "7f2399398b2eb4f1f495cc754d6353566e0ad934ee0eb46505e55162e0def56d",
95        strip_prefix = "sys-0.6.0",
96        patches = [
97            # releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/sys -go_naming_convention import_alias
98            Label("//third_party:org_golang_x_sys-gazelle.patch"),
99        ],
100        patch_args = ["-p1"],
101    )
102
103    # Needed by golang.org/x/tools/go/packages
104    # releaser:upgrade-dep golang xerrors
105    wrapper(
106        http_archive,
107        name = "org_golang_x_xerrors",
108        # master, as of 2023-03-27
109        urls = [
110            "https://mirror.bazel.build/github.com/golang/xerrors/archive/04be3eba64a22a838cdb17b8dca15a52871c08b4.zip",
111            "https://github.com/golang/xerrors/archive/04be3eba64a22a838cdb17b8dca15a52871c08b4.zip",
112        ],
113        sha256 = "ffad2b06ef2e09d040da2ff08077865e99ab95d4d0451737fc8e33706bb01634",
114        strip_prefix = "xerrors-04be3eba64a22a838cdb17b8dca15a52871c08b4",
115        patches = [
116            # releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/xerrors -go_naming_convention import_alias
117            Label("//third_party:org_golang_x_xerrors-gazelle.patch"),
118        ],
119        patch_args = ["-p1"],
120    )
121
122    # Proto dependencies
123    # These are limited as much as possible. In most cases, users need to
124    # declare these on their own (probably via go_repository rules generated
125    # with 'gazelle update-repos -from_file=go.mod). There are several
126    # reasons for this:
127    #
128    # * com_google_protobuf has its own dependency macro. We can't load
129    #   the macro here.
130    # * rules_proto also has a dependency macro. It's only needed by tests and
131    #   by gogo_special_proto. Users will need to declare it anyway.
132    # * org_golang_google_grpc has too many dependencies for us to maintain.
133    # * In general, declaring dependencies here confuses users when they
134    #   declare their own dependencies later. Bazel ignores these.
135    # * Most proto repos are updated more frequently than rules_go, and
136    #   we can't keep up.
137
138    # Go protobuf runtime library and utilities.
139    # releaser:upgrade-dep protocolbuffers protobuf-go
140    wrapper(
141        http_archive,
142        name = "org_golang_google_protobuf",
143        sha256 = "cb1a05581c33b3705ede6c08edf9b9c1dbc579559ba30f532704c324e42bf801",
144        # v1.30.0, latest as of 2023-03-27
145        urls = [
146            "https://mirror.bazel.build/github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.30.0.zip",
147            "https://github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.30.0.zip",
148        ],
149        strip_prefix = "protobuf-go-1.30.0",
150        patches = [
151            # releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/protobuf -go_naming_convention import_alias -proto disable_global
152            Label("//third_party:org_golang_google_protobuf-gazelle.patch"),
153        ],
154        patch_args = ["-p1"],
155    )
156
157    # Legacy protobuf compiler, runtime, and utilities.
158    # We still use protoc-gen-go because the new one doesn't support gRPC, and
159    # the gRPC compiler doesn't exist yet.
160    # We need to apply a patch to enable both go_proto_library and
161    # go_library with pre-generated sources.
162    # releaser:upgrade-dep golang protobuf
163    wrapper(
164        http_archive,
165        name = "com_github_golang_protobuf",
166        # v1.5.3, latest as of 2023-03-27
167        urls = [
168            "https://mirror.bazel.build/github.com/golang/protobuf/archive/refs/tags/v1.5.3.zip",
169            "https://github.com/golang/protobuf/archive/refs/tags/v1.5.3.zip",
170        ],
171        sha256 = "2dced4544ae5372281e20f1e48ca76368355a01b31353724718c4d6e3dcbb430",
172        strip_prefix = "protobuf-1.5.3",
173        patches = [
174            # releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/golang/protobuf -go_naming_convention import_alias -proto disable_global
175            Label("//third_party:com_github_golang_protobuf-gazelle.patch"),
176        ],
177        patch_args = ["-p1"],
178    )
179
180    # Extra protoc plugins and libraries.
181    # Doesn't belong here, but low maintenance.
182    # releaser:upgrade-dep mwitkow go-proto-validators
183    wrapper(
184        http_archive,
185        name = "com_github_mwitkow_go_proto_validators",
186        # v0.3.2, latest as of 2023-03-27
187        urls = [
188            "https://mirror.bazel.build/github.com/mwitkow/go-proto-validators/archive/refs/tags/v0.3.2.zip",
189            "https://github.com/mwitkow/go-proto-validators/archive/refs/tags/v0.3.2.zip",
190        ],
191        sha256 = "d8697f05a2f0eaeb65261b480e1e6035301892d9fc07ed945622f41b12a68142",
192        strip_prefix = "go-proto-validators-0.3.2",
193        # Bazel support added in v0.3.0, so no patches needed.
194    )
195
196    # releaser:upgrade-dep gogo protobuf
197    wrapper(
198        http_archive,
199        name = "com_github_gogo_protobuf",
200        # v1.3.2, latest as of 2023-03-27
201        urls = [
202            "https://mirror.bazel.build/github.com/gogo/protobuf/archive/refs/tags/v1.3.2.zip",
203            "https://github.com/gogo/protobuf/archive/refs/tags/v1.3.2.zip",
204        ],
205        sha256 = "f89f8241af909ce3226562d135c25b28e656ae173337b3e58ede917aa26e1e3c",
206        strip_prefix = "protobuf-1.3.2",
207        patches = [
208            # releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/gogo/protobuf -go_naming_convention import_alias -proto legacy
209            Label("//third_party:com_github_gogo_protobuf-gazelle.patch"),
210        ],
211        patch_args = ["-p1"],
212    )
213
214    wrapper(
215        gogo_special_proto,
216        name = "gogo_special_proto",
217    )
218
219    # go_library targets with pre-generated sources for Well Known Types
220    # and Google APIs.
221    # Doesn't belong here, but it would be an annoying source of errors if
222    # this weren't generated with -proto disable_global.
223    # releaser:upgrade-dep googleapis go-genproto
224    wrapper(
225        http_archive,
226        name = "org_golang_google_genproto",
227        # main, as of 2023-03-27
228        urls = [
229            "https://mirror.bazel.build/github.com/googleapis/go-genproto/archive/6ac7f18bb9d5eeeb13a9f1ae4f21e4374a1952f8.zip",
230            "https://github.com/googleapis/go-genproto/archive/6ac7f18bb9d5eeeb13a9f1ae4f21e4374a1952f8.zip",
231        ],
232        sha256 = "3470e7a89b24971b20c4bb8900a668df25279e4b741f72bc09418c1f22543215",
233        strip_prefix = "go-genproto-6ac7f18bb9d5eeeb13a9f1ae4f21e4374a1952f8",
234        patches = [
235            # releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/genproto -go_naming_convention import_alias -proto disable_global
236            Label("//third_party:org_golang_google_genproto-gazelle.patch"),
237        ],
238        patch_args = ["-p1"],
239    )
240
241    # go_proto_library targets for gRPC and Google APIs.
242    # TODO(#1986): migrate to com_google_googleapis. This workspace was added
243    # before the real workspace supported Bazel. Gazelle resolves dependencies
244    # here. Gazelle should resolve dependencies to com_google_googleapis
245    # instead, and we should remove this.
246    # releaser:upgrade-dep googleapis googleapis
247    wrapper(
248        http_archive,
249        name = "go_googleapis",
250        # master, as of 2022-12-05
251        urls = [
252            "https://mirror.bazel.build/github.com/googleapis/googleapis/archive/83c3605afb5a39952bf0a0809875d41cf2a558ca.zip",
253            "https://github.com/googleapis/googleapis/archive/83c3605afb5a39952bf0a0809875d41cf2a558ca.zip",
254        ],
255        sha256 = "ba694861340e792fd31cb77274eacaf6e4ca8bda97707898f41d8bebfd8a4984",
256        strip_prefix = "googleapis-83c3605afb5a39952bf0a0809875d41cf2a558ca",
257        patches = [
258            # releaser:patch-cmd find . -name BUILD.bazel -delete
259            Label("//third_party:go_googleapis-deletebuild.patch"),
260            # set gazelle directives; change workspace name
261            Label("//third_party:go_googleapis-directives.patch"),
262            # releaser:patch-cmd gazelle -repo_root .
263            Label("//third_party:go_googleapis-gazelle.patch"),
264        ],
265        patch_args = ["-E", "-p1"],
266    )
267
268    # releaser:upgrade-dep golang mock
269    _maybe(
270        http_archive,
271        name = "com_github_golang_mock",
272        # v1.7.0-rc.1, latest as of 2023-03-27
273        urls = [
274            "https://mirror.bazel.build/github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
275            "https://github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
276        ],
277        patches = [
278            # releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/golang/mock -go_naming_convention import_alias
279            Label("//third_party:com_github_golang_mock-gazelle.patch"),
280        ],
281        patch_args = ["-p1"],
282        sha256 = "5359c78b0c1649cf7beb3b48ff8b1d1aaf0243b22ea4789aba94805280075d8e",
283        strip_prefix = "mock-1.7.0-rc.1",
284    )
285
286    # This may be overridden by go_register_toolchains, but it's not mandatory
287    # for users to call that function (they may declare their own @go_sdk and
288    # register their own toolchains).
289    wrapper(
290        go_register_nogo,
291        name = "io_bazel_rules_nogo",
292        nogo = DEFAULT_NOGO,
293    )
294
295def _maybe(repo_rule, name, **kwargs):
296    if name not in native.existing_rules():
297        repo_rule(name = name, **kwargs)
298
299def _always(repo_rule, name, **kwargs):
300    repo_rule(name = name, **kwargs)
301