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:polyfill_bazel_features.bzl", "polyfill_bazel_features")
19load("//go/private/skylib/lib:versions.bzl", "versions")
20load("//go/private:nogo.bzl", "DEFAULT_NOGO", "go_register_nogo")
21load("//proto:gogo.bzl", "gogo_special_proto")
22load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
23
24def go_rules_dependencies(force = False):
25 """Declares workspaces the Go rules depend on. Workspaces that use
26 rules_go should call this.
27
28 See https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#overriding-dependencies
29 for information on each dependency.
30
31 Instructions for updating this file are in
32 https://github.com/bazelbuild/rules_go/wiki/Updating-dependencies.
33
34 PRs updating dependencies are NOT ACCEPTED. See
35 https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#overriding-dependencies
36 for information on choosing different versions of these repositories
37 in your own project.
38 """
39 if getattr(native, "bazel_version", None):
40 versions.check(MINIMUM_BAZEL_VERSION, bazel_version = native.bazel_version)
41
42 if force:
43 wrapper = _always
44 else:
45 wrapper = _maybe
46
47 # Needed by rules_go implementation and tests.
48 # We can't call bazel_skylib_workspace from here. At the moment, it's only
49 # used to register unittest toolchains, which rules_go does not need.
50 # releaser:upgrade-dep bazelbuild bazel-skylib
51 wrapper(
52 http_archive,
53 name = "bazel_skylib",
54 # 1.5.0, latest as of 2023-12-15
55 urls = [
56 "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz",
57 "https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz",
58 ],
59 sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94",
60 strip_prefix = "",
61 )
62
63 # Needed for nogo vet checks and go/packages.
64 # releaser:upgrade-dep golang tools
65 wrapper(
66 http_archive,
67 name = "org_golang_x_tools",
68 # v0.15.0, latest as of 2023-11-16
69 urls = [
70 "https://mirror.bazel.build/github.com/golang/tools/archive/refs/tags/v0.15.0.zip",
71 "https://github.com/golang/tools/archive/refs/tags/v0.15.0.zip",
72 ],
73 sha256 = "e76a03b11719138502c7fef44d5e1dc4469f8c2fcb2ee4a1d96fb09aaea13362",
74 strip_prefix = "tools-0.15.0",
75 patches = [
76 # deletegopls removes the gopls subdirectory. It contains a nested
77 # module with additional dependencies. It's not needed by rules_go.
78 # releaser:patch-cmd rm -rf gopls
79 Label("//third_party:org_golang_x_tools-deletegopls.patch"),
80 # releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias
81 Label("//third_party:org_golang_x_tools-gazelle.patch"),
82 ],
83 patch_args = ["-p1"],
84 )
85
86 # Needed for go/tools/fetch_repo
87 # releaser:upgrade-dep golang tools go vcs
88 wrapper(
89 http_archive,
90 name = "org_golang_x_tools_go_vcs",
91 # v0.12.0, latest as of 2023-08-12
92 urls = [
93 "https://mirror.bazel.build/github.com/golang/tools/archive/refs/tags/go/vcs/v0.1.0-deprecated.zip",
94 "https://github.com/golang/tools/archive/refs/tags/go/vcs/v0.1.0-deprecated.zip",
95 ],
96 sha256 = "1b389268d126467105305ae4482df0189cc80a13aaab28d0946192b4ad0737a8",
97 strip_prefix = "tools-go-vcs-v0.1.0-deprecated/go/vcs",
98 patches = [
99 # releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools/go/vcs -go_naming_convention import_alias
100 Label("//third_party:org_golang_x_tools_go_vcs-gazelle.patch"),
101 ],
102 patch_args = ["-p1"],
103 )
104
105 # releaser:upgrade-dep golang sys
106 wrapper(
107 http_archive,
108 name = "org_golang_x_sys",
109 # v0.15.0, latest as of 2023-12-15
110 urls = [
111 "https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.15.0.zip",
112 "https://github.com/golang/sys/archive/refs/tags/v0.15.0.zip",
113 ],
114 sha256 = "36e7b6587b60eabebcd5102211ef5fabc6c6f40d93dd0db83dcefd13cdeb1b71",
115 strip_prefix = "sys-0.15.0",
116 patches = [
117 # releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/sys -go_naming_convention import_alias
118 Label("//third_party:org_golang_x_sys-gazelle.patch"),
119 ],
120 patch_args = ["-p1"],
121 )
122
123 # Needed by golang.org/x/tools/go/packages
124 # releaser:upgrade-dep golang xerrors
125 wrapper(
126 http_archive,
127 name = "org_golang_x_xerrors",
128 # master, as of 2023-12-15
129 urls = [
130 "https://mirror.bazel.build/github.com/golang/xerrors/archive/104605ab7028f4af38a8aff92ac848a51bd53c5d.zip",
131 "https://github.com/golang/xerrors/archive/104605ab7028f4af38a8aff92ac848a51bd53c5d.zip",
132 ],
133 sha256 = "007a5988932222d36c106636de7f0031bb26c426327a8f1253fbf17c7c9756c1",
134 strip_prefix = "xerrors-104605ab7028f4af38a8aff92ac848a51bd53c5d",
135 patches = [
136 # releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/xerrors -go_naming_convention import_alias
137 Label("//third_party:org_golang_x_xerrors-gazelle.patch"),
138 ],
139 patch_args = ["-p1"],
140 )
141
142 # Proto dependencies
143 # These are limited as much as possible. In most cases, users need to
144 # declare these on their own (probably via go_repository rules generated
145 # with 'gazelle update-repos -from_file=go.mod). There are several
146 # reasons for this:
147 #
148 # * com_google_protobuf has its own dependency macro. We can't load
149 # the macro here.
150 # * rules_proto also has a dependency macro. It's only needed by tests and
151 # by gogo_special_proto. Users will need to declare it anyway.
152 # * org_golang_google_grpc has too many dependencies for us to maintain.
153 # * In general, declaring dependencies here confuses users when they
154 # declare their own dependencies later. Bazel ignores these.
155 # * Most proto repos are updated more frequently than rules_go, and
156 # we can't keep up.
157
158 # Go protobuf runtime library and utilities.
159 # releaser:upgrade-dep protocolbuffers protobuf-go
160 wrapper(
161 http_archive,
162 name = "org_golang_google_protobuf",
163 sha256 = "f5d1f6d0e9b836aceb715f1df2dc065083a55b07ecec3b01b5e89d039b14da02",
164 # v1.31.0, latest as of 2023-12-15
165 urls = [
166 "https://mirror.bazel.build/github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.31.0.zip",
167 "https://github.com/protocolbuffers/protobuf-go/archive/refs/tags/v1.31.0.zip",
168 ],
169 strip_prefix = "protobuf-go-1.31.0",
170 patches = [
171 # releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/protobuf -go_naming_convention import_alias -proto disable_global
172 Label("//third_party:org_golang_google_protobuf-gazelle.patch"),
173 ],
174 patch_args = ["-p1"],
175 )
176
177 # gRPC protoc plugin
178 # releaser:upgrade-dep grpc grpc-go cmd/protoc-gen-go-grpc
179 wrapper(
180 http_archive,
181 name = "org_golang_google_grpc_cmd_protoc_gen_go_grpc",
182 sha256 = "1e84df03c94d1cded8e94da7a2df162463f3be4c7a94289d85c0871f14c7b8e3",
183 # cmd/protoc-gen-go-grpc/v1.3.0, latest as of 2023-12-13
184 urls = [
185 "https://mirror.bazel.build/github.com/grpc/grpc-go/archive/refs/tags/cmd/protoc-gen-go-grpc/v1.3.0.zip",
186 "https://github.com/grpc/grpc-go/archive/refs/tags/cmd/protoc-gen-go-grpc/v1.3.0.zip",
187 ],
188 strip_prefix = "grpc-go-cmd-protoc-gen-go-grpc-v1.3.0/cmd/protoc-gen-go-grpc",
189 patches = [
190 # releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/grpc/cmd/protoc-gen-go-grpc -go_naming_convention import_alias -proto disable_global
191 Label("//third_party:org_golang_google_grpc_cmd_protoc_gen_go_grpc.patch"),
192 ],
193 patch_args = ["-p1"],
194 )
195
196 # Legacy protobuf compiler, runtime, and utilities.
197 # We need to apply a patch to enable both go_proto_library and
198 # go_library with pre-generated sources.
199 # releaser:upgrade-dep golang protobuf
200 wrapper(
201 http_archive,
202 name = "com_github_golang_protobuf",
203 # v1.5.3, latest as of 2023-12-15
204 urls = [
205 "https://mirror.bazel.build/github.com/golang/protobuf/archive/refs/tags/v1.5.3.zip",
206 "https://github.com/golang/protobuf/archive/refs/tags/v1.5.3.zip",
207 ],
208 sha256 = "2dced4544ae5372281e20f1e48ca76368355a01b31353724718c4d6e3dcbb430",
209 strip_prefix = "protobuf-1.5.3",
210 patches = [
211 # releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/golang/protobuf -go_naming_convention import_alias -proto disable_global
212 Label("//third_party:com_github_golang_protobuf-gazelle.patch"),
213 ],
214 patch_args = ["-p1"],
215 )
216
217 # releaser:upgrade-dep gogo protobuf
218 wrapper(
219 http_archive,
220 name = "com_github_gogo_protobuf",
221 # v1.3.2, latest as of 2023-12-15
222 urls = [
223 "https://mirror.bazel.build/github.com/gogo/protobuf/archive/refs/tags/v1.3.2.zip",
224 "https://github.com/gogo/protobuf/archive/refs/tags/v1.3.2.zip",
225 ],
226 sha256 = "f89f8241af909ce3226562d135c25b28e656ae173337b3e58ede917aa26e1e3c",
227 strip_prefix = "protobuf-1.3.2",
228 patches = [
229 # releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/gogo/protobuf -go_naming_convention import_alias -proto legacy
230 Label("//third_party:com_github_gogo_protobuf-gazelle.patch"),
231 ],
232 patch_args = ["-p1"],
233 )
234
235 wrapper(
236 gogo_special_proto,
237 name = "gogo_special_proto",
238 )
239
240 # go_library targets with pre-generated sources for Well Known Types.
241 # Doesn't belong here, but it would be an annoying source of errors if
242 # this weren't generated with -proto disable_global.
243 # releaser:upgrade-dep googleapis go-genproto
244 wrapper(
245 http_archive,
246 name = "org_golang_google_genproto",
247 # main, as of 2023-12-15
248 urls = [
249 "https://mirror.bazel.build/github.com/googleapis/go-genproto/archive/995d672761c0c5b9ac6127b488b48825f9a2e5fb.zip",
250 "https://github.com/googleapis/go-genproto/archive/995d672761c0c5b9ac6127b488b48825f9a2e5fb.zip",
251 ],
252 sha256 = "14164722fe3c601a0515a911b319a4d6a397f96ee74d9c12b57e5b5501f8cb48",
253 strip_prefix = "go-genproto-995d672761c0c5b9ac6127b488b48825f9a2e5fb",
254 patches = [
255 # releaser:patch-cmd gazelle -repo_root . -go_prefix google.golang.org/genproto -go_naming_convention import_alias -proto disable_global
256 Label("//third_party:org_golang_google_genproto-gazelle.patch"),
257 ],
258 patch_args = ["-p1"],
259 )
260
261 # releaser:upgrade-dep golang mock
262 _maybe(
263 http_archive,
264 name = "com_github_golang_mock",
265 # v1.7.0-rc.1, latest as of 2023-12-18
266 urls = [
267 "https://mirror.bazel.build/github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
268 "https://github.com/golang/mock/archive/refs/tags/v1.7.0-rc.1.zip",
269 ],
270 patches = [
271 # releaser:patch-cmd gazelle -repo_root . -go_prefix github.com/golang/mock -go_naming_convention import_alias
272 Label("//third_party:com_github_golang_mock-gazelle.patch"),
273 ],
274 patch_args = ["-p1"],
275 sha256 = "5359c78b0c1649cf7beb3b48ff8b1d1aaf0243b22ea4789aba94805280075d8e",
276 strip_prefix = "mock-1.7.0-rc.1",
277 )
278
279 # This may be overridden by go_register_toolchains, but it's not mandatory
280 # for users to call that function (they may declare their own @go_sdk and
281 # register their own toolchains).
282 wrapper(
283 go_register_nogo,
284 name = "io_bazel_rules_nogo",
285 nogo = DEFAULT_NOGO,
286 )
287
288 _maybe(
289 polyfill_bazel_features,
290 name = "io_bazel_rules_go_bazel_features",
291 )
292
293def _maybe(repo_rule, name, **kwargs):
294 if name not in native.existing_rules():
295 repo_rule(name = name, **kwargs)
296
297def _always(repo_rule, name, **kwargs):
298 repo_rule(name = name, **kwargs)
View as plain text