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

Make rust_proto_library work with proto_library rules using import_prefix / strip_import_prefix . #239

Merged
merged 2 commits into from
Jul 8, 2019
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
9 changes: 8 additions & 1 deletion proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ RustProtoProvider = provider(
def _compute_proto_source_path(file, source_root_attr):
"""Take the short path of file and make it suitable for protoc."""

# Bazel creates symlinks to the .proto files under a directory called
# "_virtual_imports/<rule name>" if we do any sort of munging of import
# paths (e.g. using strip_import_prefix / import_prefix attributes)
virtual_imports = "/_virtual_imports/"
if virtual_imports in file.path:
return file.path.split(virtual_imports)[1].split("/", 1)[1]

# For proto, they need to be requested with their absolute name to be
# compatible with the descriptor_set passed by proto_library.
# I.e. if you compile a protobuf at @repo1//package:file.proto, the proto
Expand Down Expand Up @@ -260,7 +267,7 @@ rust_grpc_library = rule(
),
"rust_deps": attr.label_list(
doc = "The crates the generated library depends on.",
default = GRPC_COMPILE_DEPS
default = GRPC_COMPILE_DEPS,
),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
"_optional_output_wrapper": attr.label(
Expand Down
2 changes: 1 addition & 1 deletion proto/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _rust_proto_toolchain_impl(ctx):
proto_plugin = ctx.file.proto_plugin,
grpc_plugin = ctx.file.grpc_plugin,
edition = ctx.attr.edition,
)
)

PROTO_COMPILE_DEPS = [
"@io_bazel_rules_rust//proto/raze:protobuf",
Expand Down