Skip to content

Commit

Permalink
Proto: documentation to change dependencies (#173)
Browse files Browse the repository at this point in the history
Compile dependencies for rust_proto_library and rust_grpc_library
documentation was incorrect. To work-around bazelbuild/bazel#6889,
the format has changed a little but the documentation did not
reflected that change.

Fixes #170
  • Loading branch information
damienmg committed Dec 11, 2018
1 parent 41b208b commit 23ab9d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
30 changes: 29 additions & 1 deletion proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,37 @@ rust_proto_toolchain(
)
```

Finally, now that you have your own toolchain, you need to register it by
Now that you have your own toolchain, you need to register it by
inserting the following statement in your `WORKSPACE` file:

```python
register_toolchains(["//package:toolchain"])
```

Finally, you might want to set the `rust_deps` attribute in
`rust_proto_library` and `rust_grpc_library` to change the compile-time
dependencies:

```python
rust_proto_library(
...
rust_deps = ["//cargo_raze/remote:protobuf"],
...
)

rust_grpc_library(
...
rust_deps = [
"//cargo_raze/remote:protobuf",
"//cargo_raze/remote:grpc",
"//cargo_raze/remote:tls_api",
"//cargo_raze/remote:tls_api_stub",
],
...
)
```

__Note__: Ideally, we would inject those dependencies from the toolchain,
but due to [bazelbuild/bazel#6889](https://github.com/bazelbuild/bazel/issues/6889)
all dependencies added via the toolchain ends-up being in the wrong
configuration.
19 changes: 4 additions & 15 deletions proto/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ def _rust_proto_toolchain_impl(ctx):
return platform_common.ToolchainInfo(
protoc = ctx.executable.protoc,
proto_plugin = ctx.file.proto_plugin,
proto_compile_deps = ctx.attr.proto_compile_deps,
grpc_plugin = ctx.file.grpc_plugin,
grpc_compile_deps = ctx.attr.grpc_compile_deps,
edition = ctx.attr.edition,
)
)

PROTO_COMPILE_DEPS = [
"@io_bazel_rules_rust//proto/raze:protobuf",
Expand All @@ -121,6 +119,9 @@ GRPC_COMPILE_DEPS = PROTO_COMPILE_DEPS + [
]
"""Default dependencies needed to compile gRPC stubs."""

# TODO(damienmg): Once bazelbuild/bazel#6889 is fixed, reintroduce
# proto_compile_deps and grpc_compile_deps and remove them from the
# rust_proto_library and grpc_proto_library.
rust_proto_toolchain = rule(
_rust_proto_toolchain_impl,
attrs = {
Expand Down Expand Up @@ -150,16 +151,6 @@ rust_proto_toolchain = rule(
doc = "The edition used by the generated rust source.",
default = "2015",
),
"proto_compile_deps": attr.label_list(
allow_files = True,
cfg = "target",
default = [Label(l) for l in PROTO_COMPILE_DEPS],
),
"grpc_compile_deps": attr.label_list(
allow_files = True,
cfg = "target",
default = [Label(l) for l in GRPC_COMPILE_DEPS],
),
},
)

Expand All @@ -176,8 +167,6 @@ Args:
optional_output_wrapper: An executable
grpc_plugin: The location of the Rust protobuf compiler pugin to generate
gRPC stubs.
proto_compile_deps: dependencies for rust compilation of protobuf stubs.
grpc_compile_deps: dependencies for rust compilation of gRPC stubs.
Example:
Suppose a new nicer gRPC plugin has came out. Using this new plugin can be
Expand Down

0 comments on commit 23ab9d5

Please sign in to comment.