Skip to content

Commit fe657ed

Browse files
authored
Update //proto rules to provide all required dependencies. (#868)
1 parent 73f228f commit fe657ed

18 files changed

+131
-81
lines changed

WORKSPACE.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
88

99
rust_proto_repositories()
1010

11+
load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")
12+
13+
rust_proto_transitive_repositories()
14+
1115
load("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_repositories")
1216

1317
rust_bindgen_repositories()
@@ -85,4 +89,4 @@ docs_deps()
8589

8690
load("@docs//:docs_transitive_deps.bzl", docs_transitive_deps = "transitive_deps")
8791

88-
docs_transitive_deps(is_top_level = True)
92+
docs_transitive_deps()

docs/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ bzl_library(
99
srcs = [
1010
"@bazel_tools//tools:bzl_srcs",
1111
"@build_bazel_rules_nodejs//internal/providers:bzl",
12+
"@com_google_protobuf//:bzl_srcs",
1213
],
1314
deps = [
1415
"@bazel_skylib//lib:paths",
15-
"@rules_proto//proto:rules",
16+
"@rules_proto//proto:defs",
17+
"@rules_proto//proto:repositories",
1618
],
1719
)
1820

@@ -112,6 +114,7 @@ PAGES = dict([
112114
"rust_grpc_library",
113115
"rust_proto_library",
114116
"rust_proto_repositories",
117+
"rust_proto_transitive_repositories",
115118
"rust_proto_toolchain",
116119
],
117120
),

docs/docs_deps.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Define dependencies for `rules_rust` docs"""
22

33
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
4+
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
45
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
56
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")
67

@@ -10,4 +11,6 @@ def deps():
1011

1112
rust_wasm_bindgen_repositories()
1213

14+
rust_proto_repositories()
15+
1316
stardoc_repositories()

docs/docs_transitive_deps.bzl

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
"""Define transitive dependencies for `rules_rust` docs"""
22

3-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
43
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
5-
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
4+
load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")
65

7-
def transitive_deps(is_top_level = False):
6+
def transitive_deps():
87
"""Define transitive dependencies for `rules_rust` docs
9-
10-
Args:
11-
is_top_level (bool, optional): Indicates wheather or not this is being called
12-
from the root WORKSPACE file of `rules_rust`. Defaults to False.
138
"""
14-
rust_proto_repositories()
9+
rust_proto_transitive_repositories()
1510

1611
node_repositories()
17-
18-
# Rules proto does not declare a bzl_library, we stub it there for now.
19-
# TODO: Remove this hack if/when rules_proto adds a bzl_library.
20-
if is_top_level:
21-
maybe(
22-
native.local_repository,
23-
name = "rules_proto",
24-
path = "docs/rules_proto_stub",
25-
)
26-
else:
27-
maybe(
28-
native.local_repository,
29-
name = "rules_proto",
30-
path = "rules_proto_stub",
31-
)

docs/flatten.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* [rust_proto_library](#rust_proto_library)
2424
* [rust_proto_repositories](#rust_proto_repositories)
2525
* [rust_proto_toolchain](#rust_proto_toolchain)
26+
* [rust_proto_transitive_repositories](#rust_proto_transitive_repositories)
2627
* [rust_repositories](#rust_repositories)
2728
* [rust_repository_set](#rust_repository_set)
2829
* [rust_shared_library](#rust_shared_library)
@@ -1606,6 +1607,20 @@ Declare dependencies needed for proto compilation.
16061607
| <a id="rust_proto_repositories-register_default_toolchain"></a>register_default_toolchain | If True, the default [rust_proto_toolchain](#rust_proto_toolchain) (<code>@rules_rust//proto:default-proto-toolchain</code>) is registered. This toolchain requires a set of dependencies that were generated using [cargo raze](https://github.com/google/cargo-raze). These will also be loaded. | <code>True</code> |
16071608

16081609

1610+
<a id="#rust_proto_transitive_repositories"></a>
1611+
1612+
## rust_proto_transitive_repositories
1613+
1614+
<pre>
1615+
rust_proto_transitive_repositories()
1616+
</pre>
1617+
1618+
Load transitive dependencies of the `@rules_rust//proto` rules.
1619+
1620+
This macro should be called immediately after the `rust_proto_repositories` macro.
1621+
1622+
1623+
16091624
<a id="#rust_repositories"></a>
16101625

16111626
## rust_repositories

docs/rules_proto_stub/WORKSPACE.bazel

Whitespace-only changes.

docs/rules_proto_stub/proto/BUILD.bazel

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/rules_proto_stub/proto/defs.bzl

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/rust_proto.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [rust_grpc_library](#rust_grpc_library)
55
* [rust_proto_library](#rust_proto_library)
66
* [rust_proto_repositories](#rust_proto_repositories)
7+
* [rust_proto_transitive_repositories](#rust_proto_transitive_repositories)
78
* [rust_proto_toolchain](#rust_proto_toolchain)
89

910

@@ -26,6 +27,10 @@ external repositories for the Rust proto toolchain (in addition to the [rust rul
2627
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
2728

2829
rust_proto_repositories()
30+
31+
load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")
32+
33+
rust_proto_transitive_repositories()
2934
```
3035

3136
[raze]: https://github.com/google/cargo-raze
@@ -273,3 +278,17 @@ Declare dependencies needed for proto compilation.
273278
| <a id="rust_proto_repositories-register_default_toolchain"></a>register_default_toolchain | If True, the default [rust_proto_toolchain](#rust_proto_toolchain) (<code>@rules_rust//proto:default-proto-toolchain</code>) is registered. This toolchain requires a set of dependencies that were generated using [cargo raze](https://github.com/google/cargo-raze). These will also be loaded. | <code>True</code> |
274279

275280

281+
<a id="#rust_proto_transitive_repositories"></a>
282+
283+
## rust_proto_transitive_repositories
284+
285+
<pre>
286+
rust_proto_transitive_repositories()
287+
</pre>
288+
289+
Load transitive dependencies of the `@rules_rust//proto` rules.
290+
291+
This macro should be called immediately after the `rust_proto_repositories` macro.
292+
293+
294+

docs/rust_proto.vm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ external repositories for the Rust proto toolchain (in addition to the [rust rul
1818
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
1919

2020
rust_proto_repositories()
21+
22+
load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")
23+
24+
rust_proto_transitive_repositories()
2125
```
2226

2327
[raze]: https://github.com/google/cargo-raze

docs/symbols.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ load(
3434
"@rules_rust//proto:toolchain.bzl",
3535
_rust_proto_toolchain = "rust_proto_toolchain",
3636
)
37+
load(
38+
"@rules_rust//proto:transitive_repositories.bzl",
39+
_rust_proto_transitive_repositories = "rust_proto_transitive_repositories",
40+
)
3741
load(
3842
"@rules_rust//rust:defs.bzl",
3943
_rust_analyzer = "rust_analyzer",
@@ -103,6 +107,7 @@ rust_toolchain = _rust_toolchain
103107
rust_proto_toolchain = _rust_proto_toolchain
104108
rust_proto_repositories = _rust_proto_repositories
105109
rust_stdlib_filegroup = _rust_stdlib_filegroup
110+
rust_proto_transitive_repositories = _rust_proto_transitive_repositories
106111

107112
cargo_build_script = _cargo_build_script
108113

examples/examples_repositories.bzl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ def repositories():
1111
path = "..",
1212
)
1313

14-
maybe(
15-
http_archive,
16-
name = "rules_proto",
17-
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
18-
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
19-
urls = [
20-
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
21-
"https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
22-
],
23-
)
24-
2514
maybe(
2615
http_archive,
2716
name = "rules_foreign_cc",

proto/patches/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files([
4+
"com_google_protobuf-v3.10.0-bzl_visibility.patch",
5+
"rules_proto-bzl_visibility.patch",
6+
])

proto/patches/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @rules_rust//proto patches
2+
3+
The patches here provide the required visibility to `*.bzl` files used by the rules defined in `@rules_rust//proto`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/BUILD b/BUILD
2+
index efc3d8e7f..77e3ea413 100644
3+
--- a/BUILD
4+
+++ b/BUILD
5+
@@ -1236,3 +1236,9 @@ sh_test(
6+
"update_file_lists.sh",
7+
],
8+
)
9+
+
10+
+filegroup(
11+
+ name = "bzl_srcs",
12+
+ srcs = glob(["**/*.bzl"]),
13+
+ visibility = ["//visibility:public"],
14+
+)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/proto/BUILD b/proto/BUILD
2+
index 4856ada..67105f0 100644
3+
--- a/proto/BUILD
4+
+++ b/proto/BUILD
5+
@@ -11,3 +11,14 @@ bzl_library(
6+
"//proto/private/rules:proto_descriptor_set",
7+
],
8+
)
9+
+
10+
+bzl_library(
11+
+ name = "repositories",
12+
+ srcs = [
13+
+ "repositories.bzl",
14+
+ ],
15+
+ visibility = ["//visibility:public"],
16+
+ deps = [
17+
+ "//proto/private:dependencies",
18+
+ ],
19+
+)

proto/repositories.bzl

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,31 @@ def rust_proto_repositories(register_default_toolchain = True):
2828
"""
2929
maybe(
3030
http_archive,
31-
name = "com_google_protobuf",
32-
sha256 = "758249b537abba2f21ebc2d02555bf080917f0f2f88f4cbe2903e0e28c4187ed",
33-
strip_prefix = "protobuf-3.10.0",
31+
name = "rules_proto",
32+
sha256 = "bc12122a5ae4b517fa423ea03a8d82ea6352d5127ea48cb54bc324e8ab78493c",
33+
strip_prefix = "rules_proto-af6481970a34554c6942d993e194a9aed7987780",
3434
urls = [
35-
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
36-
"https://github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
35+
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/af6481970a34554c6942d993e194a9aed7987780.tar.gz",
36+
"https://github.com/bazelbuild/rules_proto/archive/af6481970a34554c6942d993e194a9aed7987780.tar.gz",
3737
],
38-
)
39-
40-
maybe(
41-
http_archive,
42-
name = "rules_python",
43-
strip_prefix = "rules_python-0.0.1",
44-
type = "zip",
45-
urls = [
46-
"https://mirror.bazel.build/github.com/bazelbuild/rules_python/archive/0.0.1.zip",
47-
"https://github.com/bazelbuild/rules_python/archive/0.0.1.zip",
38+
patch_args = ["-p1"],
39+
patches = [
40+
Label("//proto/patches:rules_proto-bzl_visibility.patch"),
4841
],
49-
sha256 = "f73c0cf51c32c7aaeaf02669ed03b32d12f2d92e1b05699eb938a75f35a210f4",
5042
)
5143

5244
maybe(
5345
http_archive,
54-
name = "six",
55-
build_file = "@com_google_protobuf//:third_party/six.BUILD",
56-
sha256 = "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73",
46+
name = "com_google_protobuf",
47+
sha256 = "758249b537abba2f21ebc2d02555bf080917f0f2f88f4cbe2903e0e28c4187ed",
48+
strip_prefix = "protobuf-3.10.0",
5749
urls = [
58-
"https://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz",
59-
"https://pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz",
50+
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
51+
"https://github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
6052
],
61-
)
62-
63-
maybe(
64-
http_archive,
65-
name = "zlib",
66-
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
67-
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
68-
strip_prefix = "zlib-1.2.11",
69-
urls = [
70-
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
71-
"https://zlib.net/zlib-1.2.11.tar.gz",
53+
patch_args = ["-p1"],
54+
patches = [
55+
Label("//proto/patches:com_google_protobuf-v3.10.0-bzl_visibility.patch"),
7256
],
7357
)
7458

proto/transitive_repositories.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Definitions for loading transitive `@rules_rust//proto` dependencies"""
2+
3+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
4+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
5+
6+
def rust_proto_transitive_repositories():
7+
"""Load transitive dependencies of the `@rules_rust//proto` rules.
8+
9+
This macro should be called immediately after the `rust_proto_repositories` macro.
10+
"""
11+
rules_proto_dependencies()
12+
13+
rules_proto_toolchains()
14+
15+
protobuf_deps()

0 commit comments

Comments
 (0)