Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update //proto rules to provide all required dependencies. #868

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")

rust_proto_repositories()

load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")

rust_proto_transitive_repositories()

load("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_repositories")

rust_bindgen_repositories()
Expand Down Expand Up @@ -85,4 +89,4 @@ docs_deps()

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

docs_transitive_deps(is_top_level = True)
docs_transitive_deps()
5 changes: 4 additions & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ bzl_library(
srcs = [
"@bazel_tools//tools:bzl_srcs",
"@build_bazel_rules_nodejs//internal/providers:bzl",
"@com_google_protobuf//:bzl_srcs",
],
deps = [
"@bazel_skylib//lib:paths",
"@rules_proto//proto:rules",
"@rules_proto//proto:defs",
"@rules_proto//proto:repositories",
],
)

Expand Down Expand Up @@ -112,6 +114,7 @@ PAGES = dict([
"rust_grpc_library",
"rust_proto_library",
"rust_proto_repositories",
"rust_proto_transitive_repositories",
"rust_proto_toolchain",
],
),
Expand Down
3 changes: 3 additions & 0 deletions docs/docs_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Define dependencies for `rules_rust` docs"""

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")

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

rust_wasm_bindgen_repositories()

rust_proto_repositories()

stardoc_repositories()
26 changes: 3 additions & 23 deletions docs/docs_transitive_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
"""Define transitive dependencies for `rules_rust` docs"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")

def transitive_deps(is_top_level = False):
def transitive_deps():
"""Define transitive dependencies for `rules_rust` docs

Args:
is_top_level (bool, optional): Indicates wheather or not this is being called
from the root WORKSPACE file of `rules_rust`. Defaults to False.
"""
rust_proto_repositories()
rust_proto_transitive_repositories()

node_repositories()

# Rules proto does not declare a bzl_library, we stub it there for now.
# TODO: Remove this hack if/when rules_proto adds a bzl_library.
if is_top_level:
maybe(
native.local_repository,
name = "rules_proto",
path = "docs/rules_proto_stub",
)
else:
maybe(
native.local_repository,
name = "rules_proto",
path = "rules_proto_stub",
)
15 changes: 15 additions & 0 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [rust_proto_library](#rust_proto_library)
* [rust_proto_repositories](#rust_proto_repositories)
* [rust_proto_toolchain](#rust_proto_toolchain)
* [rust_proto_transitive_repositories](#rust_proto_transitive_repositories)
* [rust_repositories](#rust_repositories)
* [rust_repository_set](#rust_repository_set)
* [rust_shared_library](#rust_shared_library)
Expand Down Expand Up @@ -1606,6 +1607,20 @@ Declare dependencies needed for proto compilation.
| <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> |


<a id="#rust_proto_transitive_repositories"></a>

## rust_proto_transitive_repositories

<pre>
rust_proto_transitive_repositories()
</pre>

Load transitive dependencies of the `@rules_rust//proto` rules.

This macro should be called immediately after the `rust_proto_repositories` macro.



<a id="#rust_repositories"></a>

## rust_repositories
Expand Down
Empty file.
7 changes: 0 additions & 7 deletions docs/rules_proto_stub/proto/BUILD.bazel

This file was deleted.

6 changes: 0 additions & 6 deletions docs/rules_proto_stub/proto/defs.bzl

This file was deleted.

19 changes: 19 additions & 0 deletions docs/rust_proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [rust_grpc_library](#rust_grpc_library)
* [rust_proto_library](#rust_proto_library)
* [rust_proto_repositories](#rust_proto_repositories)
* [rust_proto_transitive_repositories](#rust_proto_transitive_repositories)
* [rust_proto_toolchain](#rust_proto_toolchain)


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

rust_proto_repositories()

load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")

rust_proto_transitive_repositories()
```

[raze]: https://github.com/google/cargo-raze
Expand Down Expand Up @@ -273,3 +278,17 @@ Declare dependencies needed for proto compilation.
| <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> |


<a id="#rust_proto_transitive_repositories"></a>

## rust_proto_transitive_repositories

<pre>
rust_proto_transitive_repositories()
</pre>

Load transitive dependencies of the `@rules_rust//proto` rules.

This macro should be called immediately after the `rust_proto_repositories` macro.



4 changes: 4 additions & 0 deletions docs/rust_proto.vm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ external repositories for the Rust proto toolchain (in addition to the [rust rul
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")

rust_proto_repositories()

load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_repositories")

rust_proto_transitive_repositories()
```

[raze]: https://github.com/google/cargo-raze
Expand Down
5 changes: 5 additions & 0 deletions docs/symbols.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ load(
"@rules_rust//proto:toolchain.bzl",
_rust_proto_toolchain = "rust_proto_toolchain",
)
load(
"@rules_rust//proto:transitive_repositories.bzl",
_rust_proto_transitive_repositories = "rust_proto_transitive_repositories",
)
load(
"@rules_rust//rust:defs.bzl",
_rust_analyzer = "rust_analyzer",
Expand Down Expand Up @@ -103,6 +107,7 @@ rust_toolchain = _rust_toolchain
rust_proto_toolchain = _rust_proto_toolchain
rust_proto_repositories = _rust_proto_repositories
rust_stdlib_filegroup = _rust_stdlib_filegroup
rust_proto_transitive_repositories = _rust_proto_transitive_repositories

cargo_build_script = _cargo_build_script

Expand Down
11 changes: 0 additions & 11 deletions examples/examples_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ def repositories():
path = "..",
)

maybe(
http_archive,
name = "rules_proto",
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
],
)

maybe(
http_archive,
name = "rules_foreign_cc",
Expand Down
6 changes: 6 additions & 0 deletions proto/patches/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package(default_visibility = ["//visibility:public"])

exports_files([
"com_google_protobuf-v3.10.0-bzl_visibility.patch",
"rules_proto-bzl_visibility.patch",
])
3 changes: 3 additions & 0 deletions proto/patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @rules_rust//proto patches

The patches here provide the required visibility to `*.bzl` files used by the rules defined in `@rules_rust//proto`.
14 changes: 14 additions & 0 deletions proto/patches/com_google_protobuf-v3.10.0-bzl_visibility.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/BUILD b/BUILD
index efc3d8e7f..77e3ea413 100644
--- a/BUILD
+++ b/BUILD
@@ -1236,3 +1236,9 @@ sh_test(
"update_file_lists.sh",
],
)
+
+filegroup(
+ name = "bzl_srcs",
+ srcs = glob(["**/*.bzl"]),
+ visibility = ["//visibility:public"],
+)
19 changes: 19 additions & 0 deletions proto/patches/rules_proto-bzl_visibility.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/proto/BUILD b/proto/BUILD
index 4856ada..67105f0 100644
--- a/proto/BUILD
+++ b/proto/BUILD
@@ -11,3 +11,14 @@ bzl_library(
"//proto/private/rules:proto_descriptor_set",
],
)
+
+bzl_library(
+ name = "repositories",
+ srcs = [
+ "repositories.bzl",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [
+ "//proto/private:dependencies",
+ ],
+)
48 changes: 16 additions & 32 deletions proto/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,31 @@ def rust_proto_repositories(register_default_toolchain = True):
"""
maybe(
http_archive,
name = "com_google_protobuf",
sha256 = "758249b537abba2f21ebc2d02555bf080917f0f2f88f4cbe2903e0e28c4187ed",
strip_prefix = "protobuf-3.10.0",
name = "rules_proto",
sha256 = "bc12122a5ae4b517fa423ea03a8d82ea6352d5127ea48cb54bc324e8ab78493c",
strip_prefix = "rules_proto-af6481970a34554c6942d993e194a9aed7987780",
urls = [
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
"https://github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/af6481970a34554c6942d993e194a9aed7987780.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/af6481970a34554c6942d993e194a9aed7987780.tar.gz",
],
)

maybe(
http_archive,
name = "rules_python",
strip_prefix = "rules_python-0.0.1",
type = "zip",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_python/archive/0.0.1.zip",
"https://github.com/bazelbuild/rules_python/archive/0.0.1.zip",
patch_args = ["-p1"],
patches = [
Label("//proto/patches:rules_proto-bzl_visibility.patch"),
],
sha256 = "f73c0cf51c32c7aaeaf02669ed03b32d12f2d92e1b05699eb938a75f35a210f4",
)

maybe(
http_archive,
name = "six",
build_file = "@com_google_protobuf//:third_party/six.BUILD",
sha256 = "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73",
name = "com_google_protobuf",
sha256 = "758249b537abba2f21ebc2d02555bf080917f0f2f88f4cbe2903e0e28c4187ed",
strip_prefix = "protobuf-3.10.0",
urls = [
"https://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz",
"https://pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz",
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
"https://github.com/protocolbuffers/protobuf/archive/v3.10.0.tar.gz",
],
)

maybe(
http_archive,
name = "zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
urls = [
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
"https://zlib.net/zlib-1.2.11.tar.gz",
patch_args = ["-p1"],
patches = [
Label("//proto/patches:com_google_protobuf-v3.10.0-bzl_visibility.patch"),
],
)

Expand Down
15 changes: 15 additions & 0 deletions proto/transitive_repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Definitions for loading transitive `@rules_rust//proto` dependencies"""

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

def rust_proto_transitive_repositories():
"""Load transitive dependencies of the `@rules_rust//proto` rules.

This macro should be called immediately after the `rust_proto_repositories` macro.
"""
rules_proto_dependencies()

rules_proto_toolchains()

protobuf_deps()